ytg
ytg

Reputation: 1857

Google Analytics in a Flex mobile app

I'm trying do some analytics with my mobile application. The application is written in Flex. I'm trying to use Google's library for Google Analytics somewhat according the official example. I created a class with a static method that I call from all the screens in their creationComplete event handlers.

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

import flash.display.DisplayObject;

public class AnalyticsHelper
{
    public static function trackScreenView(screen: DisplayObject, name: String): void {
        var tracker:AnalyticsTracker = new GATracker(screen, "UA-XXXXXXXX-1", "AS3", false);        
        tracker.trackPageview("/screen/" + name);
    }
}

After some debugging, my results are: The function gets called.trackPageview() gets called. According to Wireshark some data goes to Google but since it goes through an encrypted connection I can't see what is it. Yet no data appears on my Google Analytics dashboard. (Yes, I know that I have to wait a day for the data to appear. I waited. After two days it's still not there.)

Am I missing something? How can I make Google Analytics to work with my Flex application?

Upvotes: 1

Views: 520

Answers (2)

ytg
ytg

Reputation: 1857

After a few days of trying I finally found what the problem was. I followed the advice of the answer for a somewhat similar question and tried Google Analytics with website data tracking instead of mobile, and it worked. I guess as the gaforflash library is from 2008, it still uses the old Google Analytics API after all.

Upvotes: 2

user1901867
user1901867

Reputation:

The tracker property only exists within the scope of the function, so its getting recreated everytime the function is called; and possibly with different DisplayObject passed in too - this could be a problem.

Try this:

public class AnalyticsHelper
{
    private static var tracker:AnalyticsTracker;

    public static function trackScreenView(screen:DisplayObject, name:String):void
    {
        //only create tracker once
        if (!tracker)
            tracker = new GATracker(screen, "UA-XXXXXXXX-1", "AS3", false);        
        tracker.trackPageview("/screen/" + name);
    }
}

It doesnt really matter what DisplayObject is passed - just so long as it is a DisplayObject (so analytics can hook into Events). I'm not sure, but you probably need to pass the same DisplayObject everytime the swf runs so use something like root to keep it consistent.

Upvotes: 2

Related Questions