BJM
BJM

Reputation: 233

Set Screen Name for Google Analytics

I have a problem with Google Analytics, it display my ScreenNames like this:

package.class

But I just want the classe name, so I did this in my class:

@Override
public void onResume() {

    super.onResume();

    final Tracker tracker = ((App) this.getApplication()).getTracker();
    if(tracker != null){

        tracker.setScreenName(getClass().getSimpleName());
        tracker.send(new HitBuilders.ScreenViewBuilder().build());
    }
}

But in Google Analytics I get 2 times the Screen with 2 different name:

package.class
class

App.java:

private static final String TAG = "App";
public synchronized Tracker getTracker() {

    try {
        final GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this);
        return googleAnalytics.newTracker(R.xml.app_tracker);

    }catch(final Exception e){
        Log.e(TAG, "Failed to initialize Google Analytics V4");
    }

    return null;
}

How to do to just have class name ?

Upvotes: 4

Views: 2789

Answers (1)

Chol
Chol

Reputation: 2117

Maybe you can try in your app_tracker.xml :

<!-- If ga_autoActivityTracking is enabled, an alternate screen name can be specified to
substitute for the full length canonical Activity name in screen view hit. In order to
specify an alternate screen name use an <screenName> element, with the name attribute
specifying the canonical name, and the value the alias to use instead. -->

<screenName name="com.example.ActivityMain">Home activity</screenName>

Upvotes: 2

Related Questions