Haxe & Google Flash Analytics
I investigated how to use the recently relased google analytics flash tracking with Haxe. The solution is simple, and I prepared an out-of-the box demo pack.Start downloading google_analytics_flash_haxe_demo.zip and read on for details (or see the included readme)
Instructions for compiling:
- unzip the package
- edit Main.hx and replace your google analytics code
- swfmill simple res.xml library.swf
- haxe build.hxml
- flashplayer_dbg test.swf (don't forget allowscriptaccess=always when embedding the swf on a website)
Details:
- I downloaded the compiled AnalyticsLibrary AS3 lib
- after unzipping analytics.swc (swc is zip with different extension), I renamed the extracted library.swf to ga.swf
- generated hxclasses with haxe, fixed XML import in two generated header files
- in the swfmill resource xml, I included the ga.swf on the first frame (note: this may do the trick for other libraries as well, not just ga-flash)
- the demo code is based on the demo code found @ http://code.google.com/apis/analytics/docs/flashTrackingIntro.html
Comments
Comment by [ron], (URL) on 09.04.16. 16:37
Unfortunately it seems that this technique cannot be used to track live events in a game for example, because each single analytics request is instantly sent, and results in a well noticable lag in the game.
Comment by Tarwin, () (URL) on 09.08.04. 09:36
Sweet! Thanks for that.
I did things a little differently.
- Copied the intrinsics you made for haXe to my src folder
- Added the SWC to the “Library path” (CS4 only, Publish Settings->Flash->ActionScript 3.0->Settings).
- Added “import com.google.analytics.GATracker;” and “com.google.analytics.GATracker;” to the timeline to make sure that the classes were compiled.
- Used the SWF as a library ie “-swf-lib FLASH/lib.swf” (added in FlashDevelop Project->Properties->Compiler Options->Additional Compiler Options)
Comment by [ron], (URL) on 09.08.04. 18:26
Nice! Having the Flash IDE helps in this case :)
Comment by Cristi Baluta, () (URL) on 09.12.13. 06:05
for me the additional 98k added to the file is a disaster, i’m trying to port only the basic functionality directly to haxe but it’s hard to understand what they have done there.
