In Google Analytics V4, what screen name should I send?

I have completed this guide to implement Google Analytics in my Android app. I am having trouble understanding the document.

The document talks about creating an XML file with this as content:

<screenName name="com.mycompany.myapp.MainActivity"> SomeApp MainActivity </screenName> 

And to send the screen, I have to do this:

 Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER); t.setScreenName(screenName); t.send(new HitBuilders.AppViewBuilder().build()); 

However, I'm not sure what screenName . Is this the value of name ( com.mycompany.myapp.MainActivity ) or the value of screenName ( SomeApp MainActivity )?

+7
android google-analytics google-analytics-v4
source share
3 answers

The xml configuration that you describe is used whenever automatic activity tracking is enabled. This tracking automatically reports a new screenview whenever an action starts, which allows you to manually trigger screenview events in your code.

To enable automatic activity tracking, you can set ga_autoActivityTracking boolean to true in the xml-tracker configuration:

 <!-- Enable automatic Activity measurement --> <bool name="ga_autoActivityTracking">true</bool> 

By default, this automatic reporting tool will use your Activity class names as the name of the displayed screen (for example, com.mycompany.myapp.MainActivity ). These class names are often long and hard to read, so Google allows us to customize the screen display name for each action. This is what this part of your question does:

 <screenName name="com.mycompany.myapp.MainActivity"> SomeApp MainActivity </screenName> 

In this configuration, automatic activity tracking will use the string "SomeApp MainActivity" instead of "com.mycompany.myapp.MainActivity" when automatically presenting screen views for this activity.

It is important to note that if you do not use automatic activity tracking, any configuration of the screen name in the xml tracker will be ignored. In this case, you will need to provide a screen name each time you programmatically trigger a screen view event. What happens in your code example:

 Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER); t.setScreenName(screenName); t.send(new HitBuilders.AppViewBuilder().build()); 

Setting the screen name in your xml configuration is not used in this code, because it is not part of automatic activity tracking. Instead, you must manually set the screen name to the tracker before sending the screen. This is more flexible than automatic activity tracking - for example, in a fragmented application, navigation can be performed using fragment transactions, and not with activity changes. In this case, tracking changes in activity alone will not report every screen change in your application accordingly. It is assumed that tracking activity on the network should be less overhead than manually sending views on the screen, but I find it inflexible and more error-prone (you need to manually add <screenName> in your xml every time a new activity is introduced, and it's very easy to forget).

+13
source share

I think you only want to send the string "SomeActivity" to GA. If you want to make it easy, you can see my answer to this post. I think this will help you.

Google Analytics - NetworkOnMainThreadException when sent to AsyncTask

+5
source share

Just set the tag for the name of the current screen (view) to String. It will be used to track the screens that are viewed by users.

0
source share

All Articles