Google Analytics demographics For Android App
Asked Answered
H

2

8

I used Google Analytics Demographics on android app using Google play service library. i have updated my android code using enableAdvertisingIdCollection(). its working fine with screens and data. But its demographics info isn't working? Please suggest how do i handle demographics.

thanking you.

Code : Application code :

...

 synchronized Tracker getTracker( TrackerName trackerId, String appKey)
 {

    Log.d("Application", "In Application class getTracker PID" + appKey);
    if (!mTrackers.containsKey(trackerId))
    {

        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

        analytics.setDryRun(false);

        analytics.getLogger().setLogLevel(Logger.LogLevel.INFO);

        Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(appKey) : analytics
                .newTracker(R.xml.app_tracker);

        if (t != null)
        {
            t.enableAdvertisingIdCollection(true);
        }

        mTrackers.put(trackerId, t);

    }
    return mTrackers.get(trackerId);
}

...

code on oncreate()

...

 try
 {

    GoogleAnalytics.getInstance(getActivity()).reportActivityStart(getActivity());

        Tracker t = ((AppApplication) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER, Appkey);
        t.setScreenName("Home Screen");
        // t.setSampleRate(sampleRate);
        t.enableAdvertisingIdCollection(true);
        t.send(new HitBuilders.AppViewBuilder().build());


    }
    catch (Exception ex)
    {
        CustomLogger.showLog("GAcode", ex.getMessage());
    }
Helwig answered 12/1, 2015 at 11:43 Comment(0)
H
0

I looked at google documentation thoroughly, and as well as most of the stackoverflow and Facebook links, I didn't found any help or code tweak that could enable demographics in android mobile apps for recent google sdk. But still i found custom demographics by sending events through tracker with details about people.

So ,I concluded that Google Analytics Demographics works perfectly with web apps but yet it did not support android apps.

Helwig answered 28/1, 2015 at 9:27 Comment(0)
P
2

Just for helping others, google support is a lot unclear about this piece of code:

Enabling Advertising Features

// Get tracker.

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);

// Enable Advertising Features.

t.enableAdvertisingIdCollection(true);



The tracker there is the tracker initialized in your Application class, and get tracker is a function where you should create a List of trackers and get them by name. If you are using just one tracker, you can do:

 public static Tracker tracker;

@Override
public void onCreate() {
    super.onCreate();
    startGoogleAnalytics();
}

public void startGoogleAnalytics() {
    analytics = GoogleAnalytics.getInstance(this);
    analytics.setLocalDispatchPeriod(1800);

    tracker = analytics.newTracker(R.xml.global_tracker); // here you can add just your id value too
    tracker.enableExceptionReporting(true);
    tracker.enableAdvertisingIdCollection(true);
    tracker.enableAutoActivityTracking(true);
}

public synchronized Tracker getTracker() {
    if (tracker == null) {
        startGoogleAnalytics();
    }
    return tracker;
}

Then on your activity you can do:

    Tracker t = ((YouApplicationClassName)getApplication()).getTracker();
    t.enableAdvertisingIdCollection(true);
Parmenides answered 23/6, 2015 at 19:22 Comment(0)
H
0

I looked at google documentation thoroughly, and as well as most of the stackoverflow and Facebook links, I didn't found any help or code tweak that could enable demographics in android mobile apps for recent google sdk. But still i found custom demographics by sending events through tracker with details about people.

So ,I concluded that Google Analytics Demographics works perfectly with web apps but yet it did not support android apps.

Helwig answered 28/1, 2015 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.