Analytics ActionScript 3.0 API

How does the analytics plug-in work?

Anvato Analytics module is implemented in ActionScript 3.0 and dynamically loaded by the Flash player. It listens to video, user engagement, and ad impression events silently and sends them to the Anvato Analytics server farm for processing. Since the plug-in sends data silently to your Anvato analytics account, you will not notice anything different about your player after it is installed.

 

 

Step 1: The plug-in gets loaded

As soon as the video player is loaded by the browser, the player will dynamically loads the plug-in from Anvato's plugin server (http://plugins.anvato.com/). You can use the Anvato open source plugin loader class that load plugins from anvato plugin site (download the sample example and anvato loader action script class ) This is a preferred method to make sure that player always loads most uptodate and smallest size of anlaytics plugin custumized for loading player.

import com.anvato.analytics.PluginLoader; private var anvatoplugins:PluginLoader; public var analytics:Object = null; private function initPlayer():void{ LoadAnvatoPlugins(initVideo); } private function LoadAnvatoPlugins(callbackFunction:Function=null):void { try{ if (callbackFunction) this.addEventListener('AnvatoPluginsReady',callbackFunction); anvatoplugins = new PluginLoader(); anvatoplugins.addEventListener(PluginLoader.PLUGINS_READY, onAnvatoPluginsReady); anvatoplugins.config['analytics'] = PluginLoader.OVP_PLAYER_2_2; anvatoplugins.load(); } catch(e:Error){ this.dispatchEvent(new Event('AnvatoPluginsReady')); } } private function initVideo(e:Event=null):void { playVideo(); }

Alternativly, Plugin can be loaded is using Adobe’s standard swfloader classes or any of your favorite swf loader class from Anvato's plugin site. In this case, you should load the plugin from http://plugins.anvato.com/1.5/as3/anvatoanalytics.swf and you sould set the type of your flash player during plugin-activation step using configration setting (e.g. analytics.config['type'] = 'ovp').

Step 2: The plug-in gets activated with initialize() API Call

After the plug-in is loaded and ready, the second step is to configure and activate the anlaytics plugin. Plugin is configured by setting necessary options and paremnetres using plugins config variable. Configuration is where you will tell plugin, tracker key, player url, and player name as well as any player-specific (e.g. netStream object) object that player will listen for AnalyticEvents.

Once configuration done, you need to activate the plugin. This is done by calling plug-in’s initialize() action script API call. Once the plugin activated, it is ready to send any analytic event to server if configuration is set correctly.

private function onAnvatoPluginsReady(e:Event):void{ if (anvatoplugins.plugins['analytics']){ analytics= anvatoplugins.plugins['analytics'].content; if (analytics){ //configuring anlytic plugin analytics.config['tracker'] = this.parameters['tracker']; analytics.config['url'] = this.url; analytics.config['name'] = 'my ovp player 2.2'; //active anlytic plugin analytics.initialize(); //passing additional ui component to plugin to listen anlaytic events analytics.listenComponent(this); // to listen any event dispatch by player analytics.listenComponent(embedComp); analytics.listenComponent(shareComp); } } // let the player know the analytics plugin is initizliaed and ready to load this.dispatchEvent(new Event('AnvatoPluginsReady')); }

It is importent to load and activate the plugin before player starts playing video for completeness of the anlaytics events.

Step 3: The Video URL is set with onLoad() API Call

Once the video url is avaialable, you will use onLoad() api call to pass video-specific infromation such as video URL, video Title, video ID (if you have one for your CMS), video tags, and stream type. Video URL is key variable need to be set correctly. Any event that is going to be send to server will be associated that video_URL so onLoad() api should be called everytime the player will start playing a new video.

private function loadVideo():void{ ..... if (analytics) analytics.onLoad(VideoURL,VideoTitle,VideoID,VideoTags,StreamType); ..... }

Step 4 : Stream object are passed to plugin using addVideoStream() API call

Plugin listens to video events from stream or video object depens of the player type(e.g. netStream Flash, videoDisplay in Flex, OVPNetStream in OVP etc). AddVideoStream() api call allow you to pass video object to plugin for listeing video event whenever the videoobject is created. This will tell plugin to start listeing and reporting video events seemsly.

private function connectionReady(e:Event):void{ ........... _ns = new OvpNetStream(_nc); if (analytics) analytics.addVideoStream(_ns); playVideo(..); .......... }

Alternativly, you can configure the plugin to listen video object uising config varibale if the video/stream object has alrrady created and ready before the plugin is loaded. If the player play more than one video in a session, such as preroll, midroll or postroll in-video ads and main video. There are two function call that need to be used to differentiate main video event from ads event. Whenever the main video will be played or resumed, addVideoStream(netStreamObject) API call should be used, and whenever in video ads will be played, addAdStream(netStreamObject, ad_url,ad_id, ad_type) api call should be used. When the video ends, removeVideoStream() or removeAdStream() API call ised used.

Step 5 : The analytics events are dispatched with sendEvent() API call

By default, plugin listens all the video events generated by video/stream object. You do not need to do anything for these video events. However anvato anlaytcs plugin gives you flexiable to to send User engamenet venets, AD events or custom events to server. Why it is important, because this way you can distinuqish wther the user clik to pause video or player pause the video, or distinquish that user shared the video by email etc. In order to send the specifc User or Ad events to player, you have two option:

Using plugin's sendEvent() api call to send events to server

private function doPlayPause():void { switch (bPlayPause.label){ case "PAUSE": _ns.pause(); if (analytics) analytics.sendEvent(com.anvato.analytics.AnalyticEvent.User_Pause,_ns.time.toString()); break; case "PLAY": bPlayPause.label = "PAUSE"; _ns.resume(); if (analytics) analytics.sendEvent(com.anvato.analytics.AnalyticEvent.User_Play,_ns.time.toString()) break; } } }

dispatching AnlayticsEvent from player or any oether UI component:

private function shareClicked():void{ var linkToCall:String = "http://www.facebook.com/share.php?u=www.anvato.com"; this.dispatchEvent(AnalyticEvent.event(AnalyticEvent.User_Share,'facebook:'+int(time).toString())); navigateToURL(new URLRequest(linkToCall)); }

 

Special Cases for complex players:

 

How to handle if player plays both video and invideo ads using same video component

If the player play more than one video in a session, such as preroll, midroll or postroll in-video ads and main video. There are two function call that need to be used to differentiate main video event from ads event. Whenever the main video will be played or resumed, addVideoStream(netStreamObject) API call should be used, and whenever in video ads will be played, addAdStream(netStreamObject, ad_url,ad_id, ad_type) api call should be used. When the video ends, removeVideoStream() or removeAdStream() API call ised used.

How to handle if player plays video using http-seek

If the player uses http-seek instead of rtmp streaming or http downloading, onLoad() function must be call once the video starts, but addVideoStream() should be used subsequent seek operation. This will keep integrity of the analytics.