bigO bigO - 14 days ago 5
Android Question

How to use tracking id of google analytics in android app?

I am trying to integrate google analytics with my android app. I followed the steps in the following link:

https://developers.google.com/analytics/devguides/collection/android/v3/#manifest

Then i tried the look at the statistic of my app, but it seems like analytics is not working, i must have done something wrong. The problem is, in those steps we do not make use of the tracking id, and in google analytic's web site, it says that

Download the Google Analytics SDK for Android or iOS and implement the tracking code,
including this tracking ID.


What does it mean to "implement the tracking id"? What should i do about this can anyone help me?

Thanks

Answer

Use this:

Tracker tracker = GoogleAnalytics.getInstance(context).getTracker(ga_trakingId);

Then you can SET some variables, that will be send to GoogleAnalytics:

tracker.set(Fields.APP_NAME, "Best Android Application");
tracker.set(Fields.APP_VERSION, "1.0");

To SEND some info, events:

tracker.send(MapBuilder.createEvent("UX", "App Launch", null, null).build());

You must watch Behind the Code: The Google Analytics v3 Mobile SDKs, all info from there.

Update 1

Google Analytics API v4 you should create google-services.json file from here and then you can use:

public Tracker getTracker() {
    return GoogleAnalytics.getInstance(this).newTracker(R.xml.global_tracker);
}

And then you canuse it like this way:

getTracker().setScreenName("SomeScreenOrActivityName");
getTracker().send(new HitBuilders.ScreenViewBuilder().build()); // send screen name