Tag Archives: google analytics

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

Posted in external data, misc | Also tagged , , , | 2 Comments