Android的转诊分析v3时被删除?(Android referral removed in an

2019-10-19 00:42发布

我花了最后两天,试图找到一种解决方法。

我需要预先配置取决于介和自谷歌发挥我的应用程序播放在安装应用时安装参照意图,我创建了自己的接收器这项任务。 为清单声明和接收器中的代码是:

舱单申报:

    <receiver
        android:name="my.package.CustomReceiver"
        android:exported="true" >
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>

而CustomReceiver的简化代码:

public class CustomReceiver extends BroadcastReceiver {

private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";

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

    Log.d("debug", "waking receiver");
    Uri uri = intent.getData();
    getReferrerMapFromUri(uri);

    new CampaignTrackingReceiver().onReceive(context, intent);
}

void getReferrerMapFromUri(Uri uri) {

    MapBuilder paramMap = new MapBuilder();

    // If no URI, return an empty Map.
    if (uri == null) {
        Log.d("debug", "intent null");

        return;
    }

    if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {

        // MapBuilder.setCampaignParamsFromUrl parses Google Analytics
        // campaign
        // ("UTM") parameters from a string URL into a Map that can be set
        // on
        // the Tracker.
        paramMap.setCampaignParamsFromUrl(uri.toString());

        Log.d("debug", paramMap.get(Fields.CAMPAIGN_SOURCE));

        // If no source parameter, set authority to source and medium to
        // "referral".
    } else if (uri.getAuthority() != null) {

        paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
        paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());

    }
}

}

就这样。 我送广播安装意图与亚行shell命令,但它没有得到根本激活。 我使用谷歌分析V3。

先感谢您!

Answer 1:

我尝试过这种方式。 而且它的工作。(我也使用谷歌分析V3)

首先,在清单:

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

其次,添加CustomReceiver延伸广播接收器(在我而言,我只是复制和粘贴全部来自开发者的代码)

package com.example.testanalytics;

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

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

public class CustomReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
    // Pass the intent to other receivers.

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

最后一步:在我的活动(我想将消息发送给谷歌分析)创建一个意图,并调用sendBroadcast(意向)如下:

Intent it = new Intent("com.android.vending.INSTALL_REFERRER");

it.setPackage("com.example.testanalytics");
it.putExtra("referrer", "utm_source%3Dyahoo%26utm_medium%3Dbanner+cpc%26utm_term%3Debook%26utm_content%3Dmy_content%26utm_campaign%3Dmy_campaign_name_2");

sendBroadcast(it);

而刚刚得到它。 我希望这可以帮助你。



文章来源: Android referral removed in analytics v3?