Click here to Skip to main content
13,001,686 members (98,035 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 19 Apr 2010

Using Google Analytics in Flash

, 19 Apr 2010
Rate this:
Please Sign up or sign in to vote.
Using Google Analytics in Flash is a very straightforward approach, I just found some of my Flash Projects with one so might as well share how I made it.

Using Google Analytics in Flash is a very straightforward approach, I just found some of my Flash Projects with one so might as well share how I made it.

What do you need?

  1. Your Flash Code
  2. Analytics Library for Flash which you can get here
  3. Definitely an Account with Google

Now once you have everything in place, just add the Analytics to your library by going to File -> Import -> Import to Library.

Import To Library

Once imported, you can see it in your library and use it.

GA in Library

Once it's there, you can now add a reference of the library in your code as shown below:


If you want to check the version you are using, add this piece to your code:


Now for the code:

var tracker:AnalyticsTracker = new GATracker( this, "XX-9999999-1", "AS3", false );

//track on click and separate in different folders
var onButtonClick:Function = function( event:Event ):void
 tracker.trackPageview( "/Your Folder/" );
 var request:URLRequest = new URLRequest("");
 navigateToURL(request, "_self");

TrackBtn.addEventListener( MouseEvent.CLICK, onButtonClick );

Now let's dissect what's happening:

In the code,

new GATracker( this, "XX-9999999-1?, "AS3?, false );
  • The second parameter would be your Web Property ID – This is also known as the UA number of your tracking code and looks like UA-xxxxx-yy.
  • The third parameter is the tracking mode – you have a choice of either AS3 or Bridge.  So what's the difference? Bridge Mode is used if you control both the HTML page and the Flash content (if you own the webserver, you are hosting your page or at least have control on it). This mode is best if you have already implemented Google Analytics (ga.js) tracking on your website and you want to add tracking to embedded Flash content.

    AS3 Mode is used if you control the Flash ActionScript 3 code, but you do not own or at least control the webserver. This is completely independent of the Google Analytics (ga.js) tracking and contains all the tracking functionality.  This is good to use if you want to distribute your Flash applications to different sites.

  • The fourth parameter is the debugging mode -  I guess this is self explanatory.

Now in the code:

tracker.trackPageview( "/Your Folder/" )

This is just simply incrementing the pageview count for the virtual page “/Your Folder”.

So that's it! It's really simple and straight forward.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Raymund Macaalay
Technical Lead
New Zealand New Zealand

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 19 Apr 2010
Article Copyright 2010 by Raymund Macaalay
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid