简体   繁体   中英

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

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

The new process generates a file by Google which is called GoogleService-Info.plist .

This file contains (key, string) and one of them is:

<key>TRACKING_ID</key>
<string>*YOUR TRACKING ID*</string> // Auto generated by GAI

Just open the file and confirm that this is your tracking ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM