Android:在Google Analytics中显示屏幕名称

时间:2016-06-23 11:46:35

标签: android google-analytics

我刚刚将Google Analytics集成到了我的APP,但是我有一个问题。完整的活动名称会显示在Google Analytics中的报告中,例如 com.apps.myapp.MainActivity 但是我不需要客户端查看屏幕的全名这是我的代码:

1:类中的代码扩展了application:

public class Google_Analytics extends Application
{
   private Tracker mTracker;

/**
 * Gets the default {@link Tracker} for this {@link Application}.
 *
 * @return tracker
 */
synchronized public Tracker getDefaultTracker()
{
    if (mTracker == null)
    {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        mTracker = analytics.newTracker(R.xml.global_trackerr);
        mTracker.enableAutoActivityTracking(true);
    }
    return mTracker;
}

}

2:活动中的代码

public class MainActivity extends AppCompatActivity
{

private Tracker mTracker;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_city_listing_details);

    Google_Analytics application = (Google_Analytics )  getApplication();
    mTracker = application.getDefaultTracker();


}

@Override
protected void onResume()
{
    super.onResume();
mTracker.setScreenName("Home screen");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}

}

3:xml config中的代码

   <?xml version="1.0" encoding="utf-8"?>
   <resources>
   <!--Replace placeholder ID with your tracking ID-->
   <string name="ga_trackingId">UA-7973XXXX-1</string>

   <!--Enable automatic activity tracking-->
  <bool name="ga_autoActivityTracking">true</bool>

  <!--Enable automatic exception tracking-->
  <bool name="ga_reportUncaughtExceptions">true</bool>
  <screenName         
name="com.apps.myapp.MainActivity">Home Screen            
 Screen</screenName>

1 个答案:

答案 0 :(得分:2)

将ga_autoActivityTracking设置为false:

<bool name="ga_autoActivityTracking">false</bool>