Categories

Archives

January 30, 2009

How to Track Viral Flash Games and Content with Google Analytics

Filed under: Games — Simon Walklate

As a follow up to my previous post I’m going to go through how to use the new Google Analytics Flash component library, to track virally distributed Flash content across multiple domains. I’m still in the process of testing it fully, but on the face of it, it looks to be a viable option for tracking viral games. You get to use most of the advanced features of Google Analytics for analysing your viral campaigns, you can share profiles with clients or within your business, and it’s free!

The first thing you’ll need to do is to create a new profile for your Flash game in your Google Analytics account. You can do this by selecting ‘Add new profile’ from the Analytics Settings menu. It’s important to make sure that you set it up as a new domain (even though strictly speaking the Flash game won’t have a single domain of it’s own) to make sure the game gets it’s own unique tracking ID. So select ‘Add a profile for a new domain’ and enter a valid domain name. I used a subdomain of our website, something like ‘gamename.domainname.com’ to make it easy to identify, and it doesn’t have to exist. It’s probably a good idea to write down your new unique tracking ID at this point.

If you’d like to view the hosting domain that the game was played on for each visit, you’ll need to set up a custom filter for this profile. Otherwise all hits will be tracked as the page the game appeared on, without the domain. You can do this by going into your profile settings and selecting ‘Add filter’. Enter the filter information as shown below to show the hosting domains in your profile content view:

gafilter

Please note – Because every visit will be classed as a bounce (one page only) you will not be able to track individual domain average view times from the content view. You will however be able to see the overall average view time from the main dashboard.

To use the Flash components you need to be working with Action Script 3. So if you’re still using AS2, it’s time to think about making the change.

You’ll need to download the Google Analytics for Flash files. Now install the component library in your installation components folder. In the case of CS4 for Windows you’ll need to navigate to: ‘C:\Program Files\Adobe\Adobe Flash CS4\Common\Configuration\Components’ (otherwise go to the correct component folder in your installation). Create a new folder named ‘Google’ here. Unzip the files you’ve just downloaded and navigate to ‘lib’ in the unziped folder. You’ll see two versions of the analytics Flash component file, we’re going to use the code only version ‘analytics.swc’. Copy that into the ‘Google’ folder you just created and that’s the component installed in Flash.

Now you need to open Flash and load the Flash document that you want to track. Open the components window and drag the newly installed AnalyticsLibrary into your document library. Now we can start coding…

In the first keyframe insert the following code (replacing “UA-???????-?” with your own unique tracking ID):

import com.google.analytics.AnalyticsTracker;
import com.google.analytics.GATracker;
var tracker:AnalyticsTracker = new GATracker( this, “UA-???????-?”, “AS3″, false );
tracker.trackPageview();

This initialises the tracker and tracks a hit on your Flash game when it’s viewed. If you want to track events such as button presses I’d recommend using the event tracker because this is independent of page views. The only problem being that Google Analytics event tracking is still in beta testing and although all accounts will track the events, not all accounts have the event view enabled. If you’re a Flash developer you can put in a request to get event tracking enabled and in the meantime, use this little hack to see the events viewer. Select content view in your Google Analytics profile and then change the URL manually from:

https://www.google.com/analytics/reporting/content

to

https://www.google.com/analytics/reporting/events

Now it’s time to insert the event tracking code into your Flash document. In the following example we have a button that we want to track clicks of on the stage, with an instance name set to ‘myButton’. We’re going to put all events into one event category called ‘Interaction’ (you can split them up if you wish) and call this event action ‘Send to a Friend’. Now every time the button is clicked it will log that event in your Google Analytics profile.

myButton.addEventListener( MouseEvent.CLICK, onButtonClick );
function onButtonClick ( event:Event ):void
{
tracker.trackEvent(“Interaction”, “Send to a Friend”);
}

And there you have it. Your viral Flash game will now be tracked over multiple domains, with most of the advanced functionality of Google Analytics and without the need for an expensive and inferior paid viral tracking service.

  • Share/Bookmark

2 Comments »

  1. Hi Simon,

    Really good article. You say you were “still in the process of testing it fully”, have you tested it and does it work?

    Thanks

    Sam

    Comment by Sam Eaton — November 16, 2009 @ 3:15 pm

  2. It was a while back when I tested it and it worked great, need to take care when setting it up though. Haven’t had chance to use it in one of our games yet. Been doing almost all commercial projects for the last few months so I’ve been using a paid viral tracker. Going to be using Mochibot (for realtime stats) and Google Analytics (for more detailed reports) in our next game though, and it’s all FREE.

    Comment by Simon Walklate — November 16, 2009 @ 8:10 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment