Flash Google Analytics Lite

I’ve been using Google analytics to track events and page views. It works really well and using the events for levels and play length can be extremely helpful. The big problem though is the file size. An empty swf compiled in flashdevelop with just my google analytics class comes to nearly 70k.

I took a look around for anyone who’d made a light weight version and couldn’t find any so in the end I had a go myself.

The obvious place to start seemed to be the debug code. It’s very woven into the main code, I think it would be extremely useful if they provide a version without the debug system for final versions.

Anyway, here is a quick guide on how to quickly strip a few kbs.

Quick Start

Download the latest version over svn from here http://code.google.com/p/gaforflash/source/checkout

If you want a quick start I have a quick Tracking class, I haven’t got the original to hand but I recreated it off my the top of my head. download here . You use it like so.

//Setup the on stage display object required for GA and the account
Tracking.GAaccountID = "GAXXXXX-XXXX";
Tracking.root_display_object = this;

Tracking.trackEvent("Game","start level","game title",1);

Start Stripping

com.google.analytics.debug.DebugConfiguration.as seems be the main file we can start with.

You want to strip out ever mention of  layout:ILayout. First comment out the

public var layout:ILayout;

then head down and comment out any if containing layout. You can clear the whole contents of any if with it like so:

private function _initializeVisual():void
/*if( layout )
_visualInitialized = true;


Once you’ve cleared out any ifs mentioning layout there’s only one more mention of it inside  com.google.analytics.GATracker.as. Remove the import of layout and in the _factory() function comment out the contents of the if( visualDebug ){
Compiling that lops the file down by 13KB
You can carry on hacking away. Staying in GATracker.as I found that as I was only using the AS3 mode so I removed the case and the factory function mentioned in the following switch

/*case TrackerMode.BRIDGE :
activeTracker = _bridgeFactory();

after deleting the _bridgeFactory function I removed the import of Bridge as well this takes off a few more KB.
There’s plenty more that you can play with but the above is a 2 minute job that can get about 20KB off you’re project.
OK Bye

This entry was posted in flash. Bookmark the permalink.

Comments are closed.