This document covers everything you need to know to set up Google Analytics Tracking for Adobe Flash for the Adobe Flash development environment.
The Flash tracking component files are compressed into a single ZIP file that you can download from http://code.google.com/p/gaforflash/downloads/list.
Follow the instructions in the readme.txt file to install the Flash components.
Google directory in one of the following locations:
C:\Program Files\Adobe\ Adobe Flash CS3\language\Configuration\Components Macintosh HD/Applications/Adobe Flash CS3/Configuration/Components lib/analytics_flash.swc — The Analytics Componentlib/analytics.swc — The Analytics Library ComponentBoth components have the same functionality, but are provided as a convenience for different development styles.
Analytics component. If you develop Flash content, but are unfamiliar with ActionScript 3, use this component. The Analytics component is a complete tracking package. Just drag and drop the components directly onto your stage, make a few simple configurations in the component inspector, and you're ready to tag your controls with Analytics tracking.
AnalyticsLibrary component. If you are familiar with ActionScript 3, you can use the AnalyticLibrary component. Drag the component to your Flash Library and import the tracking classes directly into your ActionScript code.
Use the analytics_flash.swc to implement tracking via the Analytics component. Place the component in the correct Component directory, and it appears in the Components panel (Window - Components).
Because of the way Flash works with visual components, it's generally best to start tracking on the second frame of your Flash application. If you need to initialize tracking on the first frame, place the tracking calls inside event handlers to ensure the component is fully initialized within the Flash content.
The following code snippet shows how a button in Flash can be tracked when someone clicks it. In this example, the button instance is named playGame in your ActionScript. When the button is clicked, the onButtonClick method is called, which in turn invokes the trackPageview() method. This increments the pageview count for the virtual page /myGame1.
playGame.addEventListener( MouseEvent.CLICK, onButtonClick );
function onButtonClick( event:Event ):void
{
tracker.trackPageview( "/myGame1");
}
Use the analytics.swc file to implement tracking via the AnalyticsLibrary component. This component lets you instantiate a tracking object directly in your AS3 code. Once the AnalyticsLibrary component is in the proper location, it appears in the Components panel. You can then drag the component from the Components panel into your library, and from there import the libraries into your ActionScript code.
Using the Adobe Flash environment, initialize the tracking object with the following parameters:
this references the display object. Bridge or AS3. debug to false for production use and to true for validation and troubleshooting.In the following example, a movie clip called playGame exists on the stage. A new tracking object called tracker is created along with an event handler that listens for a mouse click. When the button is clicked, the onButtonClick function is called. For each click, the trackPageview() method increments the pageview count for the virtual page /myGame1.
import com.google.analytics.AnalyticsTracker;
import com.google.analytics.GATracker;
var tracker:AnalyticsTracker = new GATracker( this, "UA-111-222", "AS3", true );
playGame.addEventListener( MouseEvent.CLICK, onButtonClick );
function onButtonClick ( event:Event ):void
{
tracker.trackPageview("/myGame1");
}