What is Google Analytics for Flash?
It gives you amazing in-depth information on your game’s players, like this (click to enlarge):
This is the actual data from one of my older games on 17/03/2014. I won’t tell you which game though
Read on, and I will show you exactly how to set up the same metrics for your game.
Why Bother Tracking Metrics?
Tracking metrics in your games is important because it allows you to answer questions like:
“How many people played my game?”
- More plays means more ads are being viewed by players. If you can say my games get X players, you can use that when negotiating license sales or sequels.
“What sites is my game played on?”
- You can use this information to expand to sites that have not yet hosted your game, or target sites on which your previous games did well when selling your next game.
“What causes players to stop playing?”
- Maybe you will find out something that went unnoticed during testing and you can fix to keep players playing.
There are a lot more questions analytics can help you answer, but those are the main ones I look for.
With so many competing analytics services, it can be hard to pick one.
Which Analytics Service is Best?
In my personal opinion, Google Analytics. I much prefer it over everything else I tried. Why? It’s reliable, easy to set up, tracks common metrics such as views & hosts, supports custom metrics, and the data can be shared with others. That’s basically everything I need from an analytics service. The only downside I have encountered is that it takes 24 hours for the data to update, although there is a real-time view which shows you what is going on right now.
Others
Before settling on Google’s service, I tried a lot of others but found them all lacking in some important way or other:
- I tried Playtomic, but you have to host the server yourself which takes a lot of resources.
- I tried Mochibot, but it’s shutting down.
- I tried Scoreoid, but it requires extra work to set up since they don’t provide an actionscript API.
- I tried GamerSafe, but it only tracks some basic metrics and has no support for custom ones.
- I tried my own custom PHP+MySQL solution, but it takes a long time to re-invent the wheel and I was worried my host would shut me down if my games become too popular.
- Did I miss any good ones? Please leave me a comment so I can go check it out!
Is there any reason not to use Google’s service? Yes, there are a couple things Google Analytics doesn’t do because they’re not analytics: leaderboards, saving player savegames, level sharing, or anything that requires data to be sent from the server->client. If you need any of those features then I would still use Google for everything it can do, and chose one of the alternatives for the bits and pieces it can’t.
Have I convinced you? Then you’re probably wondering…
How do I add Google Analytics to my Game?
This step-by-step tutorial is for FlashDevelop. If you use Adobe Flash, or FlashBuilder you can still use GAForFlash and the steps are similar but I’m not going to cover it because it’s not what I use.
Set Up your Google Analytics Account
Start off by going to Google Analytics and registering for an account as a website. Just enter whatever as a url, for example mygame.com.
Add Google Analytics to your Project
1. Download GAForFlash from here: https://code.google.com/p/gaforflash/downloads/list
2. Copy the lib\analytics.swc file from the zip archive you just downloaded into your project’s lib folder, then right-click it and select ‘Add to Library’.
Start Tracking!
1. Connect to Google Analytics from your code as early as possible. You need to do this before doing any other tracking. (Tip: For my games, I connect during the preloader. I can then calculate how many visitors left during the preloader by comparing it to the number of people that reached the main menu.)
var tracker:AnalyticsTracker = new GATracker(DisplayObject, TrackingID, "AS3");
DisplayObject is your highest level Flash Display Object. Typically you can just use ‘this’ from the place you are creating it.
Tracking ID looks something like “UA-XXXXXXXX-X” and can be found for your site in Google Analytics under Admin -> Tracking Info.
2. Use pageviews to track the player’s journey throughout your game.
tracker.trackPageview("/page");
For page, make up something descriptive. Eg “/main_menu” or “/level_2_failed”.
I track:
- When the player reaches the main menu. By subtracting this from the number of players that connected, I know how many decided to leave during the preloader.
- Every time the player navigates to an important screen (eg upgrades, or credits). This shows you if players are finding their way to those important screens. If a screen is getting less attention that you would like it to, you may have to do something to make it more obvious.
- Every time the player starts a level. This will show you where players stop playing. It’s natural for you to lose players between levels, but if you notice a sudden sharp dropoff, consider reworking the next level, maybe there’s something you could improve.
- Every time the player wins or loses a level. This is useful for balancing difficulty. Levels that are too hard are a common cause of players leaving. Compare it to the ‘player started a level’ metric. Does the rate of players quitting your game match the rate of players losing levels? If yes, consider making those hard levels a little easier.
- Do you have any suggestions for interesting things to track? Leave a comment
3. Use events to track actions players take within your game.
tracker.trackEvent(category, action, label);
Category can be used to categorize events, eg “Link Clicked”.
Action is a more specific version. I chose to still include the category name in the action manually because I prefer the way it shows up in Google Analytics this way.
Labels are optional, but very useful if you want to distinguish between several version of the same event. Eg if they were done from different screens.
To give you a concrete example, this is how I track player’s clicking the sponsor’s logo on the main menu:
tracker.trackEvent("Click Link", "Click Link: Sponsor", "Main Menu");
I track:
- All clicks on external links such as sponsor & developer logos. I also always specify on which screen it was clicked so I know which are most effective.
- How many players muted the music & sfx. I assume if a lot of players mute it, they don’t like it or find it annoying.
- Tutorials and cinematics skipped.
- Anything else game specific that you can think of that you could use to improve your game, eg powerups used or upgrades bought.
- Do you have any ideas for important events to track? Leave a comment
Test It
It takes 24 hours for new data to appear, so don’t fret if you just started sending data and it isn’t showing up on the analytics site yet!
Thankfully Google included a method to test that everything is working smoothly without having to wait for the data to update. Just set the visualDebug parameter in your GATracker creation to true.
var tracker:AnalyticsTracker = new GATracker(DisplayObject, TrackingID, "AS3", true);
As long as visualDebug is turned on, you will see Google Analytics overlay a debug log over your game that looks like this:

