2

我已将谷歌分析添加到我的应用程序中,目的是获取有关您的屏幕的信息并发送自定义事件。

我获得了重复的内容......我也得到了不同的结果: “com.package.app.MainScreen” - 300 次观看和 “主屏幕” - 200 次观看

我有兴趣只跟进活动的自定义名称而不是包。无论如何,因为两者都显示不同的结果?

public class MainScreen extends Activity {
private static final String GA_PROPERTY_ID = "UA-12345678-9"; 
private static final String SCREEN_LABEL = "Main Screen";
Tracker mTracker;
EasyTracker easyTracker;

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

    mTracker = GoogleAnalytics.getInstance(this).getTracker(GA_PROPERTY_ID);
    mTracker.set(Fields.SCREEN_NAME, SCREEN_LABEL); // For Custom Name from activity
    mTracker.send(MapBuilder.createAppView().build());

    easyTracker = EasyTracker.getInstance(this); //  Analytics Events
    ...
    easyTracker.send(MapBuilder.createEvent("MainScreen", "Play", category.get(1), null).build()); //AnalyticsEvents
    ...


}

@Override
public void onStart() {
    super.onStart();
    EasyTracker.getInstance(this).activityStart(this);
}

@Override
public void onStop() {
    super.onStop();
    EasyTracker.getInstance(this).activityStop(this);
}

}

analytics.xml

<?xml version="1.0" encoding="utf-8" ?>
    <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
      <!--Replace placeholder ID with your tracking ID-->
      <string name="ga_trackingId">UA-12345678-9</string>
      <!--Enable automatic activity tracking-->
      <bool name="ga_autoActivityTracking">true</bool>
      <!--Enable automatic exception tracking-->
      <bool name="ga_reportUncaughtExceptions">true</bool>
    </resources>

谷歌分析开发指南

4

1 回答 1

1

您有 3 个单独的跟踪实例,2 个在 onCreate() 中,还有一个在 onStart()/onStop() 中。我建议将它们从 onCreate() 中删除,并将 EasyTracker 保留在 onStart()/noNstop() 中,这样您就不会获得冗余数据,但仍会获得会话长度。

要为 EasyTracker 跟踪的活动设置自定义名称,您可以analytics.xml通过添加以下字段来设置它们:

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

<-- The screen names that will appear in reports -->
<string name="com.example.app.BaseActivity">Home</string>
<string name="com.example.app.PrefsActivity">Preferences</string>

这是一个使用 EasyTracker 发送 UI 事件的 onClick(View):

@Override
public void onClick(View view) {
    String action = "";
    switch(view.getId()) {
    case R.id.btnWeb:
        getSherlockActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(sponsor.getWebsite())));
        action = "Website";
        break;
    case R.id.btnPhone:
        getSherlockActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + PhoneNumberUtils.stripSeparators(sponsor.getPhone()))));
        action = "Phone";
        break;
    }

      EasyTracker easyTracker = EasyTracker.getInstance(getSherlockActivity());
      if (easyTracker != null) {
          easyTracker.send(MapBuilder
              .createEvent("ui_action",
                           "sponsor_page",
                           title + ": " + sponsor.getName() + " - " + action,
                           null)
              .build()
          );
      }
}
于 2013-10-20T22:44:47.387 回答