Android - 是否可以通过编程方式安装引荐来源网址
Android - Is it possible to get install referrer programmatically
我注意到浏览器中的一些 Google Play 应用程序链接具有 referrer=
属性,这显然告诉引荐来源网址将您发送到 Google Play 中该应用程序的页面.
是否可以在我的应用程序代码中看到该引荐来源网址(如果有)?如果没有,想在任何地方看到它?
广告系列参数 用于将有关将用户引荐到您应用的 Google Play 商店页面的广告系列或流量来源的信息传递到您应用的 Google 分析实施。
构建广告系列参数字符串后,将其作为引荐来源参数的值添加到 Google Play 商店网址,如本例所示:
https://play.google.com/store/apps/details?id=com.example.app
&referrer=utm_source%3Dgoogle
%26utm_medium%3Dcpc
%26utm_term%3Drunning%252Bshoes
%26utm_content%3DdisplayAd1
%26utm_campaign%3Dshoe%252Bcampaign
Google Play 商店会将引用参数的值传递给您应用的 Google 分析实施。
参考文献:https://developers.google.com/analytics/devguides/collection/android/v2/campaigns
https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-url-builder
您可以使用 com.android.vending.INSTALL_REFERRER
。
The Google Play com.android.vending.INSTALL_REFERRER Intent is
broadcast when an app is installed from the Google Play Store.
将此接收器添加到 AndroidManifest.xml
<receiver
android:name="com.example.android.InstallReferrerReceiver"
android:exported="true"
android:permission="android.permission.INSTALL_PACKAGES">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
创建广播接收器:
public class InstallReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
//Use the referrer
}
}
您可以按照此 answer 的步骤测试推荐跟踪。
使用Google Play Referrer API(自 2017 年 11 月 20 日起)
InstallReferrerClient mReferrerClient
...
mReferrerClient = newBuilder(this).build();
mReferrerClient.startConnection(this);
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerResponse.OK:
try {
ReferrerDetails response = mReferrerClient.getInstallReferrer();
String referrer = response.getInstallReferrer()
mReferrerClient.endConnection();
} catch (RemoteException e) {
e.printStackTrace();
}
break;
case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
Log.w(TAG, "InstallReferrer not supported");
break;
case InstallReferrerResponse.SERVICE_UNAVAILABLE:
Log.w(TAG, "Unable to connect to the service");
break;
default:
Log.w(TAG, "responseCode not found.");
}
}
我注意到浏览器中的一些 Google Play 应用程序链接具有 referrer=
属性,这显然告诉引荐来源网址将您发送到 Google Play 中该应用程序的页面.
是否可以在我的应用程序代码中看到该引荐来源网址(如果有)?如果没有,想在任何地方看到它?
广告系列参数 用于将有关将用户引荐到您应用的 Google Play 商店页面的广告系列或流量来源的信息传递到您应用的 Google 分析实施。
构建广告系列参数字符串后,将其作为引荐来源参数的值添加到 Google Play 商店网址,如本例所示:
https://play.google.com/store/apps/details?id=com.example.app
&referrer=utm_source%3Dgoogle
%26utm_medium%3Dcpc
%26utm_term%3Drunning%252Bshoes
%26utm_content%3DdisplayAd1
%26utm_campaign%3Dshoe%252Bcampaign
Google Play 商店会将引用参数的值传递给您应用的 Google 分析实施。
参考文献:https://developers.google.com/analytics/devguides/collection/android/v2/campaigns https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-url-builder
您可以使用 com.android.vending.INSTALL_REFERRER
。
The Google Play com.android.vending.INSTALL_REFERRER Intent is broadcast when an app is installed from the Google Play Store.
将此接收器添加到 AndroidManifest.xml
<receiver
android:name="com.example.android.InstallReferrerReceiver"
android:exported="true"
android:permission="android.permission.INSTALL_PACKAGES">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
创建广播接收器:
public class InstallReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
//Use the referrer
}
}
您可以按照此 answer 的步骤测试推荐跟踪。
使用Google Play Referrer API(自 2017 年 11 月 20 日起)
InstallReferrerClient mReferrerClient
...
mReferrerClient = newBuilder(this).build();
mReferrerClient.startConnection(this);
@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerResponse.OK:
try {
ReferrerDetails response = mReferrerClient.getInstallReferrer();
String referrer = response.getInstallReferrer()
mReferrerClient.endConnection();
} catch (RemoteException e) {
e.printStackTrace();
}
break;
case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
Log.w(TAG, "InstallReferrer not supported");
break;
case InstallReferrerResponse.SERVICE_UNAVAILABLE:
Log.w(TAG, "Unable to connect to the service");
break;
default:
Log.w(TAG, "responseCode not found.");
}
}