General Information
Analytics is now served as a standalone service and you can integrate this component into any javascript-based project other than the empPlayer. Android/iOS libraries already send analytics by themselves. Also, for the empPlayer, analytics are sent automatically aswell. If your project is using an old analytics setup: for instance via plugin or calling the method setAnalytics, you can remove that code from your project as it is no longer necessary. Being a standalone component, EMPAnalytics can now be integrated with more products other than EMPPlayer. This tutorial will show you how to use EMP Analytics. When using the new component, please do not forget to remove the old video.js analytics plugin from your setup, otherwise the EMPPlayer might send duplicated analytics events. The new analytics service is delivered with some important bug fixes. We will no longer deliver new features or bug fixes to the old video.js analytics plugin.
This component collects playback events and sends them every 3s to EMP Exposure backend. In case no event has been generated and a playback is taking place, a Heartbeat event is sent every 60 seconds.
Usage
Installation
npm install empanalytics
In browser, node or react-native
// ES modules;// CommonJSvar EMPAnalytics = ;
Configuration
The following configuration values are required when the plugin is created:
- customer & businessUnit values provided by EMP project team
- serverURL EMP exposure API analytics endpoint
- sessionToken token returned by EMP exposure login API
- userId unique user identifier
If you use the EntitlmentEngine provided by EMP, in order to have analytics, all you have to do is pass these values in as options when instantiating the player:
var exposureOptions = 'customer': customercustomer 'businessUnit': customerbusinessUnit 'sessionToken': sessionsessionToken 'exposureApiURL': apiUrl ; var options = 'ericssonexposure': exposureOptions //...
If you use your own entitlment engine, just include these properties directly as options in your entitlement engine:
yourEMPPlayerObjecentitlementEngine_options_ = 'customer': customercustomer 'businessUnit': customerbusinessUnit 'sessionToken': sessionsessionToken 'exposureApiURL': apiUrl
Methods
Constructor
var deviceInfoData = deviceModel: DEVICE_MODEL_STRING // default: DESKTOP userAgent: USER_AGENT_STRING // default: window.navigator.userAgent screenHeight: SCREEN_HEIGHT // default: window.screen.height screenWidth: SCREEN_WIDTH // default: window.screen.width deviceName: DEVICE_NAME_STRING // default: window.navigator.product deviceOS: DEVICE_OS_STRING // default: platform.os.family deviceOSVersion: DEVICE_OS_VERSION_STRING // default: platform.os.version type: DEVICE_TYPE_STRING // default: WEB deviceManufacturer: DEVICE_MANUFACTURER_STRING deviceId: DEVICE_ID_STRING;var properties = disableWebWorkers: DISABLE_BOOLEAN // default: false
Init
// This method is called to initialize the component.;
Clear
// This method is called to clear all pending analytics events.;
Debug
// This property is called to enable/disable debug.debug = true | false;
Created
// This method is called to add an event for a new plackback// Event: Playback.Createdvar params = autoplay: true techName: TECH_NAME version: TECH_VERSION player: PLAYER_IDENTIFIER deviceAppInfo: APP_INFO_STRING // optional playMode: PLAY_MODE_STRING // optional;;
Play
// This method is called when a 'play' command occurs (automatic or user triggered)// Event: Playback.PlayerReadyvar params = techName: TECH_NAME version: TECH_VERSION deviceAppInfo: APP_INFO_STRING // optional playMode: PLAY_MODE_STRING // optional;;
Playing
// This method is called when the media is actually playing// Event: Playback.Startedvar params = bitrate: BITRATE_IN_BYTES duration: DURATION_IN_SECONDS mediaLocator: MEDIA_URL // optional (.mpd URL p.e.) referenceTime: UNIX_TIME_OF_THE_BEGINNING_OF_STREAM_IN_MS // optional playMode: PLAY_MODE_STRING // optional;;
Paused
// This method is called when the playback is paused.// Event: Playback.Paused;
Seek
// This method is called when a seek occurs.// Event: Playback.ScrubbedTo;
Start Casting
// This method is called when the player starts casting to an external device (chromecast p.e.).// Event: Playback.StartCasting;
Stop Casting
// This method is called when the player stops casting to an external device.// Event: Playback.StopCasting;
Set Current Time
// This method should be called regularly to update the playback current time.;
Handshake
// This method is called when a new asset is loaded.// Event: Playback.HandshakeStartedvar params = assetId: EMP_ASSET_ID programId: EMP_PROGRAM_ID // optional;;
Resume
// This method is called when the playback is resumed from a paused state.// Event: Playback.Resumed;
Bitrate Changed
// This method is called when there is a change in the playback bitrate.// Event: Playback.BitrateChangedvar params = bitrate: BITRATE_IN_BYTES;;
DRM Session Update
// Method for when DRM Session Update// Event: Playback.DRMvar params = message: WIDEVINE_CERTIFICATE_REQUEST FAIRPLAY_CERTIFICATE_REQUEST WIDEVINE_CERTIFICATE_RESPONS FAIRPLAY_CERTIFICATE_RESPONSE WIDEVINE_LICENSE_REQUEST PLAYREADY_LICENSE_REQUEST FAIRPLAY_LICENSE_REQUEST WIDEVINE_LICENSE_RESPONS PLAYREADY_LICENSE_RESPONSE FAIRPLAY_LICENSE_RESPONSE WIDEVINE_LICENSE_ERROR PLAYREADY_LICENSE_ERROR FAIRPLAY_LICENSE_ERROR code: 0 info: 'info';;
End Of Stream
// This method is called when the playback plays all the media to the end.// Event: Playback.Completed;
Error
// This method is called when an error occurs during a playback.// Event: Playback.Errorvar params = errorCode: ERROR_CODE // default: N/A errorMessage: ERROR_MESSAGE // default: Unknown Error;;
Dispose
// This method is called when a user exits/disposes a playback before it reaches the end of the stream.// Event: Playback.Aborted;
Waiting
// This method is called when the player enters goest into a waiting/buffering/loading state.// Event: Playback.BufferingStarted;
Waiting Ended
// This method is called when the player leaves a waiting/buffering/loading state.// Event: Playback.BufferingEnded;
Get Session State
// This getter returns the current state of an analytics session (IDLE, PLAYING, DIRTY, FINISHED).;
Dispatch Now
// This method immediately dispatches all events waiting to be sent to the backend.;
Exit Ongoing Session
// This method automatically disposes ongoing analytics session;
Set Custom Attribute
// This method allows you to register a custom attribute that will be sent on every Playback.Started event;
Clear Custom Attributes
// This method allows you to clear all custom events previously registered;
Usage Example
HTML Code
index.html
Javascript Connector Code
html5player-analytics-connector.js
var { thisplayer_ = html5player; thisanalytics_ = analytics; thisonLoadStartBind = thisonLoadStart; thisonCanPlayBind = thisonCanPlay; thisonPlayingBind = thisonPlaying; thisonEndedBind = thisonEnded; thisonPauseBind = thisonPause; thisonSeekedBind = thisonSeeked; thisonErrorBind = thisonError; thisonAbortBind = thisonAbort; thisonWindowUnloadBind = thisonWindowUnload; this;}; // Initialization function - adds events to the provided playerHTML5PlayerAnalyticsConnectorprototype { this; thisrnd_ = Math; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; window;}; // Returns the session ID being currently analysedHTML5PlayerAnalyticsConnectorprototype { return 'ANALYTICS-DEMO-' + thisrnd_;}; // Function triggered when player starts to load new sourceHTML5PlayerAnalyticsConnectorprototype { this;}; // Sends playback current time to the analytics engineHTML5PlayerAnalyticsConnectorprototype { var sessionId = this; if thisanalytics_getSessionState && thisanalytics_ === 'PLAYING' // This is important for the heartbeats to reflect accurate playback currentTime thisanalytics_; }; // Clears all timers bound to the analytics sessionHTML5PlayerAnalyticsConnectorprototype { ifthiscurrentTimeTimer_ ; thiscurrentTimeTimer_ = null;}; // Registers a timer to send to the analytics engine regular currentTime updatesHTML5PlayerAnalyticsConnectorprototype { this; thiscurrentTimeTimer_ = ;}; // Function triggered when player is able to start playing mediaHTML5PlayerAnalyticsConnectorprototype { var currentSessionId = this; this;}; // Function triggered when player receives a command to start playing mediaHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when the playback is pausedHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when player actually displays the first media elements on the screenHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when the playback reaches the end of the streamHTML5PlayerAnalyticsConnectorprototype { var currentSessionId = this; this;}; // Function triggered when the media is seekedHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when an error occurs within the player's playback sessionHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when the playback session is interrupedHTML5PlayerAnalyticsConnectorprototype { this;}; // Function triggered when the browser window is unloaded/closedHTML5PlayerAnalyticsConnectorprototype { this;}; HTML5PlayerAnalyticsConnectorprototype { if eventFnc && callback ; else console; }; // Function used to unregister callbacks for player events and clear timersHTML5PlayerAnalyticsConnectorprototype { this; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; thisplayer_; window;};