据我的老板说,我们的一些应用程序已通过 Google Ads 投资于应用程序的广告。为了让他们解析数据并正确分析它们,他们正在使用 UTM 自动标记方法。客户端(Android 设备)的工作是使用 Firebase Analytics 发送 UTM,并根据此 UTM 向 Firebase 发送自定义事件。
但是,我们的数据显示 Firebase SDK 和我们的事件都被错误地传输。点击次数和下载次数不匹配。由于它们都不正确,我猜设备本身收到的 UTM 是错误的,需要正确接收,我无法找到答案。
在将应用程序下载到设备后,我正在使用Install Referrer Library来跟踪 UTM 是什么。我猜 Firebase SDK 也使用了一些类似的方法。在我们这边,UTM 被记录到SharedPreferences
,如果查询成功就不会再次查询。
下面是它的相关代码(该processReferrer
方法基本上是根据我们的需要解析UTM):
/**
* Checks if the referrer information is recorded before, if not, creates
* a connection to Google Play and saves the data to shared preferences.
*/
private static void fetchReferrerInformation(Context context)
{
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(context);
String utmData = preferences.getString(UTM_DATA, "");
// Only connect if utm is not recorded before.
if (TextUtils.isEmpty(utmData))
{
InstallReferrerClient client;
try
{
client = InstallReferrerClient.newBuilder(context).build();
client.startConnection(new InstallReferrerStateListener()
{
@Override
public void onInstallReferrerSetupFinished(int responseCode)
{
switch (responseCode)
{
case InstallReferrerClient.InstallReferrerResponse.OK:
{
ReferrerDetails response;
try
{
response = client.getInstallReferrer();
}
catch (Exception e)
{
Log.e(TAG, "Error while fetching referrer information.", e);
if (Fabric.isInitialized())
Crashlytics.logException(new IllegalStateException("Exception while fetching UTM information.", e));
return;
}
if (response != null)
{
processReferrer(context, response.getInstallReferrer());
}
break;
}
case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
{
Log.w(TAG, "Install referrer client: Feature is not supported.");
break;
}
case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
{
Log.w(TAG, "Install referrer client: Service is unavailable.");
break;
}
}
try
{
client.endConnection();
}
catch (Exception ignored){}
}
@Override
public void onInstallReferrerServiceDisconnected()
{
// Do nothing, we need to fetch the information once and
// it is not really necessary to try to reconnect.
// If app is opened once more, the attempt will be made anyway.
}
});
}
catch (Exception e)
{
if (Fabric.isInitialized())
Crashlytics.logException(new IllegalStateException("Exception while fetching UTM information.", e));
}
}
else
Log.i(TAG, "UTM is already recorded, skipping connection initialization. Value: " +
utmData);
}
该方法非常简单,但是数据似乎是错误的。那么,执行起来似乎有些不正确吗?如果不是,为什么从 Google Ads 收到的数据有误?任何帮助表示赞赏,非常感谢。
编辑:经过一些测试,这是我发现的:
作品:
一个 API 19 真实设备(GM Discovery II Mini)和安装了 Play Store 的 API 25-29 仿真器之间。编辑:UTM 也可以通过安装了 Play Store 的 API 23 和 24 Genymotion Emulators 获取。
不起作用:
安装了最新的 Google Play Services 和 Play Store 的 API 24 Android Studio 模拟器(设备也登录到我的帐户),而真实设备(General Mobile 4G Dual,API 23)无法查询 UTM 信息。下面的代码落在InstallReferrerResponse.FEATURE_NOT_SUPPORTED
. 所以我几乎可以肯定安装引用客户端在某些 API 级别上存在错误。
编辑:向谷歌打开一个问题:https ://issuetracker.google.com/issues/149342702