获取Android的谷歌Analytics(分析)引荐标签 [英] Get Android Google Analytics referrer tag

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

问题描述

我们打算使用谷歌Analytics(分析)来跟踪广告点击推介,通过Android Market,我们的应用程序。

We're planning to use Google Analytics to track ad click-through referrals, through the Android Market, to our application.

按照谷歌文档的引荐标签经由意图来通过,并且由谷歌分析库自动记录。

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.

所以不是,我注册的只有的我自己的接收,处理信息,并沿谷歌Analytics(分析)通过。不知道怎么犹太这个,但它的工作原理。 code如下:

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);
    }

}

然后,当你的应用程序实际上是启动,你可以拉值回了共享preferences,并随着用户注册或任何通过。我用的运动标签,我的目的,但你可以抓住你想从创建的引用字符串<一的任何参数href="https://developers.google.com/analytics/devguides/collection/android/devguide#google-play-builder">with这个工具。

这篇关于获取Android的谷歌Analytics(分析)引荐标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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