获取 Android Google Analytics(分析)引荐来源网址标签

Get Android Google Analytics referrer tag(获取 Android Google Analytics(分析)引荐来源网址标签)
本文介绍了获取 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 文档 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(分析)引荐来源网址标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)