以下是模拟从google play 安装是发的广告以及渠道来源广播 (在 adb Shell 下执行)
锁屏
am broadcast -a com.android.vending.INSTALL_REFERRER -n com.zuimeia.suite.lockscreen.international/com.zuimeia.suite.lockscreen.receiver.GACampaignTrackingReceiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=11"
swift
am broadcast -a com.android.vending.INSTALL_REFERRER -n com.zuiapps.suite.swift/com.zuiapps.suite.swift.receiver.GACampaignTrackingReceiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=11"
Log TAG(用于搜索打印 的log日志)
INSTALL_RECEIVER
google 广告后缀添加地址
https://developers.google.com/analytics/devguides/collection/android/v4/campaigns#google-play-url-builder
真是的地址 经过测试得到的数据 和通过上面模拟得到的数据是一致的
测试时 跳转到 swif 的googleplay 地址
https://play.google.com/store/apps/details?id=com.zuiapps.suite.swift&referrer=utm_source%3DtestSource1%26utm_medium%3DtestMedium1%26utm_term%3DtestTerm1%26utm_content%3DtestContent1%26utm_campaign%3DtestCampaign1%26utm_campaign3333%3DtestCampaign13333"
具体实现获取广告数据方法:
1. 现在mainfest 中注册 监听器 和相应的google 服务:
// 下面这个是正常的google 服务的监听广告信息的服务
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
// 这里是我们监听广告信息监听器
<receiver
android:name="com.appsflyer.MultipleInstallBroadcastReceiver"
android:exported="true"
android:process=":service">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
在监听器做如下处理
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.e(TAG, "Received install event");
String referrer = "";
Bundle extras = intent.getExtras();
if (extras != null) {
referrer = extras.getString("referrer");
// 得到相应的广告信息 是url 参数格式,需要解析
// 格式: utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=11
LogUtil.e(TAG, "Referer is: " + referrer);
}
// 由于广告被我们截取了,为了googlepaly 那边的通知还要我们手动去调用 google play 的相关服务监听
new CampaignTrackingReceiver().onReceive(context, intent);
}