使用 @capgo/capacitor-install-referrer
@capgo/capacitor-install-referrer 在 Capacitor 应用中读取安装归因信号。
通过统一的 API,在 Android 上获取 Google Play Install Referrer 数据,并在 iOS 上获取 Apple AdServices 归因 token。
安装
bun add @capgo/capacitor-install-referrer
bunx cap sync
插件暴露的内容
getReferrer返回 Android 或 iOS 的安装归因详情。GetReferrer是用于从以下版本迁移的已弃用兼容别名:cap-play-install-referrer.- Android 会返回 Play referrer 字符串、点击时间戳、安装时间戳以及 instant app 标记。
- iOS 会返回 AdServices attribution token,还可以选择获取 Apple 的 attribution payload。
用法示例
import { InstallReferrer } from '@capgo/capacitor-install-referrer';
const result = await InstallReferrer.getReferrer();
if (result.platform === 'android') {
console.log(result.referrer);
}
if (result.platform === 'ios') {
console.log(result.attributionToken);
}
Apple 归因载荷
const result = await InstallReferrer.getReferrer({
fetchAppleAttribution: true,
appleAttributionRetryCount: 3,
appleAttributionRetryDelayMs: 5000,
});
console.log(result.appleAttribution);
平台注意事项
Android 使用 Google Play Install Referrer 服务,且必须通过 Play Store 安装才能拿到真实的 referrer 数据。iOS 使用 Apple AdServices,因为 Apple 并没有提供通用的 App Store 安装 referrer 等效机制。
完整参考
- GitHub: https://github.com/Cap-go/capacitor-install-referrer/
- 文档:/docs/plugins/install-referrer/
从“使用 @capgo/capacitor-install-referrer”继续
如果你正在使用 使用 @capgo/capacitor-install-referrer 要规划原生插件工作,请将其与 @capgo/capacitor-install-referrer 有关 @capgo/capacitor-install-referrer 的实现细节, 快速入门 有关“入门指南”中的实现细节, Capgo 插件目录 查看 Capgo 插件目录中的产品工作流, Capgo 提供的 Capacitor 插件 有关 Capgo 开发的 Capacitor 插件的实现细节,以及 添加或更新插件 有关添加或更新插件的实现细节。