Skip to main content

Metrics

FLAnalytics 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.

Setup

Datazoom

Quickplay's Player QOE metrics are powered by Datazoom, a video data platform which continually gathers data from endpoints, like a CDN or a video player, through an ecosystem of collectors. Once the data is gathered, it is normalized using standardized data definitions. This data is then sent through available connectors to analytics platforms like Google BigQuery, Google Analytics, and Splunk and can be visualized in tools such as Looker and Superset. Datazoom is your key to a more effective and efficient data pipeline.

Supported SDK version

  • DZ_Collector 3.8.1

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 (each Object configuration, analyticsDelegate, commonReportingData are discussed in detail in below sections).

NameRequiredDescription
configEndPointfalseA QP endpoint which enables customised reporting.
import FLAnalytics

// Required to initialize before reporting events.
FLAnalyticsFactory.applicationSession.initialize(configuration: <#T##Configuration#>, commonData: <#T##CommonReportingData#>, configEndPoint: <#T##String?#>, delegate: <#T##AnalyticsDelegate#>, completion: <#T##(Result<Bool, Error>) -> Void#>)

// API to create PlaybackSession
FLAnalyticsFactory.applicationSession.createPlaybackSession()

// API to create UserSession
FLAnalyticsFactory.applicationSession.createUserSession()

// API to create DownloadSession
FLAnalyticsFactory.applicationSession.createDownloadSession()
note

Passing the config url(configEndPoint) on app launch and on success of session initialization making a new API call and parsing the response, and reporting event we need to filter out the Block list events and report it. Since ApplicationSession is a singleton class, FLAnalyticsFactory.applicationSession.initialize should be called before creating sessions and reporing events. The library client can start reporting events only if successful connectivity has been established to analytics system. Also note that ApplicationSession acts as a factory to create the remaining analytic session instances(UserSession, PlaybackSession, DownloadSession).

The library supports connection to multiple analytics provider (supports Datazoom at present) by create configuration to specific analytic provider, below is the one for creating configuration for datazoom.

Datazoom Configuration

Create configuration to initialize datazoom.

NameRequiredDescription
IdtrueThe unique Datazoom configuration key.
let configuration = Configuration.datazoom(id: <#T##String#>)

AnalyticsDelegate

AnalyticsDelegate provides the callbacks when there is any failure in analytics reporting.

class <class name>: MetricsDelegate {
/// Listen analytics errors
func didFail(with error: FLError) {
}
}

CommonReportingData

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.

note

Use API to update any of this common reporting data.

Application

Create application reporting data payload.

NameTypeRequiredDescription
nameStringtrueThe name of the application.
versionStringtrueThe version of the application.
buildVersionStringtrueThe build version of the application.
productStringfalseThe customer product.
let appInfo = Application(name: <#T##String#>, version: <#T##String#>, buildVersion: <#T##String#>, product: <#T##String?#>)
User

Create user's reporting data payload.

NameTypeRequiredDescription
typeUserTypetrueIndicates appropriate user type.
idStringfalseThe unique user identifier (eg: Customer Id)
subscriptionSubscriptionfalseUser subscription details.
profileIDStringfalseThe unique identifier for the user's profile
let userInfo = User(id: <#T##String?#>, type: <#T##UserType#>, subscription: <#T##Subscription?#>, profileId: <#T##String?#>)
Subscription

Create Subscription reporting data payload which will be reported as part of above user's payload.

NameTypeRequiredDescription
idStringtrueThe unique subscription identifier for the user.
ststusSubscriptionStatusfalseIndicates appropriate subscription status.
planStringfalseThe subscription plan type name.
planIdStringfalseThe subscription plan type id
let subscription = Subscription(id: <#T##String#>, status: <#T##SubscriptionStatus?#>, plan: <#T##String?#>, planId: <#T##String?#>)
Device

Create user device's reporting data payload.

NameTypeRequiredDescription
platformTypePlatformTypetrueRepresents how user consuming service (eg: APP, WEB)
customDeviceManufacturerStringfalseThe manufacturer of the user's device if available.
customDeviceNameStringfalseThe name of the device model if available.
let deviceInfo = Device(platformType: <#T##PlatformType#>, customDeviceManufacturer: <#T##String?#>, customDeviceName: <#T##String?#>)

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

NameTypeRequiredDescription
configEndPointStringfalseThe end point where custom events configuration details are hosted
ABTesting

Create ABTesting reporting data payload.

NameTypeRequiredDescription
experimentIDStringfalseThe identifier for the AB testing experiment.
variantIDStringfalseThe identifier for the AB testing experiment variant.
let abTesting = ABTesting(experimentID: <#T##String?#>, variantID: <#T##String?#>)

Create CommonReportingData that has to be reported across all the events for the entire application lifecycle.

NameTypeRequiredDescription
appApplicationtrueThe Application instance
userUserfalseThe User instance.
deviceDevicefalseThe Device instance.
abTestingABTestingfalseThe [ABTesting] (metrics#abtesting) instance.
let commonData = CommonReportingData(application: <#T##Application#>, user: <#T##User?#>, device: <#T##Device?#>, abTesting: <#T##ABTesting?#>)

Standard Playback Events & Metrics

Create PlaybackSession to report player related events.

let playbackSession = FLAnalyticsFactory.applicationSession.createPlaybackSession()

Attach Player

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)

Playback events that are auto-captured by library itself

NameDescription
playback_startThis event is reported when the video starts playing for the user.
heartbeatThis event is reported at periodic intervals (1 minute) during content playback.
media_requestThis event is reported after the user invokes playback.
player_readySignifies when the player has been initialized and is ready for playback.
pauseThis event is reported when the player is paused.
resumeThis event is reported when the user begins playing after pausing the video.
buffer_startBuffer Start identifies anytime the player has to wait for the video buffer to fill with video segments.
buffer_endEvent is reported when video starts playing again after a buffer is completed.
stall_startStall Start event is reported when playback of video stops because the buffer has been depleted causing an unexpected interruption for the user.
stall_endEvent reported when video starts playing again after a stall and the buffer has been replenished and playback resumes.
errorThrown if an error occurs during content playback or retrieval of the video.
playback_completeThis event signifies that the video player has reached the end of the currently playing content.
stopThis event is reported when the player has entered a stopped state.
milestoneReported 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_startThis event records when the user interacts with time controls within the player to move forward or backward in the video timeline.
see_endEvent is reported when the player stops moving the playhead position to jump to a specific point on the timeline.
playingThe media is no longer blocked from playback, and has started playing. Reported when playback resumes from Stall, Buffering or Seek.

Report Custom Playback Events

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.

NameTypeRequiredDescription
idStringtrueThe unique identifier for content item.
typeContentTypetrueThe type of content to report.
nameStringtrueThe content name from CMS.
providerIdStringfalseThe content's provider identifier.
genreStringfalseThe genre of the content.
licenseWindowStartDateStringfalseThe license window start date. The clear content may not have this parameter.
sportNameStringtrueThe name of the sport.
leagueNameStringtrueThe name of the sport league.
team1NameStringtrueThe name of the first sport team.
team2NameStringtrueThe name of the second sport team.
leagueIDStringfalseThe unique identifier of the sport league.
leagueExternalIDStringfalseThe external unique identifier of the sport league.
leagueShortNameStringfalseThe short name of the sport league.
gameIDStringfalseThe unique identifier of the sport game.
gameExternalIdStringfalseThe external unique identifier of the sport game.
venueNameStringfalseThe name of the sport event venue.
venueCityStringfalseThe city where the sport event takes place.
venueCountryStringfalseThe country where the sport event takes place.
team1IDStringfalseThe unique identifier of the first sport team.
team1ExternalIDStringfalseThe external unique identifier of the first sport team
team1ShortNameStringfalseThe short name of the first sport team.
team2IDStringfalseThe unique identifier of the second sport team.
team2ExternalIDStringfalsehe external unique identifier of the second sport team.
team2ShortNameStringfalseThe short name of the second sport team.
 let contentInfo = Sport(id: <#T##String#>, type: <#T##ContentType#>, name: <#T##String#>, providerId: <#T##String?#>, genre: <#T##String?#>, licenseWindowStartDate: <#T##String?#>, sportName: <#T##String#>, leagueId: <#T##String?#>, leagueExternalId: <#T##String?#>, leagueName: <#T##String#>, leagueShortName: <#T##String?#>, gameId: <#T##String?#>, gameExternalId: <#T##String?#>, venueName: <#T##String?#>, venueCity: <#T##String?#>, venueCountry: <#T##String?#>, team1Id: <#T##String?#>, team1ExternalId: <#T##String?#>, team1Name: <#T##String#>, team1ShortName: <#T##String?#>, team2Id: <#T##String?#>, team2ExternalId: <#T##String?#>, team2Name: <#T##String#>, team2ShortName: <#T##String?#>)
TVShow

Create TVShow reporting data payload that is specific to TV show.

NameTypeRequiredDescription
idStringtrueThe unique identifier for content item.
typeContentTypetrueThe type of content to report.
nameStringtrueThe content name from CMS.
providerIdStringfalseThe content's provider identifier.
genreStringfalseThe genre of the content.
licenseWindowStartDateStringfalseThe license window start date. The clear content may not have this parameter.
seriesIDStringtrueThe unique identifier of the TV show series.
seriesNameStringtrueThe name of the TV show series.
seasonNumberStringtrueThe season number of the TV show series.
episodeNumberStringtrueThe number of one of the episodes in the TV show series.
 let contentInfo = TVShow(id: <#T##String#>, type: <#T##ContentType#>, name: <#T##String#>, providerId: <#T##String?#>, genre: <#T##String?#>, licenseWindowStartDate: <#T##String?#>, seriesId: <#T##String#>, seriesName: <#T##String#>, seasonNumber: <#T##String#>, episodeNumber: <#T##String#>)
MiscellaneousContent

Create MiscellaneousContent video content reporting data payload that belongs to categories other than SportContent or TVShow.

NameTypeRequiredDescription
idStringtrueThe unique identifier for content item.
typeContentTypetrueThe type of content to report.
nameStringtrueThe content name from CMS.
providerIdStringfalseThe content's provider identifier.
genreStringfalseThe genre of the content.
licenseWindowStartDateStringfalseThe license window start date. The clear content may not have this parameter.
 let contentInfo = MiscellaneousContent(id: <#T##String#>, type: <#T##ContentType#>, name: <#T##String#>, genre: <#T##String?#>, providerId: <#T##String?#>, licenseWindowStartDate: <#T##String?#>)
note

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.

NameTypeRequiredDescription
idStringtrueThe unique identifier of the carousel where the content or link to the collection is located.
nameStringtrueThe name of the carousel where the content or link to the collection is located.
 let container = ApplicationContainer(id: <#T##String#>, name: <#T##String#>)

Create PlaybackRequest reporting data payloads related to video playback request event.

NameTypeRequiredDescription
contentContenttrueThe Content details.
playbackSourcePlaybackSourcetrueThe PlaybackSource details.
containerApplicationContainerfalseThe ApplicationContainer details.
 let source = PlaybackSource(type: <#T##PlaybackSourceType#>)

let playbackRequest = PlaybackRequest(content: <#T##Content#>, playbackSource: <#T##PlaybackSource#>, container: <#T##ApplicationContainer?#>)
playbackSession..start(value: 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
let interruptStartEvent = CustomEvent(event: <#T##String#>, attributes: <#T##[String : Any]?#>)
playbackSession.interruptStart(value: <#T##CustomEvent#>)

// Report Interruption end
let interruptEndEvent = CustomEvent(event: <#T##String#>, attributes: <#T##[String : Any]?#>)
playbackSession.interruptEnd(value: <#T##CustomEvent#>)

Configure Playback Metadata

Add Playback custom metadata

PlaybackSession provides an API that add / update common metadata to be reported across all playback related events.

playbackSession.updateMetadataRecord(metadata: <#T##[String : Any]#>)

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: <#T##FLError?#>)

Report Retry Playback Error Event

Application could retry playback for certain error codes and report the same to metrics to keep track of retries. We recommend creating FLError object with code 2097152 (0x200000) and internal error of the actual error.

// Create retry error object wrapping the internal player error
// `error` object is the error reported through player delegate callback playerDidFail(with error:)
let retryError = FLFoundationFactory.error(errorCode: 2097152, errorDescription: "Player retry attempted, check internal error for actual cause", internalError: error.internalError)

// Report retry event to anaytics
playbackSession.stop(error: retryError)
note

Application while reporting retry error event, should not report the actual error. Instead, they should only report retry error event, so that we avoid duplicate error events reported in metrics.

Value Added Events and Metrics

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.

NameTypeRequiredDescription
startUpTimeLongtrueThe time, in milliseconds, it takes to start the application.
FLAnalyticsFactory.applicationSession.start(value: ApplicationMetrics(startUpTime: <#T##TimeInterval#>))

Report Application End

ApplicationSession provides an API to report app_end event.

 FLAnalyticsFactory.applicationSession.stop(error: <#T##FLError?#>)

User Events

Create UserSession to report user related events.

let userSession = FLAnalyticsFactory.applicationSession.createUserSession()

UserSession provides the following API to report user action based events.

// Called when [User] executes "signup" flow.
userSession.signup(user: <#T##User#>)

// Called when [User] executes "login" flow.
userSession.login(user: <#T##User#>)

// Called when [User] executes "logout" flow.
userSession.logout(user: <#T##User#>)

// Called when [User] executes "create profile" flow.
userSession.createProfile(user: <#T##User#>)

// Called when [User] executes "update profile" flow.
userSession.updateProfile(user: <#T##User#>)

// Called when [User] executes "start subscription" flow.
userSession.startSubscription(user: <#T##User#>)

// Called when [User] executes "purchase subscription" flow.
userSession.purchaseSubscription(user: <#T##User#>)

// Called when [User] executes "change subscription" flow.
userSession.changeSubscription(user: <#T##User#>)

// Called when [User] executes "complete payment" flow.
userSession.completePayment(user: <#T##User#>)
note

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.

let downloadSession = FLAnalyticsFactory.applicationSession.createDownloadSession()

Report Download Start

DownloadSession provides API to report download_request event.

DownloadRequest
  1. 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.

  2. Create ApplicationContainer reporting data payload related to application container.

  3. Create DownloadRequest reporting data payloads related to video playback request event.

    NameTypeRequiredDescription
    contentContenttrueThe Content details.
    playbackSourcePlaybackSourcetrueThe PlaybackSource details.
    containerApplicationContainerfalseThe ApplicationContainer details.
    let source = PlaybackSource(type: <#T##PlaybackSourceType#>)

    let downloadRequest = FLAnalytics.DownloadRequest(content: <#T##Content#>, playbackSource: <#T##PlaybackSource#>, container: <#T##ApplicationContainer?#>)
    downloadSession.start(value: downloadRequest)

Download events that are auto-captured by library itself

NameDescription
download_preparedThis event is reported when a download is prepared
download_startedThis event is reported when a download is started
download_pausedThis event is reported when a download is paused
download_resumedThis event is reported when a download is resumed
download_stoppedThis event is reported when a download is stopped
download_completedThis event is reported when a download is completed
download_deletedThis 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.

FLAnalyticsFactory.applicationSession.addEvent(event: <#T##String#>, attributes: <#T##[String : Any]?#>)
note
  1. 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"
  2. In datazoom, any custom event will be reported as event name with custom_ prefix. (eg: playback_start as custom_playback_start)
caution

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. Also use this api to update the metadata.

FLAnalyticsFactory.applicationSession.updateMetadataRecord(metadata: <#T##[String : Any]#>)

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.

FLAnalyticsFactory.applicationSession.stop(error: <#T##FLError?#>)

Report Non-fatal errors

Any application non-fatal error can be reported using below API. Send FLError to report playback stop on any error.

FLAnalyticsFactory.applicationSession.addErrorEvent(error: <#T##FLError#>)

Download Errors

Any Download error can be reported using below API. Send Error to report download stop on any error.

downloadSession.stop(error: <#T##FLError?#>)

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

NameTypeRequiredDescription
codeStringtrueThe unique error code.
messageStringtrueThe message describing the error.
descriptionStringfalseThe contextual description of the error.
let userError = UserError(code: <#T##String#>, message: <#T##String#>, description: <#T##String?#>)
userSession.addErrorEvent(error: <#T##UserError#>, value: <#T##User#>)

Out-of-box Player Metrics

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.

  • AverageVideoBitrate - The average bitrate of video track if it is unmuxed. Measured in bits per second.

  • AverageAudioBitrate - The average bitrate of audio track. Measured in bits per second.

  • IndicatedBitrate - The throughput required to play the stream, as advertised by the server. Measured in bits per second.

  • DroppedFrames - The total number of dropped video frames.

  • ObservedBandwidth - Provides the Observed bandwidth.

  • BufferedRange - The accumulated duration of the media downloaded in the buffer so far (ratio of currentPosition and bufferedDuration).

  • Playback Interruption Rate - Playback is interrupted whenever the media chunks are not available at a rate equivalent to the rate at which the player consumes the chunks.

  • Playback Interruption Wait Ratio - Time taken to recover from playback interruption depends on two factors primarily, network bandwidth and variant availability.

  • Media Quality of Playback - The measure of streaming quality is a number which says, is the user presented with the best possible media quality.

  • Playback Failure Rate - The measure of total failures rate

AVPlayer provides playback statistics and error statistics via AVPlayerItemAccessLogEvent and AVPlayerItemErrorLogEvent objects. The below code snippet demonstrates how to get these informations. The AVPlayer instance is made available through rawPlayer property on FLPlayer.

// Register to receive notifications whenever a new access log entry or entry log entry is available with AVPlayer
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

NotificationCenter.default.addObserver(self,
selector: #selector(self.handlePlayerItemNewErrorLogEntry(notification:)),
name: .AVPlayerItemNewErrorLogEntry,
object: nil)

NotificationCenter.default.addObserver(self,
selector: #selector(self.handlePlayerItemNewAccessLogEntry(notification:)),
name: .AVPlayerItemNewAccessLogEntry,
object: nil)
}

@objc func handlePlayerItemNewErrorLogEntry(notification _: Notification) {
guard let avplayer = player?.rawPlayer as? AVPlayer,
let currentItem = avplayer.currentItem,
let errorLog = currentItem.accessLog() else { return }
if let errorLogEvent = errorLog.events.last {
// process error log event
}
}
@objc func handlePlayerItemNewAccessLogEntry(notification _: Notification) {
guard let avplayer = player?.rawPlayer as? AVPlayer,
let currentItem = avplayer.currentItem,
let accessLog = currentItem.accessLog() else { return }
if let accessLogEvent = accessLog.events.last {
// process access log event
}
}

For further reading on access log and error log events, please check Measure Playback Performance section of apple document¹.

note

Please refer to PlayerStats class in the FLPlayerSampleApp that comes with the library package.