views:

25

answers:

1

Hi There

I am attempting to add google analytics tracking to an Adobe Air app created with HTML and javascript.

I have tried adding the ga.js file and using it like I would in a webpage:

<script type="text/javascript" src="lib/js/ga.js"></script>
<script type="text/javascript">
   var pageTracker = _gat._getTracker("UA-********-1");
   pageTracker._initData();
   pageTracker._trackPageview('/test');
</script>

But this doesn't seem to register anything on the analytics dashboard.

Have also tried using the GA for flash actionscript library but I can't seem to create an instance of the GATracker as it needs a DisplayObject?

EDIT

using the information from grapefrukt I tried the following:

air.Sprite = window.runtime.flash.display.Sprite;
air.GATracker = window.runtime.com.google.analytics.GATracker;

var tracker = new air.GATracker( new air.Sprite(), "UA-XXXXXXX-X", "AS3", false );

but I get the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference

+1  A: 

NOTE: I originally misread your question to be about how to use gaforflash, but I'll post this anyway since I've already typed it up and it might be of some use.

You can the constructor whatever DisplayObject you like, normally you'd use your document class, but anything will work. As far as I can understand it's only really used for displaying debug info.

var tracker:AnalyticsTracker = new GATracker( new Sprite, "UA-XXXXXXX-X", TrackerMode.AS3, false );

Setting the TrackerMode to AS3 let's the flash communicate directly with the tracking servers, so you don't need the javascript from google's servers.

I can't help you with the communication between js/as3, but that should be fairly easy.

grapefrukt
Thank you for your answer. I had a go, changing the syntax to work with adobe air/javascript and I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
JordanW