Google Analytics Utility

Actionscript:
  1. package com.hapticdata.utils
  2. {
  3.     import flash.external.ExternalInterface;
  4.     /**
  5.      * Simplifies posting to Google's Analytics Tracker, allows easily disabling for development phase
  6.      * and uses ExternalInterface rather than navigateToURL
  7.      * @class Urchin
  8.      * @author Kyle Phillips - <a href="http://www.haptic-data.com">http://www.haptic-data.com</a>
  9.      * @created October 28, 2008
  10.      * @example Analytics.post("section");
  11.      */
  12.    
  13.    
  14.     public class Analytics
  15.     {
  16.        
  17.         public static var enabled:Boolean = true;
  18.         //appended as a directory to all trackings
  19.         public static var swfID:String="/flashevent/";
  20.         //correct for default snippet. Change this if you have a custom-wrapped analytics method
  21.         public static var functionToCall:String = "pageTracker._trackPageview";
  22.        
  23.         /**
  24.          * Will invoke the set javascript function
  25.          * @param location:String - a string identifying where the user is in the site
  26.          */
  27.         public static function post(location:String):void
  28.         {
  29.             if(enabled && ExternalInterface.available)
  30.             {
  31.                 ExternalInterface.call(functionToCall,swfID+location);
  32.             }
  33.         }
  34.     }
  35. }

This contest entry by Kyle Phillips is a utility class for dealing with google analytics. If you haven't messed with google analytics I suggest you give it a try.

Kyle Phillips links:
>> http://workofkylephillips.com
>> http://labs.hapticdata.com

I usually find myself adding google analytics code in a very hacky way... usually because the client asks for it at the 11th hour. Using a class like Kyle's would enable you to simply add the tracking code from the start and then if the client doesn't ask for it... you can just keep the class disabled... or charge more when you offer google analytics tracking for "phase 2" of the project ;)

This entry was posted in external data, misc and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted November 9, 2009 at 5:46 pm | Permalink

    Hi!

    I often use :
    navigateToURL(new URLRequest(”javascript:pageTracker._trackPageview(…

    To deal with analytics.
    I think ExternalInterface with its Synchronous communication could slow the code execution when you track a page.

    But with navigateToUrl you can loose some information when to call start at the same time :

    [..]
    navigateToURL(new URLRequest(”javascript:pageTracker._trackPageview(“the-first”);
    navigateToURL(new URLRequest(”javascript:pageTracker._trackPageview(“the-second”);
    […]

    “the-first” is never called.

    It’s possible to use Timer or Enter_Frame to make delay but it’s not very well.

    Do you have feedback with ExternalInterface Performances?

  2. Posted November 12, 2009 at 6:50 am | Permalink

    Google also provides a class of their own:
    http://code.google.com/p/gaforflash/

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*