Tip: Google Analytics for flash websites

Google Analytics implementation in full flash websites
Once upon a time, in a galaxy far far away, google analytics wasn’t able to track full flash websites. Luckily that’s not todays reality!

This little trick enables you to use Asual’s SWFAdress in collaboration with Google Analytics to  track how users interact with your website. Monitor how much time they spend there, what version of the flash player they are running, where they live, what screen resolution their monitors have and lots and lots more.

– But most importantly, it allows you to see how those numbers progress from day to day.

Google Analytics

Google Analytics


SWFAdress is a javascript that allows your flash websites to use “deep linking”, also known as “pretty URLs”, by letting flash talk back to the javascript and tell it whenever a new page is viewed. The javascript then updates the adress bar in your browser.

This allows you to get URLs like this:

Pretty URL

Pretty URL

Instead of URLs like this:

Without pretty URLs

Ordinary flash website URL

What’s the point?
Well it gives your users the ability to link to, and share, specific parts of your website. It also records history states in the browser, so you can actually browse a full flash websites with the back and forward buttons in the browser(Without SWFAdress, that just restarts the whole thing and throws you back to the front page). You can read more about the SWF Adress features here.

Google Analytics and SWFAdress
In this case we’ll use SWFAdress to tell Google analytics which pages the user visits, so GA can record all this information.

When i first discovered how easy it was to implement GA in my flash websites i was completely amazed. It requires no ActionScript and only a few lines of javascript in your index.html. Here goes:

This is your normal SWFAdress implementation code in your index.html:

<script type="text/javascript" src="js/swfaddress.js"></script>
Replace it with this:
<script type="text/javascript">
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"));
</script><script type="text/javascript">
var pageTracker = _gat._getTracker("UA-YOUR TRACKER ID-HERE");
<script type="text/javascript" src="js/swfaddress.js?tracker=pageTracker._trackPageview"></script>
That's all it takes
Next time the Google Analytics data updates you'll be able to see all the tracking data from your flash website.
For those of you, who want to play around more with this stuff, you can even track custom events from flash. It's pretty easy. Read more about it here.


About Ahrengot

Hello — My name is Jens and I'm a freelance full-stack developer. I usually work on medium to large scale projects. React, Elm, Node & WordPress
This entry was posted in Flash, Tips and tutorials and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s