Metrics
fl-analytics is an add-on library that serves as a framework for recording comprehensive data metrics related to application, video playback, video downloads, and user events. The library can also be used to collect custom events and metadata. The library's data model is based on the Data Dictionary which is the standard schema used to normalize every piece of data captured in order to generate many popular video streaming quality of experience metrics.
QP Analytics offers extensions for the following analytics tools, enabling client applications to seamlessly interact with them through simplified public APIs:
- Datazoom
- Conviva
Below are the steps for setting up and integrating each tool.
Setup
- Conviva
- Datazoom
- Add the following dependencies for Conviva in your Application's
build.gradle
file's dependencies block.
dependencies {
implementation 'com.conviva.sdk:conviva-core-sdk:4.0.39'
implementation 'com.conviva.sdk:conviva-exoplayer-sdk:4.1.3'
}
- Add the following Moshi-Kotlin dependency, which QP Analytics library uses internally to convert kotlin native obejcts to collections and vice verse
dependencies {
implementation 'com.squareup.moshi:moshi-kotlin:1.9.1'
}
- Add following maven repository URL in your Root
build.gradle
file.
maven {
// Snapshot Repository
maven {
url 'https://gitlab.com/api/v4/projects/18323233/packages/maven'
}
// Release Repository
maven {
url 'https://gitlab.com/api/v4/projects/10353305/packages/maven'
}
}
- Add the following dependencies for Datazoom Exo Player SDK in your Application's
build.gradle
file's dependencies block.
dependencies {
implementation 'com.datazoom.android:base-collector-gold:3.3.3'
implementation 'com.datazoom.android:exo-collector-gold-google:2.3.7'
}
Create Application Session
ApplicationSession
provides the entry point to the library analytics protocols. It also serves as factory containing APIs to create other analytic sessions (PlaybackSession, UserSession, DownloadSession). Besides this ApplicationSession
also provides APIs for reporting app start and report fatal and non-fatal errors.
Create ApplicationSession
using the relevant APIs, creation of each parameter is briefed below
val appSession = ApplicationSession.createInstance(
configuration,
connectionListener,
commonData,
customEventsConfigEndpoint
)
ApplicationSession.getInstance()
// API to create PlaybackSession
appSession.createPlaybackSession()
// API to create UserSession
appSession.createUserSession()
// API to create DownloadSession
appSession.createDownloadSession()
Since ApplicationSession
is a singleton class, ApplicationSession.createInstance
should be called only once and ApplicationSession.getInstance
should be used to access the ApplicationSession
object thereafter.
Also note that ApplicationSession
acts as a factory to create the remaining analytics session instances(UserSession
, PlaybackSession
, DownloadSession
).
The library supports connection to multiple analytics provider (supports Datazoom, Conviva at present) by create configuration to specific analytic provider, below is the section for creating configuration for respective analytics module.
Create Analytics Configuration
- Conviva
- Datazoom
Name | Required | Description |
---|---|---|
customerKey | true | The unique identifier of the Conviva configuration key. |
gatewayURL | false | The url for show-casing playbackSession on touchstone (A Conviva tool designed to assist in debugging and validating the integration of Conviva’s video sensor with streaming applications and platforms.). |
allowBackgroundDataCapture | false | Tracks metrics even when the application goes to background if the value is set to true. Default is set to false. |
setLogLevel | false | Set logger level for additional logs to debug, below is the table with possible enum values |
Name | Description |
---|---|
ConvivaLogLevel.DEBUG | To set debug level logs. |
ConvivaLogLevel.INFO | To set info level logs. |
ConvivaLogLevel.WARNING | To set warning level logs. |
ConvivaLogLevel.ERROR | To set error level logs. |
ConvivaLogLevel.NONE | fallback value |
val configuration = ConvivaConfiguration(
<provided customer key from conviva>,
appContext = applicationContext,
)
gatewayURL
has to be set only on debug builds if required, this should never be enabled on production build
Name | Required | Description |
---|---|---|
Id | true | The unique Datazoom configuration key. |
url | true | The URL of the Datazoom server endpoint. |
appContext | true | The Android application instance. |
val configuration = DatazoomConfiguration(
<configuration id from Datazoom>,
<url given by Datazoom>,
applicationContext
)
Create Analytics Connection Status Listener
The library client can start reporting events only if successful connectivity has been established to analytics system and AnalyticsConnectionStateListener API provides the connectivity status.
val connectionListener = object : MetricsConnectionStateListener {
override fun onSuccess() {
// write logic for the case when connected to analytics system.
}
override fun onFailure(error: Error) {
// write logic for the case when we not connect to analytics system. Check the error for reason.
}
}
Create Common Data
When intergrating Conviva just provide the basic parameters provided below to create ApplicationSession
which is marked as required true
as Conviva is mainly player metrics focusses tool.
The Metadata that is expected to remain constant for the entire duration of a session should be provided using CommonReportingData. It encapsulates all relevant optional and mandatory metadata regarding different aspects of the AnalyticSession
.
Use API to update any of this common reporting data.
Application
Create application reporting data payload.
Name | Type | Required | Description |
---|---|---|---|
name | String | true | The name of the application. |
version | String | true | The version of the application. |
buildVersion | String | true | The build version of the application. |
product | String | false | The customer product. |
User
When integrating Conviva, the id
for the USER
type is mandatory, as Conviva categorizes data based on the user's ID, follow below snippet to initialize it.
val user = User(
UserType.ANONYMOUS // modify this as per user type
)
user.id = <userId collected by your system>
Create user's reporting data payload.
Name | Type | Required | Description |
---|---|---|---|
type | UserType | true | Indicates appropriate user type. |
id | String | false | The unique user identifier (eg: Customer Id) |
subscription | Subscription | false | User subscription details. |
profileID | String | false | The unique identifier for the user's profile |
Subscription
Create Subscription
reporting data payload which will be reported as part of above user's payload.
Name | Type | Required | Description |
---|---|---|---|
subscriptionId | String | true | The unique subscription identifier for the user. |
subscriptionStatus | SubscriptionStatus | false | Indicates appropriate subscription status. |
subscriptionPlan | String | false | The subscription plan type name. |
subscriptionPlanID | String | false | The subscription plan type id |
Device
Create user device's reporting data payload.
Name | Type | Required | Description |
---|---|---|---|
platformType | PlatformType | true | Represents how user consuming service (eg: APP, WEB) |
customDeviceManufacturer | String | false | The manufacturer of the user's device if available. |
customDeviceName | String | false | The name of the device model if available. |
Create CommonReportingData
that has to be reported across all the events for the entire application lifecycle.
Name | Type | Required | Description |
---|---|---|---|
app | Application | true | The Application instance |
user | User | false | The User instance. |
device | Device | false | The Device instance. |
val appInfo = Application("sample", "1", "1")
val userInfo = User(UserType.SUBSCRIBED)
val deviceInfo = Device(PlatformType.APP)
val commonData = CommonReportingData(
appInfo,
userInfo,
deviceInfo
)
Toggle Custom Events
Custom Events reporting to the Analytics server can be toggled on/off remotely. Passing the config end point URL, where the black-listed items are hosted, to the createInstance
will restricts the reporting of black-listed custom events
Name | Type | Required | Description |
---|---|---|---|
customEventsConfigEndpoint | String | false | The end point where custom events configuration details are hosted |
Standard Playback Events & Metrics
Create Playback Session
Create PlaybackSession
to report player related events.
val playbackSession = appSession.createPlaybackSession()
Attach Player
Call above attachPlayer
API right after player has been created using PlayerBuilder
.
When composing the player (with IMA, Yospace, or Brightcove), invoke the attachPlayer API immediately after the player is composed with the said additional capabilities.
PlaybackSession
provides and API called attachPlayer
which takes Player
instance as parameter. This API enables the underlying analytics collection tool to access platform native player instance, therefore auto-reporting most of the playback related events.
playbackSession.attachPlayer(player: Player)
Call above attachPlayer
API once player has been loading, Listen for PlaybackState.LOADING
state (refer Here).
Playback events that are auto-captured by library itself
- Conviva
- Datazoom
Name | Description |
---|---|
pause | This event is reported when the player is paused. |
resume | This event is reported when the user begins playing after pausing the video. |
buffer_start | Buffer Start identifies anytime the player has to wait for the video buffer to fill with video segments. |
buffer_end | Event is reported when video starts playing again after a buffer is completed. |
player error | Thrown if an error occurs during content playback or retrieval of the video. |
seek_start | This event records when the user interacts with time controls within the player to move forward or backward in the video timeline. |
see_end | Event is reported when the player stops moving the playhead position to jump to a specific point on the timeline. |
playing | The media is no longer blocked from playback, and has started playing. Reported when playback resumes from Stall, Buffering or Seek. |
Name | Description |
---|---|
playback_start | This event is reported when the video starts playing for the user. |
heartbeat | This event is reported at periodic intervals (1 minute) during content playback. |
media_request | This event is reported after the user invokes playback. |
player_ready | Signifies when the player has been initialized and is ready for playback. |
pause | This event is reported when the player is paused. |
resume | This event is reported when the user begins playing after pausing the video. |
buffer_start | Buffer Start identifies anytime the player has to wait for the video buffer to fill with video segments. |
buffer_end | Event is reported when video starts playing again after a buffer is completed. |
stall_start | Stall Start event is reported when playback of video stops because the buffer has been depleted causing an unexpected interruption for the user. |
stall_end | Event reported when video starts playing again after a stall and the buffer has been replenished and playback resumes. |
error | Thrown if an error occurs during content playback or retrieval of the video. |
playback_complete | This event signifies that the video player has reached the end of the currently playing content. |
stop | This event is reported when the player has entered a stopped state. |
milestone | Reported when the playheadPosition passes a predetermined percentile milestone of the video's duration. Current milestones are fired at the 10, 25, 50, 75, 90 & 95 percentiles. |
seek_start | This event records when the user interacts with time controls within the player to move forward or backward in the video timeline. |
see_end | Event is reported when the player stops moving the playhead position to jump to a specific point on the timeline. |
playing | The media is no longer blocked from playback, and has started playing. Reported when playback resumes from Stall, Buffering or Seek. |
Report Custom Playback Events
The Android implementation of fl-analytics library does not provide support for multiple concurrent playback event reporting.
Report Playback Start
PlaybackSession
provides API to report playback_request
event.
PlaybackRequest
Content Specific metadata
Create data payload for specific type of contents as below.
SportContent
Create SportContent
reporting data payload that is specific to sport event.
Name | Type | Required | Description |
---|---|---|---|
id | String | true | The unique identifier for content item. |
type | String | true | The type of content to report. |
name | String | false | The content name from CMS. |
providerId | String | false | The content's provider identifier. |
genre | String | false | The genre of the content. |
licenseWindowStartDate | String | false | The license window start date. The clear content may not have this parameter. |
sportName | String | false | The name of the sport. |
leagueName | String | true | The name of the sport league. |
team1Name | String | false | The name of the first sport team. |
team2Name | String | false | The name of the second sport team. |
leagueID | String | false | The unique identifier of the sport league. |
leagueExternalID | String | false | The external unique identifier of the sport league. |
leagueShortName | String | false | The short name of the sport league. |
gameID | String | false | The unique identifier of the sport game. |
gameExternalId | String | false | The external unique identifier of the sport game. |
venueName | String | false | The name of the sport event venue. |
venueCity | String | false | The city where the sport event takes place. |
venueCountry | String | false | The country where the sport event takes place. |
team1ID | String | false | The unique identifier of the first sport team. |
team1ExternalID | String | false | The external unique identifier of the first sport team |
team1ShortName | String | false | The short name of the first sport team. |
team2ID | String | false | The unique identifier of the second sport team. |
team2ExternalID | String | false | he external unique identifier of the second sport team. |
team2ShortName | String | false | The short name of the second sport team. |
TVShow
Create TVShow
reporting data payload that is specific to TV show.
Name | Type | Required | Description |
---|---|---|---|
id | String | true | The unique identifier for content item. |
type | String | true | The type of content to report. |
name | String | false | The content name from CMS. |
providerId | String | false | The content's provider identifier. |
genre | String | false | The genre of the content. |
licenseWindowStartDate | String | false | The license window start date. The clear content may not have this parameter. |
seriesID | String | true | The unique identifier of the TV show series. |
seriesName | String | true | The name of the TV show series. |
seasonNumber | String | true | The season number of the TV show series. |
episodeNumber | String | true | The number of one of the episodes in the TV show series. |
MiscellaneousContent
Create MiscellaneousContent
video content reporting data payload that belongs to categories other than SportContent
or TVShow
.
Name | Type | Required | Description |
---|---|---|---|
id | String | true | The unique identifier for content item. |
type | String | true | The type of content to report. |
name | String | false | The content name from CMS. |
providerId | String | false | The content's provider identifier. |
genre | String | false | The genre of the content. |
licenseWindowStartDate | String | false | The license window start date. The clear content may not have this parameter. |
If the content type do not fall under any of the categories like SportContent and TVShow then create Content as MiscellaneousContent
.
ApplicationContainer
Create ApplicationContainer
reporting data payload related to application container.
Name | Type | Required | Description |
---|---|---|---|
id | String | true | The unique identifier of the carousel where the content or link to the collection is located. |
name | String | true | The name of the carousel where the content or link to the collection is located. |
Create PlaybackRequest
reporting data payloads related to video playback request event.
Name | Type | Required | Description |
---|---|---|---|
content | Content | true | The Content details. |
playbackSource | PlaybackSource | false | The PlaybackSource details. |
container | ApplicationContainer | false | The ApplicationContainer details. |
val container = ApplicationContainer("456", "Movies")
val playbackSource = PlaybackSource(PlaybackSourceType.CAROUSEL)
// For MiscellaneousContent
val contentInfo = MiscellaneousContent("12345", "movie", "Sample Content")
// For SportContent
val contentInfo = SportContent("1234", "sport_show")
// For TVShow
val contentInfo = TVShow("2345", "Magic Show", "1", "5")
val playbackRequest = PlaybackRequest(contentInfo, playbackSource, container)
playbackSession.start(playbackRequest)
Handling Playback Request Interruptions
Any interruptions prior to starting the playback (before creating a player) can be reported using PlaybackSession
API.
Example: Checks related to content authorization (content authentication, parental controls etc)
// Report Interruption start
val event = "content_authorization_started"
val reportingData = mapOf("key" to "value")
val customEvent = CustomEvent(event, reportingData)
playbackSession.interruptStart(customEvent)
// Report Interruption end
val event = "content_authorization_success"
val reportingData = mapOf("key" to "value")
val customEvent = CustomEvent(event, reportingData)
playbackSession.interruptEnd(customEvent)
Configure Playback Metadata
Add Playback custom metadata
PlaybackSession
provides an API that inserts common metadata to be reported across all playback related events.
playbackSession.addMetadata(
mapOf("key" to "value")
)
Update Playback custom metadata
PlaybackSession
provides an API to update common metadata to be reported across all playback related events.
playbackSession.updateMetadataRecord(
mapOf("cc_enabled" , "true")
)
Report Playback Error
To report any error caused like content-auth failure, concurrent streams max limit reached (failure from server but not from player layer as fl-analytics auto-reports player errors) can be reported using stop
API in PlaybackSession
. Send Error as a parameter(optional) to report playback stop on any error.
playbackSession.stop(error)
Valued Added Events & Metrics
Click to see more details on creating other sessions(User, Download sessions), prefer this section if integrating Datazoom
Application Events
Report Application start
ApplicationSession
provides an API to report app_start
event along with app start time.
ApplicationMetrics
Create ApplicationMetrics
reporting data payload related to application performance metrics.
Name | Type | Required | Description |
---|---|---|---|
startUpTimeMs | Long | true | The time, in milliseconds, it takes to start the application. |
appSession.start(
ApplicationMetrics(3000)
)
Report Application End
ApplicationSession
provides an API to report app_end
event.
appSession.stop()
User Events
Create UserSession
and start session to report user related events.
val userSession = appSession.createUserSession()
userSession.start(Unit)
UserSession
provides the following API to report user action based events.
// Called when [User] executes "signup" flow.
userSession.signup(user: User)
// Called when [User] executes "login" flow.
userSession.login(user: User)
// Called when [User] executes "logout" flow.
userSession.logout(user: User)
// Called when [User] executes "create profile" flow.
userSession.createProfile(user: User)
// Called when [User] executes "update profile" flow.
userSession.updateProfile(user: User)
// Called when [User] executes "start subscription" flow.
userSession.startSubscription(user: User)
// Called when [User] executes "purchase subscription" flow.
userSession.purchaseSubscription(user: User)
// Called when [User] executes "change subscription" flow.
userSession.changeSubscription(user: User)
// Called when [User] executes "complete payment" flow.
userSession.completePayment(user: User)
It is client application responsibility to ensure that each user action is triggered in the correct sequence.
Download Events
Create DownloadSession
to report download related events.
val downloadSession = appSession.createDownloadSession()
Report Download Start
DownloadSession
provides API to report download_request
event.
DownloadRequest
Create Content, video content reporting data payload based on type of content that is being requested. Create SportContent if sport content was requested or TVShow if TV show content was requested, MiscellaneousContent otherwise.
Create ApplicationContainer reporting data payload related to application container.
Create
DownloadRequest
reporting data payloads related to video playback request event.
Name | Type | Required | Description |
---|---|---|---|
content | Content | true | The Content details. |
playbackSource | PlaybackSource | false | The PlaybackSource details. |
container | ApplicationContainer | false | The ApplicationContainer details. |
val container = ApplicationContainer("456", "Movies")
val playbackSource = PlaybackSource(PlaybackSourceType.CAROUSEL)
// For MiscellaneousContent
val contentInfo = MiscellaneousContent("12345", "movie", "Sample Content")
// For SportContent
val contentInfo = SportContent("1234", "sport_show")
// For TVShow
val contentInfo = TVShow("2345", "Magic Show", "1", "5")
val downloadRequest = DownloadRequest(contentInfo, playbackSource, container)
downloadSession.start(downloadRequest)
Download events that are auto-captured by library itself
Name | Description |
---|---|
download_prepared | This event is reported when a download is prepared |
download_started | This event is reported when a download is started |
download_paused | This event is reported when a download is paused |
download_resumed | This event is reported when a download is resumed |
download_stopped | This event is reported when a download is stopped |
download_completed | This event is reported when a download is completed |
download_deleted | This event is reported when a download is deleted |
Report Custom Events
ApplicationSession
provides an API to report custom events. The library provides MiscellaneousEvent
names for the client application to reuse.
val customEvent = CustomEvent("sample_event", mapOf("key" to "value"))
appSession.addEvent(customEvent)
- In order to conform to the existing reporting scheme the event name should be provided in the lower case format and words should be separated by the underscore character e.g."playback_request"
- In datazoom, any custom event will be reported as event name with
custom_
prefix. (eg: playback_start as custom_playback_start) :::
When trying to report an custom event with a name that is already reserved (the list of reserved event names is captured by QP_ANALYTICS_EVENTS
), library will throw an error.
:::
Configure Application Metadata
Add Application custom metadata
Any additional metadata that is to be attached to all application / playback / user events can be done using the the below API. All subsequent events will report this additional data once it is defined.
appSession.addMetadata(
mapOf("key" to "value")
)
Update Application custom metadata
ApplicationSession
provides an API if the application wants to change any application level attribute at any point of time during the application session.
Example: If the application wants to report the changeable language that it is rendering in, a key - value pair denoting the information can be added using this method. If the language is updated at any point of time during the session, this change can be reflected using below API.
appSession.updateMetadata(
mapOf("catalogue_selected" , "English")
)
Application Errors
ApplicationSession
provides APIs to report both fatal and non-fatal errors.
Report Fatal errors
Any application fatal error can be reported using below API. Send Error as a parameter(optional) to report playback stop on any error.
applicationSession.stop(error)
Report Non-fatal errors
Any application non-fatal error can be reported using below API. Send Error to report playback stop on any error.
applicationSession.addErrorEvent(error, null)
Download Errors
Any Download error can be reported using below API. Send Error to report download stop on any error.
downloadSession.stop(error)
User Action Errors
Any User error can be reported using below API. Create UserError
reporting data payload in case where one of user's action fails and User attribute along with it.
Create User Error
Name | Type | Required | Description |
---|---|---|---|
code | String | true | The unique error code. |
message | String | true | The message describing the error. |
description | String | false | The contextual description of the error. |
val userError = UserError("<error-code>", "user action failure")
val user = User(UserType.SUBSCRIBED)
userSession.addErrorEvent(userError, user)
Out-of-box Player Metrics
Click to know more about out-of-box player reporting metrics
The Quickplay Player provides number of key metrics to analyse the playback performance. Please refer the bundled sample app to understand the corresponding metrics API.
Key Player Metrics
Playback Startup Time
- Playback startup time is the time taken for player to start the playback measured from the moment playback was requested.BufferedRange
- The accumulated duration of the media downloaded in the buffer so far (ratio of currentPosition and bufferedDuration).BufferPercentage
- Returns an estimate of the percentage in the current content window or ad up to which data is buffered.DecodedFrameRate
- Provides number of frames being decoded (the average bandwidth in bits per second).DisplayedFrameRate
- Provides number of Frames being displayed (per second).DroppedDecodedFrameCount
- Provides the number of frames that could not be decoded.DroppedDisplayableFrameCount
- Provides the number of displayable frames that could not be displayed.AudioDecoderInfo
- Provides the audio codec type and name used by player.VideoDecoderInfo
- Provides the video codec type and name used by player.ObservedBandwidth
- Provides the Observed bandwidth.BandwidthEstimate
- Provides the player's current estimate bandwidth.VariantSwitchCount
- The number of times video/audio variant switch based on network bandwidth.
The Quickplay Player's StreamInformation
and NetworkInformation
classes provides all metric info required. For more information please refer sample app.
class MetricsOverlayView(context: Context) : Player.AuxiliaryListener {
override fun onNetworkInfoChanged(networkInfo: NetworkInformation) {
// access here all networkInfo metrics related to playback
}
override fun onStreamInfoChanged(streamInfo: StreamInformation) {
// access here streamInfo metrics related to playback
}
}