Google Analytics Visual Debug Log
Test your game and make sure that all your page views and events show up.
Configure Your Dashboard
Switch back to the Google Analytics site. You can look at the default Dashboard, or poke around the various options on the right, but I like to set up a custom dashboard that has all the information important to me in one place.
If you want your Dashboard to look exactly like mine, you can simply click my template link and it will be created for you. However you will probably want to customize it to fit your tracking. For example my levels played bar graph will only work if you are tracking page views as ‘/level_x_win’.
My Dashboard Template: google.com/analytics/web/template?uid=saxKoPTBTMmsORUgOUcwlA
If you don’t want to import the whole thing, select Dashboard -> New Dashboard -> Blank Canvas. You can then add any widgets you feel like. If you want to know how I configured my individual widgets, check out the image below.
Now, Wait 24 Hours
This step is important! It takes 24 hours for data to start appearing. So don’t complain if you just added Google Analytics and nothing is showing up yet in your dashboard!
Advanced Tips
There is a limit of 500 metrics recorded per connection. That’s quite a lot so it’s unlikely that you will hit it, and even if you the game will just keep running as normal (but metrics will stop being reported). Just in case, I count the number of things sent in my code and when it reaches 499 I send a special event to let me know the limit has been reached.
If your game is super popular, anything over 10,000,000 hits per month may not be processed. However I have exceeded this limit before and my hits continued to be counted accurately (which I determined by comparing the data to a 2nd tracking system I had in place). So I guess there’s no guarantee it will work, and none that it won’t either.
To make things a little more convenient, I have put together a little helper class over time. The main thing it does is automate the 500 requests per connection checking. Just enter your tracking id, then use GATracking.init(displayObject) to connect, and GATracking.trackAndCountEvent and GATracking.trackAndCountPage to track things.
package { import com.google.analytics.AnalyticsTracker; import com.google.analytics.GATracker; import flash.display.DisplayObject; public class GATracking { public static const TRACKING_ID:String = "UA-XXXXXXXX-X"; public static const MAX_REQUESTS:uint = 500; public static const DEBUG:Boolean = false; public static var tracker:AnalyticsTracker; public static var requests:uint = 0; public static function init(DO:DisplayObject):void { tracker = new GATracker(DO, TRACKING_ID, "AS3", DEBUG); requests = 0; } public static function trackAndCountEvent(category:String, action:String, label:String = null):void { requests++; if (requests == MAX_REQUESTS - 1) { tracker.trackEvent("Requests", "Maximum Reached"); } else if (requests < MAX_REQUESTS - 1) { tracker.trackEvent(category, action, label); } } public static function trackAndCountPage(pageURL:String=""):void { requests++; if (requests == MAX_REQUESTS - 1) { tracker.trackEvent("Requests", "Maximum Reached"); } else if (requests < MAX_REQUESTS - 1) { tracker.trackPageview(pageURL); } } } }
[…] game hosts and shows it in a nicer dashboard. For anyone looking for a mochibot replacement, I wrote up a little tutorial. Hope it helps someone __________________ Treasure Sweeper Available for […]
Nice post. Wondering if you would share the template link for your custom dashboards? It would be intersting to see how you filter the data, etc.
Sure thing, didn’t even know about that feature. I have updated the post with a link.
https://www.google.com/analytics/web/template?uid=saxKoPTBTMmsORUgOUcwlA
Cool, thanks
Great article Wolfgang, and your dashboard looks absolutely fantastic — thanks so much for sharing, this should be especially useful with MochiMedia ending their services soon!
I’d love to bring this to a wider audience, and I was just wondering if you would be interested in allowing us to re-publish it on GameDev.net? The article would of course be attributed to you, and would prominently link back to the original source to drive readers back to your own site.
Obviously no pressure if you’re not interested, but I had to at least ask since you’ve written such a great article!
Hi Jason, yes please! I would be honored to. Let me know if there’s anything I can do to help.
Thanks so much Wolfgang!
It’ll take a few days with GDC on at the moment, but we’ll handle the whole thing for you and let you know when the article is live on the site.
Thanks again for sharing your knowledge!
Just letting you know the re-publish has gone live on our site, and will be shared via social media early tomorrow.
http://www.gamedev.net/page/resources/_/business/business-and-law/tracking-player-metrics-and-views-in-flash-games-with-google-analytics-r3625
Looks great!
Perhaps I can interest you in my latest post on monetization in Clash of Clans?
http://www.allworkallplay.org/blog/clash-of-clans-time-monetization-formulas-demistifyed/
Or an upcoming series of Unreal Engine 4 game making tutorials that will start going live early next week?
You have blanket permission to republish anything.
Thank-you very much Wolfgang, it’s great that you’re so willing to share with the development community.
Btw, I tried your Orbital Debris game — very fun little mini game, great job!
That’s a smart answer to a dilifcuft question.
Os torcedores esperam para 2011 um uniforme mais bonito…a spieler por mais q seja mais viavel ao clube o material da camisa é horrivel. espero q a diretoria consgia fazer com outra marca esportiva. o azul e o vermelho tem q retratar melhor as cores do marinheiro q são rubro anil…poderiam fazer um modelo numero 3 no estilo quadriculada(croacia) aquele uniforme ficou marcado, e é uma jogada de marketing para vender bem
Hey Wolf can you drop me an email? I’m the articles editor and would like a direct means of getting in touch with you in the event of any issues with your blog entries we republish. Thanks!
Mega thanks!
Now that MochiBot is out this is exactly what I was looking for! Thanks a lot!!
Nice post. I was checking continuously this blog and
I care for such information a lot. I was seeking this particular info for
I’m impressed! Extremely useful info specially the last part
a long time. Thank you and good luck.
Every weekend i used to pay a visit this web site, for
the reason that i wish for enjoyment, for the reason that this this web site conations in fact pleasant
funny data too.
Battling with archrival Mercedes-Benz year in and also year
out for the greatest laurels, BMW continuouslies frequently modify its alreadying existing line as well as add brand-new
cars to its line in a proposal to promote and also
reinforce client passion. One location where BMW has discovered a lot of its current success
is with its race automobile inspired line of automobiles, the M Series.
Famous Mercedes-Benz is taking on proclaimed BMW for the right to call themselves the top selling
deluxe brand in the world.
Hi! great post, thx for this used the info in my new game.
I have a question about hosts, is this automatically sent upon api connection or you have to send it manually? (and if so what’s the best option?)
Thanks- that cleared up my problem how to implement analytics in flash games. Does it work if I upload my game to a free flash games portal such as newgrounds, kongregate and gamejolt?
Met slechts 3 simpele stappen kun jij al iemand zijn Whatsapp hacken.
Hello,
is is still working?
[…] article by Wolfgang Graebner (2014) says this about using Google […]
This game is lame, I liked http://bit.ly/1VxBGzl much more
I don’t know іf it’s just me or if pеrhaps everүone else experiencing problems with your website.
It seems like some of the written text withіn your postѕ are running off the screen.
Caаn someone elsxe please comment and let me know if this is happening
to them too? This may be a problem with my browser because I’ve
had this happen before. Thank you
It’s hard to find experienced people for this topic, but
you sound like you know what you’re talking about!
Thanks