获取 Android Google Analytics 引用标记 [英] Get Android Google Analytics referrer tag

查看:18
本文介绍了获取 Android Google Analytics 引用标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们计划使用 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 文档 引荐来源标签通过意图传递,并由 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 引用标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