如何从Google Analytics中获取引荐来源/广告系列来源

时间:2013-04-16 23:16:38

标签: android google-analytics

来自here的最底层。这是一个URL生成器,我可以使用引荐来生成谷歌播放中我的应用程序的链接。如何从Google Analytics中添加该广告系列来源?我一直在搜索谷歌但仍然找不到答案。我发现有人说我应该创建一个扩展BroadcastReceiver的类,但我也发现了here。通过这样做,我将无法获得GA工作。 GA非常强大,我想使用它。我现在需要的是提取一个参数,该参数是来自GA的引用者/活动源。我还发现EasyTracker.getTracker()下有几个getter,比如getAppId(),getAppInstallerId()和getTrackingId(),但是没有一个被记录。我怎么知道哪个ID getter属于哪个? 谢谢您的帮助!

1 个答案:

答案 0 :(得分:4)

虽然推荐人/广告系列教程文档位于GA(谷歌分析)文档中,但您可以获取推荐人信息并在未实施GA的情况下在您的应用中使用,请参阅:https://developers.google.com/analytics/devguides/collection/android/v4/campaigns#google-play-implement

<!-- Used for Google Play Store Campaign Measurement-->
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
          android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

只需将第3行更改为自定义BroadCastReceiver示例:

<!-- Used for Google Play Store Campaign Measurement-->
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver android:name="com.xxx.Myapp.CustomReceiver"
          android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

您的自定义BroadCastReceiver可能:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.google.analytics.tracking.android.CampaignTrackingReceiver;

/*
 *  A simple Broadcast Receiver to receive an INSTALL_REFERRER
 *  intent and pass it to other receivers, including
 *  the Google Analytics receiver.
 */
public class CustomReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

    // get referrer info
     String referrer = intent.getStringExtra("referrer");
    // do anything you want with referrer
     ......

    // When you're done, pass the intent to the Google Analytics receiver
    new CampaignTrackingReceiver().onReceive(context, intent);
  }
}