Tracking with Google Analytics from Flash
Just a quick update on the Google Analytics work I have been doing in-amongst writing a desktop application to detect proxy settings (maybe more on that later).
I have completed the move from development to live server and have implemented some code for Flash banners to call the Google Analytics JavaScript _trackPage function. Its really simple stuff but as I have done 2 examples (one in Actionscript 2 and one in Actionscript 3) for the client to be able to supply the creative departments of advertisers (as they usually create the banners and supply .gif or in this case .swf files) I thought I might as well post the examples. For those people trying to find there way with Actionscript 3, a button click action is now triggered by an Event (MouseEvent.CLICK) and interestingly a call to some JavaScript in the page that embeds the Flash file is now called using the ExternalInterface class (it won’t work with the old method of calling the function from the getURL method). For example:
ExternalInterface.call("pageTracker._trackPageview('/clks/adv/insert-name-here')");
Replaces:
getURL("javascript:pageTracker._trackPageview('/clks/adv/insert-name-here');");
Anyways, here are the examples for download.
It’s basic but it might help someone

Hi there. although easy, for some reason i am struggling..
i would like to track the pages on my portfolio site http://www.chasmackinnon.com.
very simple, it only has 4 tabs i would like to track, however each tab is calling on a external .swf and importing it into the home page (so the url never changes)
does that mean i need to use
ExternalInterface.call(“pageTracker._trackPageview(‘/clks/adv/insert-name-here’)”);
or
getURL(“javascript:pageTracker._trackPageview(‘/clks/adv/insert-code-here-as2-click’);”);
also what code do i insert here (insert-name-here)?
thanks
Hi there,
ExternalInterface.call enables you to call a javascript function in the page/html that is embedding the flash site. It looks like your site is self-contained flash with one url so you need to use ExternalInterface.call to call the google script each time one of you tabs is loaded (Google Analytics will then record a page impression each time one of your Flash pages is loaded because you will be calling the pageTracker._trackPageview method).
If you are using this method make sure that your Google Analytics code (the one you get from Google) is pasted into the page which embeds the Flash site.
With regards to your question about (insert-name-here), I was just giving an example but whatever ystring goes into this parameter (the bit between the ”) is what is stored as the page name in Google Analytics – the name of the tabs/pages in your flash site if you want to use them. For example:
pageTracker._trackPageview(‘/Tab One’)
pageTracker._trackPageview(‘/Tab Two’)
pageTracker._trackPageview(‘/Tab Three’)
pageTracker._trackPageview(‘/Tab Four’)
Its whatever name you want Google Analytics to record your individual pages as.
Hope this helps
K-dog,
I know this post is quite old, but I’m still rocking ActionScript 2 and wondered if you might be able to make the example files available for download again. The link above seems to be broken.
Thanks so much for the help.
Dustin
Hi There, sorry about that, seems our re-jigging of the site moved a few things. I have updated the link on the post. Good luck.
Hi Kirsten. Thank you for posting this code. I am having a bit of trouble which I suspect is a simple fix. I am using AS2 and the following onPress of my button:
getURL(“javascript:pageTracker._trackPageview(‘/DownloadTrack’);”);
In my HTML I am using both your button tracking JS and Google’s page tracking script:
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
var pageTracker = _gat._getTracker(“UA-12520643-1″);
pageTracker._initData();
pageTracker._trackPageview();
try {
var pageTracker = _gat._getTracker(“UA-12520643-1″);
pageTracker._trackPageview();
} catch(err) {}
Am I using duplicates here? I implemented this code around 5 hours ago and still the only page that shows up in Analytics is my home page… no button clicks. Thank you, I appreciate your help!
Hi Jon,
Sorry for the delay in getting back to you but we’ve had so much spam comments on the blog that it’s a bit like seeing the wood for the trees! Anyway, I would have thought you have sussed this out by now but I’ll respond in case anyone else needs the info: you said that you had waited 5 hours since implementing the code but unfortunately, one of the downsides of Google Analytics is that it takes up to 24 hours for you to see your changes in action which of course makes it a little frustrating to debug when you start delving into regular expressions and more complex actions with Google Analytics!
I hope everything works for you now, let us know if not.
Kirsten