AS2: GoogleAnalyticsUtils
View Documentation
Download Class
GoogleAnalyticsUtils is a utility class to easily track your clicks using Google Analytics. The class allows you to track in the old Urchin format or the new Event format as well as tracking with the old AS2 "javascript" calls or tracking with the new ExternalInterface API.
This class is a follow-up to my original post about using Google Analytics in your Flash projects.
-
import flash.external.ExternalInterface;
-
-
/**
-
* A utility class to easily track your clicks using Google Analytics. The class allows you to track in the old Urchin format or the new Event format
-
* as well as tracking with the old AS2 "javascript" calls or tracking with the new ExternalInterface API.
-
*
-
* @author Matt Przybylski [http://www.reintroducing.com]
-
* @version 1.0
-
*/
-
-
class com.reintroducing.utils.GoogleAnalyticsUtils
-
{
-
//- PRIVATE VARIABLES -------------------------------------------------------------------------------------
-
-
-
-
//- PUBLIC VARIABLES --------------------------------------------------------------------------------------
-
-
-
-
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
-
-
public function GoogleAnalyticsUtils()
-
{
-
-
}
-
-
//- PRIVATE METHODS ---------------------------------------------------------------------------------------
-
-
-
-
//- PUBLIC METHODS ----------------------------------------------------------------------------------------
-
-
/**
-
* Uses the old Urchin method in Google to track the page.
-
*
-
* @param $path The path that you want to appear in your analytics to track the selected item.
-
*/
-
public static function urchinTrack($path:String):Void
-
{
-
getURL("javascript:urchinTracker('" + $path + "');");
-
}
-
-
/**
-
* Uses the new Event method in Google to track the page.
-
*
-
* @param $path The path that you want to appear in your analytics to track the selected item.
-
*/
-
public static function eventTrack($path:String):Void
-
{
-
getURL("javascript:pageTracker._trackPageview('" + $path + "');");
-
}
-
-
/**
-
* Uses ExternalInterface and the old Urchin method in Google to track the page.
-
*
-
* @param $path The path that you want to appear in your analytics to track the selected item.
-
*
-
* @return Object The response received from the container.
-
*/
-
public static function urchinEITrack($path:String):Object
-
{
-
return ExternalInterface.call("urchinTracker", $path);
-
}
-
-
/**
-
* Uses ExternalInterface and the new Event method in Google to track the page.
-
*
-
* @param $path The path that you want to appear in your analytics to track the selected item.
-
*
-
* @return Object The response received from the container.
-
*/
-
public static function eventEITrack($path:String):Object
-
{
-
return ExternalInterface.call("pageTracker._trackPageview", $path);
-
}
-
-
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
-
-
-
-
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
-
-
-
-
//- HELPERS -----------------------------------------------------------------------------------------------
-
-
public function toString():String
-
{
-
return "com.reintroducing.utils.GoogleAnalyticsUtils";
-
}
-
-
//- END CLASS ---------------------------------------------------------------------------------------------
-
}
An example usage of the class (using the Event tracking method with External Interface) would be as follows:
-
GoogleAnalyticsUtils.eventEITrack("/home/portfolio");
As you can see, the usage is very straightforward and all methods of the class are static. The path can be whatever you want it to be. This is just so that you can easily identify the path/buttons which your users clicked through when you view your stats in Google Analytics.
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.













Matt , thanks for sharing. That's exactly what I was looking for.