问题描述
我们计划使用 Google Analytics 来跟踪通过 Android Market 到我们应用程序的广告点击推荐.
We're planning to use Google Analytics to track ad click-through referrals, through the Android Market, to our application.
根据 Google 文档 referrer 标签是通过 Intent 传递的,并由 Google Analytics 库自动记录.
According to the Google Documentation the referrer tag comes through via an intent, and is automatically recorded by the Google Analytics library.
这很好,但我们需要提取该推荐标签以进行我们自己的内部分析.文档没有详细说明如何从初始启动意图中获取它,以及如何在上线之前模拟它的说明.
That's great, but we need to extract that referral tag for our own internal analytics. The documentation is shy on details about how to grab it out of the initial launch intent, and instructions on how to simulate this before going live.
有人有这方面的经验吗?
Does anyone have experience with this?
推荐答案
我继续并发布了一个坏点查找器应用程序来玩窥探意图.出于某种原因,当我注册了两个不同的广播接收器(即 com.google.android.apps.analytics.AnalyticsReceiver 和我自己的)时,我自己从来没有收到过.
I went ahead and published a dead pixel finder app to play with snooping on the intent. For some reason, when I registered two different broadcast receivers (ie com.google.android.apps.analytics.AnalyticsReceiver and my own), I never received it on my own.
因此,我仅注册了我自己的接收器,处理信息,并将其传递给 Google Analytics.不知道这是多么洁净,但它有效.代码如下.
So instead, I registered only my own receiver, process the information, and pass it along to Google Analytics. Don't know how kosher this is, but it works. Code follows.
public class ZSGoogleInterceptor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String referrerString = extras.getString("referrer");
// Next line uses my helper function to parse a query (eg "a=b&c=d") into key-value pairs
HashMap<String, String> getParams = Utility.getHashMapFromQuery(referrerString);
String source = getParams.get("utm_campaign");
if (source != null) {
SharedPreferences preferences = context.getSharedPreferences("my_prefs", Context.MODE_PRIVATE);
Editor preferencesEditor = preferences.edit();
preferencesEditor.putString("ga_campaign", source);
preferencesEditor.commit();
}
// Pass along to google
AnalyticsReceiver receiver = new AnalyticsReceiver();
receiver.onReceive(context, intent);
}
}
然后,当您的应用程序实际启动时,您可以将值从共享首选项中提取出来,并将其与用户注册或其他内容一起传递.我将广告系列标签用于我的目的,但您可以从创建的引荐来源字符串中获取任何您想要的参数 用这个工具.
Then, when your application is actually launched, you can pull the value back out of the shared preferences and pass it along with user signup or whatever. I used the campaign tag for my purposes, but you can grab any parameters you want out of the referrer string created with this tool.
这篇关于获取 Android Google Analytics(分析)引荐来源网址标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!