analytics - 测量推荐的谷歌教程 - 本教程可以吗?

时间:2014-04-03 12:02:33

标签: android google-analytics

根据Google Analytics Campaign Measure(版本3 ),我接着是他们的教程,但在onStart我们只创建了调用MapBuilder.createAppView()而没有发送此数据,我是否应该更改它

EasyTracker.getInstance(this).send(MapBuilder.createAppView().setAll(getReferrerMapFromUri(uri)).build());

?我认为存在错误,因为我在Google Analytics面板上看不到任何反对意见。

以下是Google Analytics Campaing Measuring代码:

public class MainActivity extends Activity {
  private static final String GA_PROPERTY_ID = "UA-XXXX-Y";
  private static final String SCREEN_LABEL = "Home Screen";

  private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";
  Tracker mTracker;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mTracker = GoogleAnalytics.getInstance(this).getTracker(GA_PROPERTY_ID);
  }
  @Override
  public void onStart() {
    super.onStart();
    mTracker.set(Fields.SCREEN_NAME, SCREEN_LABEL);

    Intent intent = this.getIntent();
    Uri uri = intent.getData();

    MapBuilder.createAppView().setAll(getReferrerMapFromUri(uri));
  }

  Map<String,String> getReferrerMapFromUri(Uri uri) {
    MapBuilder paramMap = new MapBuilder();

    if (uri == null) { return paramMap.build(); }
    if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {
      paramMap.setCampaignParamsFromUrl(uri.toString());
     } else if (uri.getAuthority() != null) {
       paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
       paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());
     }
     return paramMap.build();
  }
}

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。 要检索&#34;常规广告系列和流量来源归因&#34;,我尝试了https://developers.google.com/analytics/devguides/collection/android/v3/campaigns的示例代码

我的Uri由&#34; Google Play网址构建器生成&#34; https://play.google.com/store/apps/details?id=com.flipr.ga3&referrer=utm_source%3Dsource3%26utm_medium%3Dmedium3%26utm_term%3Dterm3%26utm_content%3Dcontent3%26utm_campaign%3Dcampaign3&#34;

点击该应用后,它确实启动了我的应用。但是&#34; getQueryParameter(CAMPAIGN_SOURCE_PARAM)&#34;已退回null

我发现Uri中的确切参数名称是&#34; referrer&#34;而不是&#34; utm_source&#34;。 我认为这就是getQueryParameter(CAMPAIGN_SOURCE_PARAM)返回null

的原因

我认为样本是错的,我们应该: 1. String str1 = getQueryParameter("referrer") 2.然后,将所有key-vaue对检索到地图中 3. createAppView().setAll(map)

答案 1 :(得分:0)

我已经解决了这个问题。在某种程度上。 文档编辑器做了太多操作。 代替:

MapBuilder.createAppView().setAll(getReferrerMapFromUri(uri));

应该是:

mTracker.send(getReferrerMapFromUri(uri));

因为.send()需要Map并且getReferrerMapFromUri(uri)返回此值。