This page covers data collection for the In focus player state. See Streams impacted by in focus, In focus counts, and In focus total duration for the corresponding reporting metrics.
The in focus player state tracks when the player has the viewer’s attention. Fire a state-start event when the player gains focus (typically when the player tab or window becomes active) and a state-end event when the player loses focus. The backend computes three metrics from these events: streams impacted, count of state entries, and total time in state.
a.media.states.infocus.set, a.media.states.infocus.count, a.media.states.infocus.timexdm.mediaCollection.statesStart[] and xdm.mediaCollection.statesEnd[] (entries with name: "inFocus")c_contextdata.a.media.states.infocus.set, c_contextdata.a.media.states.infocus.count, c_contextdata.a.media.states.infocus.timeRecommended implementation types
Use sendEvent to send a media.statesUpdate event with the state added to statesStart:
| code language-javascript |
|---|
|
When the player loses focus, send another event with the state in statesEnd:
| code language-javascript |
|---|
|
Use tracker.trackPlayerStateStart() and tracker.trackPlayerStateEnd() with the MediaConstants.PlayerState.IN_FOCUS constant.
| code language-swift |
|---|
|
Use tracker.trackPlayerStateStart() and tracker.trackPlayerStateEnd() with the MediaConstants.PlayerState.IN_FOCUS constant.
| code language-kotlin |
|---|
|
Use sendMediaEvent to send a media.statesUpdate event with the state added to statesStart:
| code language-brightscript |
|---|
|
When the player loses focus, send another event with the state in statesEnd:
| code language-brightscript |
|---|
|
Call the statesUpdate endpoint with inFocus in statesStart (or statesEnd when the player loses focus):
| code language-json |
|---|
|
Legacy implementation types (Analytics-only)
Use ADB.Media.createStateObject and the ADB.Media.PlayerState.InFocus constant:
| code language-javascript |
|---|
|
Use ADBMobile.media.createStateObject with the "inFocus" string directly, as Chromecast does not have named PlayerState constants:
| code language-javascript |
|---|
|
Send a stateStart POST request when the player gains focus, and a stateEnd POST when it loses focus:
| code language-json |
|---|
|
See the Media Collection API events reference for the full request structure.