« back to blog Posts Tagged ‘flash analytics’

Track flash events in google analytics

This relatively easy method is especially useful as it does not require your file to be included in a HTML page, as many other techniques do.

Download the AnalyticsLibrary component here: http://code.google.com/p/gaforflash/downloads/list and follow the instructions in the readme.txt file to install the Flash component.

Create a new flash file called Tracker.fla and an actioscript file called Tracker.as. When installed correctly you can drag the  AnalyticsLibrary component from the components panel into your fla’s library. Add the following code to your Analytics.as file.

package {

    import com.google.analytics.AnalyticsTracker;
    import com.google.analytics.GATracker;
    import flash.display.MovieClip;

    public class Tracker extends MovieClip {

        private var tracker:AnalyticsTracker;

        public function Tracker():void
        {
            tracker = new GATracker( this, "UA-111-222", "AS3", true );
            tracker.trackPageview("/initial-load");
        }
    }
}

First import the two analytics libraries we will be using, AnalyticsTracker and GATracker. Then we create a new instance of the AnalyticsTracker, which needs four paramaters:

  • The current display object (“this”)
  • Your analytics account ID (“UA-111-222”)
  • The tracking mode, either Bridge or AS3.
  • The debug mode. This defines whether helpful messages will be displayed for errors. You should set this to true when testing and false when your application is live.

Finally, the trackPageview method creates a new page view on your google analytics account. This method can of course be placed inside a button click method or similar. To test, enter Tracker as the document class on Tracker.fla and press Ctrl+Enter to test the movie. See the results below:

If anyone needs it I can also upload the source!

Happy tracking

This tip and others from We Love are in the latest issue of Web Designer Magazine in the article “55 Pro Flash Tips”! Look out for Gavin Clark.