Actionscript:
-
package com.hapticdata.utils
-
{
-
import flash.external.ExternalInterface;
-
/**
-
* Simplifies posting to Google's Analytics Tracker, allows easily disabling for development phase
-
* and uses ExternalInterface rather than navigateToURL
-
* @class Urchin
-
* @author Kyle Phillips - <a href="http://www.haptic-data.com">http://www.haptic-data.com</a>
-
* @created October 28, 2008
-
* @example Analytics.post("section");
-
*/
-
-
-
public class Analytics
-
{
-
-
public static var enabled:Boolean = true;
-
//appended as a directory to all trackings
-
public static var swfID:String="/flashevent/";
-
//correct for default snippet. Change this if you have a custom-wrapped analytics method
-
public static var functionToCall:String = "pageTracker._trackPageview";
-
-
/**
-
* Will invoke the set javascript function
-
* @param location:String - a string identifying where the user is in the site
-
*/
-
public static function post(location:String):void
-
{
-
if(enabled && ExternalInterface.available)
-
{
-
ExternalInterface.call(functionToCall,swfID+location);
-
}
-
}
-
}
-
}
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