设置Google Analytics的屏幕名称

时间:2015-07-30 11:38:10

标签: android google-analytics

我在使用Google Analytics时遇到问题,它会显示我的ScreenNames:

package.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());
    }
}

但是在谷歌分析中,我得到2次屏幕,有2个不同的名字:

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;
}

如何才能拥有班级名称?

1 个答案:

答案 0 :(得分:2)

也许您可以尝试使用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>