Announcing Google Analytics Plug-in For OSMF, The GTrack Plug-in
The GTrack plugin has been built as an example of an OSMF proxy plugin. The plugin is able to send page tracking and event tracking for an OSMF MediaElement. The GTrack plugin uses the gaforflash library to send tracking to google analytics.
Page tracking is per MediaElement. Basically when the MediaElement is loaded and begins to play the URL of the resource is sent as a pageView to Google Analytics. You can also configure the value that is sent by adding metadata to the URLResource for the MediaElement. An example of this can be found in the Configuration section.
Events are sent to Google Analytics based on an XML configuration. Each of the MediaElements main traits can be configured to send a tracking event.
The GTrack plugin determines which tracking should be sent and what values are sent to Google Analytics via XML configuration.
This node specifies the Google Account to associate the tracking with. You can specify multiple <account> nodes to send tracking to multiple accounts. The value for this node can be found in your Google Analytics account and should look similar to – ‘UA-1234567-1′.
Example:
<account><![CDATA[UA-1782464-4]]></account> <account><![CDATA[UA-1782464-5]]></account>
The <url> node is the URL that was set as the profile URL to be tracked by Google Analytics.
Example:
<url><![CDATA[http://osmf.realeyes.com]]></url>
The <event> node is what defines the tracking that will be sent to your Google Analytics account. The ‘name’ attribute of the node is the key that tells the GTrack plugin to send an event. So, the names much match exactly. There are multiple types of events that can be tracked:
Example:
<event name="percentWatched" category="video" action="percentWatched"> <marker percent="0" label="start" /> <marker percent="25" label="25PercentView" /> <marker percent="50" label="50PercentView" /> <marker percent="75" label="75PercentView" /> </event>
This configuration example will track the start, 25, 50 & 75 percent markers as the media item is played. The complete is tracked by the complete event see MediaElement Events below.
Example:
<event name="timeWatched" category="video" action="timeWatched"> <marker time="5" label="5sec" /> <marker time="10" label="10sec" /> <marker time="20" label="20sec" /> </event>
This example will send tracking at 5, 10, & 20 seconds respectively
MediaElement events are based off of the MediaElement’s available Traits. If the MediaElement supports a specific trait and there is an event that can be associated with the trait tracking can be defined for it. Example:
<event name="complete" category="video" action="complete" label="trackingTesting" value="1" />
This example will send tracking when the MediaElement has completed playing.
The <updateInterval> node defines the interval that the GTrack plugin checks the current time and position of the currently playing MediaElement to determine when to send the time and/or percentage based tracking.
The <debug> node is not currently used but is planned to be implemented as a custom logging & debugging feature.
The node attributes (except for the name attribute) correspond to the tracking values defined in the Google Analytics Tracking API for Event Tracking
- category: String – The general event category (e.g. “Videos”).
- action: String – The action for the event (e.g. “Play”).
- label: String – An optional descriptor for the event.
- value: Int – An optional value associated with the event. You can see your event values in the Overview, Categories, and Actions reports, where they are listed by event or aggregated across events, depending upon your report view.
Sample XML configuration:
<value key="reTrackConfig" type="class">
<!-- Set your analytics account ID -->
<account><![CDATA[UA-1782464-4]]></account>
<!-- You can track to multiple analytics accounts by adding additional <account /> nodes -->
<!-- <account><![CDATA[{ADDITIONAL_GA_ID}]]></account> -->
<!-- Set the url that you registered with your GA account -->
<url><![CDATA[http://osmf.realeyes.com]]></url>
<!-- Set up the percent based tracking -->
<event name="percentWatched" category="video" action="percentWatched">
<marker percent="0" label="start" />
<marker percent="25" label="view" />
<marker percent="50" label="view" />
<marker percent="75" label="view" />
</event>
<!-- Set up the event tracking for the completed event -->
<event name="complete" category="video" action="complete" label="trackingTesting" value="1" />
<!-- Set up the event tracking for the completed event -->
<event name="pageView" />
<!-- These are the other available events that can be tracked -->
<!--
<event name="autoSwitchChange" category="video" action="autoSwitchChange" />
<event name="bufferingChange" category="video" action="bufferingChange" />
<event name="bufferTimeChange" category="video" action="bufferTimeChange" />
<event name="bytesTotalChange" category="video" action="bytesTotalChange" />
<event name="canPauseChange" category="video" action="canPauseChange" />
<event name="displayObjectChange" category="video" action="displayObjectChange" />
<event name="durationChange" category="video" action="durationChange" />
<event name="loadStateChange" category="video" action="loadStateChange" />
<event name="mediaSizeChange" category="video" action="mediaSizeChange" />
<event name="mutedChange" category="video" action="mutedChange" />
<event name="numDynamicStreamsChange" category="video" action="numDynamicStreamsChange" />
<event name="panChange" category="video" action="panChange" />
<event name="playStateChange" category="video" action="playStateChange" />
<event name="seekingChange" category="video" action="seekingChange" />
<event name="switchingChange" category="video" action="switchingChange" />
<event name="traitAdd" category="video" action="traitAdd" />
<event name="traitRemove" category="video" action="traitRemove" />
<event name="volumeChange" category="video" action="volumeChange" />
<event name="recordingChange" category="dvr" action="recordingChange" />
-->
<!-- Time based tracking (in seconds)-->
<!--
<event name="timeWatched" category="video" action="timeWatched">
<marker time="5" label="start" />
<marker time="10" label="start" />
<marker time="20" label="start" />
</event>
-->
<debug><![CDATA[true]]></debug>
<!-- How often you want the timer to check the current position of the media (milliseconds) -->
<updateInterval><![CDATA[250]]></updateInterval>
</value>
- Add the <event> node to the XML configuration
- Add a MetadataValue to the URLResource object for the MediaElement
- Create the MediaElement
<event name="complete" category="video" action="complete" label="trackingTesting" value="1" />
var resource:URLResource = new URLResource( PROGRESSIVE_PATH );
resource.addMetadataValue( GTRACK_NAMESPACE, {pageURL:"AnalyticsTestVideo"} );
var element:MediaElement = mediaFactory.createMediaElement( resource );
This will track the String ‘AnalyticsTestVideo’ instead of the URL of the media resource.
- Set up the player
- Set up a loadPlugin() method.
- Create a URLResource that points to the GTrackPlugin.swf
- Add the XML configuration to the pluginResource as a MetaData value – ‘gTrackPluginConfigXML’ is an XML variable
- Listen for the plugin load events
- Load the plugin
- The loadPlugin() method should look something like:
- Once the plugin is loaded, remove the plugin listeners and load the media
protected function initPlayer():void
{
mediaFactory = new DefaultMediaFactory();
player = new MediaPlayer();
container = new MediaContainer();
this.addChild( container );
loadPlugin( {PATH_TO_GTRACK_PLUGIN_SWF} );
}
var pluginResource:MediaResourceBase = new URLResource( {PATH_TO_GTRACK_PLUGIN_SWF} );
pluginResource.addMetadataValue( "http://www.realeyes.com/osmf/plugins/tracking/google", gTrackPluginConfigXML );
mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded ); mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadFailed );
mediaFactory.loadPlugin( pluginResource );
private function loadPlugin( source:String ):void
{
// Create the plugin resource
var pluginResource:MediaResourceBase = new URLResource( source );
// Add the configuration data as Metadata to the pluginResource
pluginResource.addMetadataValue( GTRACK_NAMESPACE, gTrackPluginConfigXML );
// Set up the plugin listeners
mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded );
mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadFailed );
// Load the plugin
mediaFactory.loadPlugin( pluginResource );
}
protected function onPluginLoaded( event:MediaFactoryEvent ):void
{
// Remove the plugin listeners
mediaFactory.removeEventListener( MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded );
mediaFactory.removeEventListener( MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadFailed );
// Create the media resource
var resource:URLResource = new URLResource( PROGRESSIVE_PATH );
// Set up the page tracking
resource.addMetadataValue( GTRACK_NAMESPACE, { pageURL:"AnalyticsTestVideo" } );
// Create & set the MediaElement
var element:MediaElement = mediaFactory.createMediaElement( resource );
player.media = element;
container.addMediaElement( element );
}
http://code.google.com/p/reops/source/browse/#svn/trunk/plugins/tracking/google/GTrackPlugin
- The gaforflash API is released under a Apache License 2.0
- The REOPS project & the GTrack OSMF Plugin is released under the Mozilla Public License 1.1
Contact RealEyes
For more information about OSMF plug-ins, or to inquire about custom plug-in development:






Do you have any examples on how to implement it?
Sorry for the delayed response Chris.
The Google code wiki has configuration and usage information: http://code.google.com/p/reops/wiki/GTrackPlugin
It seems that the plugin keeps “timeWatched” and “percentageWatched” even after the video is paused.
Some text was missing in the previous comment:
It seems that the plugin keeps sending “timeWatched” and “percentageWatched” to GA even after the video is paused.
Thanks @Haakon –
Sounds like a bug & we’ll look into it. If you need a fix immediatley, you can checkout the source for the plugin from the Google Code repo. The GTrack plugin is part of the REOPS project: http://code.google.com/p/reops/wiki/GTrackPlugin – if you do fix the issue and would like to contribute a patch to the project it would be appreciated. Just let us know.
Hi John, I’ve looked into it, and it seems like the _currentTimeTimer needs to be paused some how within processPlayStateChange. I’ll see if I can contribute on the issue and report back
Haakon – I’ve just uplaoded a new SWF to the Google Code site that should fix the tracking while paused issue.
https://code.google.com/p/reops/downloads/detail?name=GTrackPlugin.swf
Let me know if it is working better for you now. Thanks for being patient and willing to submit a patch for it.
Need help, Hi Im really lost I do not understand How to implement this plug in, Im new in all of this, need help, I put the plugin in the same file as my strobeplayer.swf and the I copy this code for the gtrack plug in
plugin_myPlugin1=http://www.burstmediausa.com/streams/burst/GTrackPlugin.swf& myPlugin1_namespace=http://www.osmf.org/plugin/metadata/1.0
when I run the player in a web show a error message that the taht the Gtrack plugin expects an xml configuration content, where I put this xml and wish name I need to use?
Jamie – have you checked out the sample configuration and usage for GTrack on the Google Code page?
http://code.google.com/p/reops/wiki/GTrackPlugin
Hi I’m trying to add this plugin and I’m not sure if it works.
How long do I have to wait to see the info in GA?
Thx in advance!
Pablo.
It used to be 24 hours but, I have experienced analytics showing up in a couple of hours. Also, Google has real-time analytics in beta right now – so hopefully you won’t have to wait much at all once that it released.
Thanks John,
I’m still having issues on this.
Do you have another example of this implementation?
Thanks!
Pablo.
Did this link help at all? http://osmf.org/dev/1.5gm/youtube-googleanalytics.html?verbose=true
Shoot me an email and let me know. If you want to send the code you’re working with I’d be happy to take a peek.
Hi, is it possible to set it for a custom domain?
The tracking works but for the general domain.
Thx.
Pablo
Hi, I am having a really hard time understanding your documentation.
I’m looking at: http://code.google.com/p/reops/wiki/GTrackPlugin#Usage_Example
Do I need to compile a new player with the example code (what looks like as3 although the initPlayer function does not have declared and typed variables)?
Can I just use the basic strobe player, http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf, and load the plugin and config xml via flashvars?
I would love a basic example of just the GTrackPlugin implementation – flash player src with www build folder html implementation. I find a working basic example a lot easier to understand than instructions based on assumed knowledge.
Hi Jeremy,
Were you able to add the player?
I can give a url to you with an easy implementation of it.
Regards,
Pablo.
I’m having trouble with GTrack and Strobe 1.6. To track down the problem, I cloned the http://osmf.org/dev/1.5.rc1/youtube-googleanalytics.html page and made the following changes. I changed the account info to my GA account, removed the YouTubePlugin.swf and changed the source to http://osmf.org/videos/cathy2.flv. This worked fine and I can see my pageViews and other event data in my GA account. Then I replaced the existing 1.5.rc1 Strobe player with 1.6 and it no longer worked. I tried both http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf as well as my own downloaded v1.6 StrobeMediaPlayback.swf. Any ideas?
Tim – have you tried pulling down the source code and compiling it against the updated OSMF 1.6 framework?
Not yet. That will be my next step but just wanted to see if anyone else experienced the same issue first.
You can try this one: http://www.realeyes.com/osmf/plugins/tracking/GTrackPlugin.swf
I just updated it.
I get the following error when I use the new one:
TypeError- Error #1009: Cannot access a property or method of a null object reference.