Quick Tip: How to use Google Analytics for Tracking in Flash


In this Quick Tip I'll show you how to examine the way visitors are using your websites, widgets and games. Then we'll look at how to improve them based on this info!


Building nice looking websites is great; building websites that have a high Return Of Investment is priceless.

Recently I joined the web team of a Brussels based communication agency, a team with expert knowledge in the fields of user experience design, content strategies, software development, and interaction design. We spend a lot of time on wireframes, storyboards, and prototypes, which guarantees that the functionality and the content of the websites are optimal before any graphical design takes place. This means our websites have a solid base to be built upon, which results in a higher ROI with less time spent on development.

A huge part of our work is under the hood: Google Analytics inside Flash.

This tool allows us to measure how well our sites are doing against our predefined goals: bounce rate, click paths and even custom measurements like how many people scrolled a certain page. Our specialists analyze all this information and use it to optimize the website. If you're not measuring how people are using your site, you can only guess about its successes and failures.

The following setup is a stripped-down version of an image gallery; Google Analytics allowed the client to discover which images triggered the most interest. I've left out the actual gallery building as it is beyond the scope of this tutorial; there are plenty on Activetuts+ already though - just search for "gallery".

We will focus on how to set up Google Analytics to put a smile on your clients' faces (and probably yours too...)

Google Analytics in Action

Here's the simplified image gallery:

As you can see, when an image is clicked, its identity gets sent over to my Google Analytics account. Later on, I can look at all the statistics of which images were clicked, at which times, in which countries, and so on.

(Of course, you'll remove all that overlaid information when it's live on your own site!)

Step 1: Understand the Benefits

Imagine yourself working hours, weeks, even months on a website. You successfully deliver the files before the deadline, but a few months later it's clear that - despite being beautiful - the site is not attracting as many customers as your client expected. Google Analytics helps you to review visitors' browsing habits and discover which parts of the site could be better highlighted. Beauty is great, but I believe that Return Of Investment should be your main priority.

In another scenario this same tool helps you to understand what area of your website has the most page views, how many times visitors wanted to contact you, or which elements of your portfolio visitors love the most. How many benefits can you think of for your site?

Step 2: Set Up a Google Analytics Account

If you don't have a Google account already, sign up for one here - it only takes a few seconds.

Once that's done, head to and sign up for an Analytics account. There you can give an account name for the websites you want to track.


Step 3: Inside the Machine

Head to
and use your mouse skills to click Analytics.

Great, we are now in the Overview page. You should see your Analytics account name; click it and you'll find yourself at the website profiles.


If you haven't set up a website to track, simply click 'Add Website Profile'. Enter your domain name and Country, then click Finish.


Step 4: Retrieve your UA Code and Tracking Status

The Tracking Status page will automatically appear:


The most important part is your web property ID. This is a unique number Google Analytics will use to send and store your website's traffic. (Copy this UA code for use later in Flash, or write it down.) For this introduction we'll simply keep all the options at their defaults.

If you're going to embed your SWF on your own webpage, the javascript code must be pasted right before the </body> tag in the page's HTML. This will allow you to keep statistics for the actual page itself, as well as for within the SWF. It's worth inserting this code in every page on your site.

All this is great, but you still won't be able to pinpoint your visitors' interaction in great detail, as the HTML is blind to your actual SWF / Flash content.

Step 5: Gathering Wood

To make sure you can see which parts of your SWF are being used, head to

This amazing open source AS3 API has a lot of great features for integrating GA into Flash, but even with our biggest and most complex websites, we've only ever used two functions. (More about these later on.) Make sure you download the latest installment on the right of the page. (Come back any time to read the wiki, issues etc, to learn more about this vast API.)


Step 6: Install the Components

The zip contains a documentation folder with the entire API layout to help you along the way; a library folder (lib) where you'll find the two components; and some text files you probably won't ever read. At least I didn't ;]

To install the components, make sure Flash is closed, then navigate to:

  • Windows users: C:\Program Files\Adobe\Adobe Flash CS X\language\Configuration\Components
  • Mac users: Macintosh HD/Applications/Adobe Flash CS X/Configuration/Components

At this point you need to create a directory named 'Google' and copy the files from the \lib\ folder in the zip to it.

Basically the two components give you the same functionality but are developed for two different purposes. The Analytics component is for those who are unfamiliar with AS3. I assume most of you are already using AS3, so we'll use the AnalyticsLibrary component.

Step 7: Feeding the Fire

Inside Flash, open the FLA for the project you're working on, click Window > Components, and drag the AnalyticsLibrary component to your library.


Step 8: Action! (Script)

Whether you're coding on the timeline or using a document class, you'll need to do some imports:

//import the Analytics classes

Also, in your code, create a new instance of the AnalyticsTracker:

var tracker:AnalyticsTracker = new GATracker( this, "UA-XXXXXX", "AS3", true );

The parameters are: stage, UA code, actionscript 3 mode, visual debugger on/off. Leave them all as I've set them, apart from the UA code which you'll need to swap for your own. Set the last parameter to false when you are done with your testing phases, as when true it will create an overlay on top of your SWF file like in the example above.

Test this out by adding a Click event listener and handler to one of your movie clips or buttons:

myMc.addEventListener (MouseEvent.CLICK,onClick);
function onClick (event:MouseEvent):void
	//make your clients happy.
    //use '' instead of ''
	//this will display 'myMc' instead of [object myMc], which is obviously a nicer output.
	var mySelection:String =;
	tracker.trackPageview ("gallery = " + mySelection);

Here we're using the trackPageView() function. Use this for navigation purposes. You can add a string so your client knows what part is being tracked. In this case we're tracking which gallery has been triggered. So copy and paste this code everywhere you want to track your interactions and give an understandable String to the data.

For example, if you have a "call to action" button on stage to lure potential new clients, you could write:

tracker.trackPageview("Hire me"); the Click event handler for that button. Or if you want to track how many times they have read your disclaimer:


I'm sure you get the idea.

Step 9: Event Tracking

Use event tracking if you want to track what video or MP3 event is being played, or when the user pauses it - things like that. It's basically for any action that doesn't represent opening a "page".

The code looks like this:

trackEvent(category, action, label);

For example:

tracker.trackEvent("profile videos", "play", "first video: introduction");

Additionally you can add a fourth parameter. This can represent any value you like, but it must be an integer (whole number). For example, you might want to pinpoint the exact time when the video was paused.

This is great to see how well your streaming or downloading performs for your visitors (not everyone has top class Internet connections):

var currentTime:Date = new Date().time;	//get the current time
//load the video here
var readyToRoll:Date = new Date().time - currentTime;	//get time taken to load the video
tracker.trackEvent("profile videos", "playing the video", "video 1/3: introduction", readyToRoll);

Step 10: See the Data in Google Analytics

Go to and click your account name. Next to your domain name, click View Report.


Here you will see a timeline. (Please note: depending on your server response time it can take a while before the data gets stored, but it shouldn't take too long.) Select the dates for when you have been testing using the calendar in the top-right:


Locate the Content Overview; here you can see which events or buttons were triggered:


As you can see, as I explained a few steps back, displays a "nice" name like "/gallery = gallery 1", while returns something like "[object picture1]"

Clicking on one of these links - for example, "/gallery = gallery2" - you will be able to see in-depth information, like what screen resolution your users have, when you choose an option in the drop-down menu.


There's a deep and rich information source in nearly every single branch of the Google Analytics module. It's nearly impossible to list all of them. Don't be afraid; look around and see what data you can provide to your clients and yourself.

Step 11: Eliminate Yourself from the Stats using Filters

It's a good idea to filter out your own behaviour; otherwise, it will give you incorrect data since you will probably test this in great detail.

You can do this by filtering all activity coming from your IP address - though please note, this will only work if you have a static IP address. There is a lot of documentation in the help files; I can't cover it all here. Check out

Filters can also be useful for other reasons. Here is some more information:

Step 12: The End is the Beginning...

In this Quick Tip I've only covered a snowflake on the tip of the iceberg of what you can do with this amazing API. It's a quick overview on the two most beneficial functions that we deal with to improve our websites and match our clients' wishes.

You can also set predefined goals, group users that (for example) use widescreen monitors, base your Analytics on search engine keywords and so on. For your clients, you can send an email with daily, weekly or monthly reports (as xml, PDF, or other formats), or even give them access to your Analytics page. If you'd like more information, please ask in the comments!

My Opinions on Search Engine Friendly Flash Websites

Although it is beneficial to read and trace your visitors' interactions, this is a long way from using Flash in an SEO-friendly world. I've warmed you up for optimal website design and focusing on Return of Investment, but we're not there yet.

A good next step would be to look into the Gaia framework, and use its mighty setup to work with swfaddress and deeplinking. This will allow you to track individual pages of your website project and in combination with your newly learned Google Analytics magic, I am sure not only your clients will smile.

Editor's Note: We have some Gaia tutorials lined up, don't worry ;)

I've been working for over 10 years in the graphic design world, and never had so much power to know exactly what my clients and visitors want. I often like to call it "free marketing and research from your desktop". (If you are wondering why my own site isn't using this technology, well honestly... I hope to re-launch by mid 2010 *sips coffee*)

I hope this opens new doors for you and boosts your skill set. Good luck and have fun!

Related Posts
  • Web Design
    The State of SEO in 2014Seo retina
    Back in December 2012, we published the first article of our SEO for Web Designers series. The fundamentals we covered still form a great basis for the optimization of a website, but because of some changes to Google’s algorithm, I've decided to give you some additional advice about the application of these techniques.Read More…
  • Web Design
    Design Theory
    Understanding the Composite Parts of Your DesignFourier retina
    In this article we're going to look at a simple analogy which will illustrate effective ways of communicating through design. Once we've established the idea, we'll take a look at some familiar examples to drive the point home.Read More…
  • Computer Skills
    Run the Ghost Blogging Software on a Raspberry PiGhostpi400
    In this tutorial I will show you how to host a blog on your Raspberry Pi using the Ghost blogging platform. Ghost is a brand new piece of blog software, currently under development which was recently funded by a Kickstarter campaign. Similar to the way Wordpress is distributed, you can opt to purchase a hosted blog or download the software to try out yourself. As Ghost is very new it is still quite simplistic, and this simplicity makes it ideal to run on a Raspberry Pi. You'll be able to write and edit posts and upload images to your blog. I'll also show you how to install google analytics so you can see how many people are reading your website.Read More…
  • Business
    App Training
    Squarespace Activity and Google Analytics ComparedPreviews squarespace activity and google analytics compared
    Over the course of this series, we've set up a complete online presence using products such as Squarespace and Google Apps to provide rock-solid web and email services with almost no configuration and zero maintenance required. In this part of our series, we'll show you how to gather analytical information about your Squarespace site's visitors, as well as comparing it to Google Analytics.Read More…
  • Business
    Minimally Viable Google Analytics Conversion TrackingPreview minimally viable google analytics setup graphic
    Have you heard of Google Analytics? The amazing free tool that lets you know exactly what’s going on with your website traffic? From where your visitors are coming from to what they’re doing on your site to where they’re leaving? If you have, then you know that Google Analytics can give you a lot of amazing insights into your business. Google Analytics can tell you where your customers or leads are coming from, but it doesn’t come setup out-of-the-box to do that for you. It requires a little tweaking. And let’s be honest, if you’re not using Google Analytics to tell you where the leads for your business are actually coming from, what are you using it for?Read More…
  • Business
    App Training
    How to Install Google Analytics on WordpressPreview install google analytics on wordpress
    Have you heard about all the powerful insights Google Analytics can churn out for your business? (Here are just 3 Google Analytics insights you can learn about your business.) If you haven’t heard about Google Analytics, it’s an amazing, free tool you can use to track everything related to your website visitor data - from how many, to where they’re coming from, to what they’re doing on your website (and what’s making them leave!). If you have heard of Google Analytics and its powerful insights, you know that installing it on your site is a must do item. If you're a Wordpress user, I have a secret for you: installing Google Analytics on your Wordpress site involves very little code. We can install Google Analytics easily. Sound good? Let’s get to it.Read More…