简体   繁体   中英

set custom labels for activity name in Google Analytics

i use Google Analytics for monitor my users in my Android app. Now i want to set label's for each activity in google analytics. Just for better understanding i don't want see Activity Class name, instead see my custom label's. how i can do this?

in onCreate:

// Get tracker.
Tracker t = ((MyApplicationClass)
getActivity().getApplication()).getTracker(MyApplicationClass.TrackerName.APP_TRACKER);

// Set screen name. Where path is a String representing the screen name.
t.setScreenName("YOUR_CUSTOM_LABLE_FOR_THIS_SCREEN");

// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());

Initialize variable:

private Tracker tracker;

onCreate()

tracker = ((GlobalClass) getApplication()).getTracker(GlobalClass.TrackerName.APP_TRACKER);
tracker.setScreenName("Add_your_own_lable");
tracker.send(new HitBuilders.AppViewBuilder().build());

Hope this will help you.

You can also configure the activity names with XML tracker configuration file. https://developers.google.com/analytics/devguides/collection/android/v4/#analytics-xml

For example if you like to name "com.example.app.MainActivity" activity as "Home Screen" you can add:

<screenName name="com.example.app.MainActivity">
   Home Screen
</screenName>

to the configuration file. When creating the tracker, make sure you are using the XML configuration instead of hardcoded trackerId.

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