如何使用Google的installreferrer库测试安装引荐来源网址?

时间:2019-08-30 21:15:20

标签: android google-play google-play-services install-referrer

有很多示例如何测试检测安装引荐来源网址的“默认”方式,但是没有示例如何测试com.android.installreferrer:installreferrer库。

例如

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER 
                       -n your.package.name/path.to.receiver --es referrer
                       --es referrer "EXTRA_STRING_VALUE"

不起作用,因为我们不知道receiver的路径。那么如何测试呢?

2 个答案:

答案 0 :(得分:1)

InstallReferrerClient中,似乎BroadcastReceiver中没有注册任何AndroidManifest.xml。该库只是绑定到系统的安装引荐来源服务...

private static final String SERVICE_PACKAGE_NAME = "com.android.vending";
private static final String SERVICE_NAME = "com.google.android.finsky.externalreferrer.GetInstallReferrerService";
private static final String SERVICE_ACTION_NAME = "com.google.android.finsky.BIND_GET_INSTALL_REFERRER_SERVICE";

客户端在手动安装后会收到引荐来源网址utm_source=google-play&utm_medium=organic。没有暴露的BroadcastReceiver(但InstallReferrerService应该有一个)。

原始Intent Bundle的键是:install_referrerreferrer_click_timestamp_secondsinstall_begin_timestamp_seconds(如果要尝试模拟它们)-但{{1 }}回调将间接传递结果。

文档还指出:

  

安装引荐来源网址信息的有效期为90天,除非重新安装该应用程序,否则不会更改。 为避免在应用程序中不必要的API调用,您应在安装后的首次执行期间仅调用一次API。您的应用程序可以收听系统广播onInstallReferrerSetupFinished(),以识别该应用程序的首次执行。


因此,这应该是Intent.ACTION_PACKAGE_FIRST_LAUNCH intent-filter的{​​{1}},随后将action连接到Intent.ACTION_PACKAGE_FIRST_LAUNCH。一个人无法使用InstallReferrerClient来触发InstallReferrerService,因为它会过滤“受保护的广播操作字符串”,因此只有在从Play商店安装时才可能触发它。

根据文档,该实现可能类似于:

Intent.ACTION_PACKAGE_FIRST_LAUNCH

adb

AndroidManifest.xml

<receiver
    android:name=".receiver.PackageStatusReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH"/>
    </intent-filter>
</receiver>

要对此进行测试,您需要指向Play商店的引荐来源网址链接,然后通过它们安装程序包...否则,将仅记录默认引荐来源地址(除了在正确实现客户端时甚至无法触发意图)

答案 1 :(得分:1)

您可以通过在Play电子市场控制台中设置应用的内部测试版本来测试安装引荐来源网址。然后,使用Play Market URL Builder中的修改链接。