Google Analytics + Flash = Easy Peasy…

You're clients will love it! And in the end you will know more about the sites you build and how to better drive traffic to certain areas! Win! Win!

googleanalytics.jpg

Ok so I have been using Google Analytics for quite sometime now and I must say i love it! So if you don't know by now Google provides FREE website statistics that go above and beyond any stat tracking systems I have seen to date. Well that is for something that is FREE. Anyway I want encourage all of you to get out there and start using Google Analytics for all your flash site going forward. Its really very simple to implement into your flash sites and even track individual events that occur in each of your sites. Please see analytics.google.com for more information on setting up your personal analytics with google and to get the Javascript needed for the code below to work. With that said let's get on to some actionscript!

googleAnalytics.as (right click - save as)

 
/// GOOGLE ANALYTICS SIMPLE TRACKING
/// Script by: corban baxter
 
import flash.external.ExternalInterface;
 
function gaTracking(page) {
	ExternalInterface.call("pageTracker._trackPageview", page);
}
 
//end

Code for simple call

 
gaTracking("/flash/home"); //sends event to google's analytics system

Now what you can understand from this is... You can call this function during ANY event function etc that you so desire. And any string combination that you want to pass to it is fair game. Use best practices when passing in the strings though so its easier for you and your clients to read when you all are reviewing the numbers. Ok so thats that! Cheers!

11 Responses to “Google Analytics + Flash = Easy Peasy…”


  1. 1 zuiopo

    damn! easy going. :)

  2. 2 Spirituc Design

    If you use SWFAddress, every path change will be registered automatically in GA :)

  3. 3 Tiago Dias
  4. 4 corbanb

    Tiago thats great! Thanks for sharing. Using External Interface with my AS2 projects opens up the door for a lot of options when making the tracking calls. Its great since using external interface won’t interfere with a normal getURL call or other similar calls out to the server.

  5. 5 Matt Przybylski

    Oddly enough, I too wrote an article about this a while back with an AS2/AS3 approach. I haven’t tested mine in the new version of Flash Player that was just released though so I’m not sure if anything will break because I wasn’t using ExternalInterface. EI is probably the better way to go so I may have to update my article. It was probably wise of you as well to wrap it into one method and just call the method, nice work.

    http://evolve.reintroducing.com/2008/01/09/tips-n-tricks/using-google-analytics-in-your-flash-projects/

  6. 6 Omar

    Using ExternalInterface is an excellent idea, as opposed to the code that Google suggest in their help pages.

    And as someone else said using SWFAddresss will automatically make page calls to GA.

    SWFAdrress + Google Analytics + Flash = Really Easy Peasy…

  7. 7 Gaston

    This post is great! Thnak you!

  8. 8 Jay

    Thanks for this solution.

    I have a question about where the Google tracking javascript code gets placed in the page that calls the SWF. On our site we have the GA script just before the …we are currently not tracking Flash events in production. I have seen a couple of blogs say that the script on these pages needs to actually be placed after the opening tag before the SWF call. Why is that? We put a test case together last night with the GA script before the close tag and the events were tracked as expected.

  9. 9 corbanb

    @Jay The code I created in this example only uses the ga.js method from google. You will have to edit it to fit the needs of the urchin tracker method if you want to use this. Thanks!

  10. 10 Dan

    Hello,

    Does this method matter how the Flash is actually being embedded in the page? I use SWFObject to embed the Flash with JavaScript.

    Will this still work?

  11. 11 corbanb

    @Dan it should not matter. I have used it with SWF Object and seen no issues.

Leave a Reply






Bad Behavior has blocked 261 access attempts in the last 7 days.