Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411478 Posts in 69369 Topics- by 58424 Members - Latest Member: FlyingFreeStudios

April 23, 2024, 07:23:43 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsGoogle Analytics for Flash Games
Pages: [1]
Print
Author Topic: Google Analytics for Flash Games  (Read 7496 times)
isaac
Level 2
**



View Profile WWW
« on: December 13, 2008, 05:33:44 PM »

This is a fairly simple tutorial. It pertains to Flash Actionscript 3 only, and assumes that you're a competent AS3 programmer. You'll also probably need access to a web server to test things before release.

Google and Adobe recently released a set of tools for tracking Flash content in Google Analytics. You've been able to track Flash events for a while by getting Flash to talk to external javascript on the webpage it's hosted on, but that's kinda complicated to get right, and it doesn't help for Flash games where you have no idea where they're going to end up. The new tools allow Analytics tracking without having to deal with Javascript.

Mochibot has of course had tools for tracking number of plays, and where a game is hosted for years. Using Google Analytics though lets you get much more detailed information about player's behavior.

As an example in this tutorial I'll be using my new flash game Gravitat. It's my first test at using Analytics, so I figured I'd share the mistakes I made. The game is nothing amazing, but it's fairly simple structure allows for easy tracking.

Analytics tracking for games is pretty useful for getting detailed data on how people use your game. It's like having access to 50,000 beta testers.

First off, you'll want to download the gaforflash package. The instructions for installing the packages to Flash/Flex can be found here and here.

Now that you've got the tracking software, you'll need to set up a 'site' for the game within Google Analytics. Go to google.com/analytics/ and log in. You'll see a list of currently tracked websites if you've used it before... otherwise the list will be empty. Click on Add Website Profile and point the profile towards a URL you'll be using for testing purposes. Once you've added a profile it'll give you some code to use on your webpage. Put this in your testing page... It's not 100% necessary, but Analytics will give you a tracking status warning until it's satisfied that you've got tracking installed properly on a webpage.

Actually setting up the tracking packages to work in Flash is super easy. Once you've installed them, from the components menu in Flash, drag out the AnalyticsLibrary object into your library. Make sure it's exporting to ActionScript properly.

Now, in your code first import the correct classes:

Code:
import com.google.analytics.AnalyticsTracker; 
import com.google.analytics.GATracker;

Then start up the tracker:

Code:
private var tracker:AnalyticsTracker;

private function initTracking():void{
tracker = new GATracker( this, "UA-111-222", "AS3", true );
}

In the tracker setup, this is the current display object, "UA-111-222" should be replaced with the tracking code that Analytics gives you for the 'site' in it's list of your sites. "AS3" tells the package to not use external Javascript for it's tracking, and true puts it in debug mode. Set that to false for release.

Now that everything is set up properly, you can track page views. In a flash game, these are virtual pages that you can use to see what people are doing:

Code:
private function initTracking():void{
tracker = new GATracker( this, "UA-111-222", "AS3", true );
tracker.trackPageview( "/tracker-initated" );
}

private function startLevel( levelId:int ):void{
// this will tell me how many people reach each level
tracker.trackPageview( "/startLevel?level=" + levelId );
}

In the documentation, Google also happily chat about event tracking as well as pageview tracking. Apparently, tracking events allows you to attach variables to your tracking data as well. Don't believe it though. What the documentation fails to mention is that event tracking is still in beta, and most Analytics accounts cannot enable it. So for now just stick to measuring 'pageviews'.

Analytics tracking doesn't actually register pageviews that are sent out from the debug player inside Flash. To test that everything is working, you'll need to upload the .swf you're working on to a web server. You can then play around with it for a bit to generate some data.

Now comes the painful part: Analytics is only updated once every 24 hours. You'll need to wait that long before you know whether your tracking is actually working or not.

Quote from: PROTIP
   Something I learned from the user analytics guy at my work is that you can use a bit of URL hacking to see more recent data. This isn't reliable as it hasn't been number-cruched yet, but you might be able to see if things are working.
   
   In your Analytics page, go to View Report on the site you're testing. This will bring up a most likely empty graph, etc. To try to see more recent data, in the URL change the day of the date variable ( looks something like 20081113-20081213) to a later date (20081113-20081214). This will let you see data that's about 6 hours or so old, rather than 24 hours old.   

So hopefully you come back a day later and everything is working! It all seemed to work first time for me, so hopefully for you too!

Now that Analytics is working, you can start to use it to track interesting data. Here's the things I'm tracking in Gravitat:

  • When the game starts loading
  • When the game finishes loading
  • If the credit links are clicked
  • When the level mode game is started
  • When the survival mode game is started
  • If the sound is muted/turned back on
  • When a player reaches a new level, and what level they reach
  • When a player loses the game, what their final score is and how long they played for
  • If a player submits their high score

To track specific variables, I have used a basic URL variable structure, so when a player loses the game a pageview like this is send:

Code:
/gravitat/loseLevelMode?score=6473&time=336

However, this url is a little difficult to make sense of using just the #of pageviews, since every player will have a slightly different score and time. Luckily, Analytics allows exporting XML data, so I'll eventually write something to decode this into useful graphs.

Gravitat is only been released for a day, but I'm already pulling all kinds of useful data.

The most useful piece of data is that of the times players have stated a game, only 8% of those are a survival mode game, and 30% of the people who start a survival mode game quit before finishing. This suggests that both the name or menu item of 'survival mode' seem unappealing, and that the gameplay gets boring fast. So next time I make a game with multiple game modes, I should either cut one and keep the best, or make the second mode more appealing.

It's easy to see that implementing user tracking into a Flash game is both painless and rather useful in understanding how a lot of people use your game. Let me know if you have any questions!
« Last Edit: March 19, 2009, 09:12:12 PM by Derek » Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic