Announcing Google Analytics Plug-in For OSMF, The GTrack Plug-in

Posted on September 27, 2010 at 9:12 am in Development, Media Solutions, Strategic Consulting

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>

  1. Add the <event> node to the XML configuration
  2.         <event name="complete" category="video" action="complete" label="trackingTesting" value="1" />
  3. Add a MetadataValue to the URLResource object for the MediaElement
  4.         var resource:URLResource = new URLResource( PROGRESSIVE_PATH );
            resource.addMetadataValue( GTRACK_NAMESPACE, {pageURL:"AnalyticsTestVideo"} );
  5. Create the MediaElement
  6.         var element:MediaElement = mediaFactory.createMediaElement( resource );

This will track the String ‘AnalyticsTestVideo’ instead of the URL of the media resource.

  1. Set up the player
  2.         protected function initPlayer():void
            {
                    mediaFactory = new DefaultMediaFactory();
                    player = new MediaPlayer();
                    container = new MediaContainer();                      
                    this.addChild( container );
                    loadPlugin( {PATH_TO_GTRACK_PLUGIN_SWF} );
            }
  3. Set up a loadPlugin() method.
  4. Create a URLResource that points to the GTrackPlugin.swf
  5.         var pluginResource:MediaResourceBase = new URLResource( {PATH_TO_GTRACK_PLUGIN_SWF} );
  6. Add the XML configuration to the pluginResource as a MetaData value – ‘gTrackPluginConfigXML’ is an XML variable
  7.         pluginResource.addMetadataValue( "http://www.realeyes.com/osmf/plugins/tracking/google", gTrackPluginConfigXML );
  8. Listen for the plugin load events
  9.         mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded );
            mediaFactory.addEventListener( MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadFailed );
  10. Load the plugin
  11.         mediaFactory.loadPlugin( pluginResource );
  12. The loadPlugin() method should look something like:
  13.         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 );
            }
  14. Once the plugin is loaded, remove the plugin listeners and load the media
  15.         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

Contact RealEyes

For more information about OSMF plug-ins, or to inquire about custom plug-in development:

* Required


Comments

  1. Chris 13 December 2010 at 12:40 pm permalink

    Do you have any examples on how to implement it?

  2. Haakon 14 February 2011 at 9:09 am permalink

    It seems that the plugin keeps “timeWatched” and “percentageWatched” even after the video is paused.

  3. Haakon 14 February 2011 at 9:10 am permalink

    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.

    • John 14 February 2011 at 11:11 am permalink

      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.

  4. Haakon 14 February 2011 at 2:02 pm permalink

    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 ;)

  5. Jaime 7 July 2011 at 2:00 pm permalink

    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?

  6. Pablo 16 November 2011 at 7:18 am permalink

    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.

    • John Crosby 20 November 2011 at 12:11 pm permalink

      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.

  7. Pablo 23 November 2011 at 5:59 am permalink

    Thanks John,

    I’m still having issues on this.

    Do you have another example of this implementation?

    Thanks!

    Pablo.

  8. Pablo 27 December 2011 at 12:12 pm permalink

    Hi, is it possible to set it for a custom domain?
    The tracking works but for the general domain.
    Thx.
    Pablo

  9. Jeremy 18 January 2012 at 6:13 pm permalink

    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.

  10. Pablo 13 February 2012 at 11:52 am permalink

    Hi Jeremy,
    Were you able to add the player?
    I can give a url to you with an easy implementation of it.

    Regards,
    Pablo.

  11. Tim Baldwin 15 March 2012 at 12:22 pm permalink

    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?