示例 URL 可以如下所示
https://play.google.com/store/apps/details?id=com.example.application&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Drunning%252Bshoes%26utm_content%3Dlogolink%26utm_campaign%3Dspring_sale
您可以通过短信或电子邮件(缩短的 URL)发送此 url,或将它们嵌入您的网站。因此,当有人单击 URL 时,它将导航用户到 Play 商店。
要在 utm_referrer、utm_medium、utm_term、utm_content 等 URL 中接收 utm 数据,您必须像以下那样配置应用程序。
- 在你的 android manifest 文件中添加 google referrer receiver
<receiver
android:name="com.example.application.ReferrerReceiver"
android:exported="true">
<intent-filter>
<action
android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
2 创建一个ReferrerReceiver.java
广播接收器类
public class ReferrerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getAction().equals("com.android.vending.INSTALL_REFERRER")) {
return;
}
String referrer = intent.getStringExtra("referrer");
try {
// This is your data from th URL, you can do any kind of
// manipulation using this.
referrer = URLDecoder.decode(referrer, "UTF-8");
} catch (UnsupportedEncodingException e) {
return;
}
}
}