开始使用
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-appsflyer`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/appsflyer/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
安装bun add @capgo/capacitor-appsflyerbunx cap sync导入
导入import { AppsFlyer } from '@capgo/capacitor-appsflyer';import type { AFAdRevenueData, AFAndroidInAppPurchase, AFAnonymizeUser, AFAppendToDeepLink, AFConsentData, AFConsentOptions, AFCuid, AFCurrency, AFData, AFDisable, AFEmails, AFEnableTCFDataCollection, AFEvent, AFFbDAL, AFFilters, AFHost, AFInit, AFIosInAppPurchase, AFLanguage, AFLatLng, AFLinkGenerator, AFLogInvite, AFOnelinkDomain, AFOnelinkID, AFPartnerData, AFPath, AFPhone, AFPromotion, AFPurchaseDetailsV2, AFPushPayload, AFUninstall, AFUrls,} from '@capgo/capacitor-appsflyer';API概述
API概述initSDK
__CAPGO_KEEP_2__使用此方法初始化并启动AppsFlyer SDK。此 API 应尽快在应用启动时调用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.initSDK({} as AFInit);startSDK
开始SDK仅在手动启动模式下使用此方法启动 AppsFlyer SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.startSDK();logEvent
日志事件在应用中记录事件。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logEvent({} as AFEvent);setCustomerUserId
设置客户ID设置客户ID使您可以将自己的唯一ID与AppsFlyer的唯一ID和其他设备的ID进行交叉引用。 此ID可在原始数据报告和Postback API中找到,用于与内部ID进行交叉引用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCustomerUserId({} as AFCuid);setCurrencyCode
设置货币代码设置应用内购买的货币。提供三位字符的ISO 4217 code。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCurrencyCode({} as AFCurrency);updateServerUninstallToken
更新服务器卸载令牌在 Android 上传递 GCM/FCM 令牌,或者在 iOS 上传递 APNs 令牌,另一个插件收集了它们。 将卸载测量令牌传递给 AppsFlyer。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.updateServerUninstallToken({} as AFUninstall);setAppInviteOneLink
设置邀请 OneLink设置邀请 OneLink ID,用于邀请属性的基础链接。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAppInviteOneLink({} as AFOnelinkID);setOneLinkCustomDomain
设置 OneLink 自定义域为 AppsFlyer 注册自定义 OneLink 域名,以便解析短链中的属性参数。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setOneLinkCustomDomain({} as AFOnelinkDomain);appendParametersToDeepLinkingURL
向 App Links 深度链接 URL 追加属性在不使用 OneLink 的情况下启用 App Links 深度链接的属性。请在调用此方法之前 startSDK()复制到剪贴板 pid 和在参数映射中。 is_retargeting=true 复制到剪贴板
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.appendParametersToDeepLinkingURL({} as AFAppendToDeepLink);setResolveDeepLinkURLs
使用此选项,当AppsFlyer OneLink被包裹在另一个Universal Link中时。
它让__CAPGO_KEEP_0__解析包裹的URL,以便深度链接仍然正常工作。Use this when an AppsFlyer OneLink is wrapped inside another Universal Link. It lets the SDK resolve the wrapped URL so deep linking still works correctly.
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setResolveDeepLinkURLs({} as AFUrls);addPushNotificationDeepLinkPath
配置__CAPGO_KEEP_0__从推送通知包裹中提取深度链接值的方式。Configures how the SDK extracts deep link values from push notification payloads.
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.addPushNotificationDeepLinkPath({} as AFPath);setSharingFilter
阻止事件传播到指定的AppsFlyer合作伙伴。复制到剪贴板
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilter({} as AFFilters);setSharingFilterForAllPartners
setSharingFilterForAllPartners阻止所有 AppsFlyer 合作伙伴接收事件。 覆盖 setSharingFilter。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilterForAllPartners();setSharingFilterForPartners
setSharingFilterForPartners阻止特定 AppsFlyer 合作伙伴接收事件。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilterForPartners({} as AFFilters);setAdditionalData
setAdditionalData设置额外的键值对数据发送到 AppsFlyer。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAdditionalData({} as AFData);getAppsFlyerUID
getAppsFlyerUID获取 AppsFlyer 的唯一设备 ID(每个新安装的应用程序都会创建一个)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.getAppsFlyerUID();anonymizeUser
“匿名化用户”AppsFlyer 分析数据(匿名化用户数据)中的终端用户退回选项。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.anonymizeUser({} as AFAnonymizeUser);stop
“停止”一旦调用了这个 API,我们的 SDK 就不会再与我们的服务器通信,停止运行。 在实施用户自愿/不自愿时有用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.stop();disableSKAdNetwork
“禁用SKAdNetwork”禁用 SKAdNetwork
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableSKAdNetwork({} as AFDisable);disableAdvertisingIdentifier
“禁用广告标识符”禁用 SDK 收集各种广告标识符,包括苹果广告标识符(IDFA)、谷歌广告标识符(GAID)、OAID 和亚马逊广告标识符(AAID)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableAdvertisingIdentifier({} as AFDisable);disableCollectASA
Section titled “disableCollectASA”退出苹果搜索广告的贡献。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableCollectASA({} as AFDisable);setHost
Section titled “setHost”设置自定义主机。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setHost({} as AFHost);generateInviteLink
Section titled “generateInviteLink”允许您的现有用户邀请他们的朋友和联系人作为新用户加入您的应用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.generateInviteLink({} as AFLinkGenerator);validateAndLogInAppPurchaseAndroid
Section titled “validateAndLogInAppPurchaseAndroid”API用于服务器验证应用内购买。成功验证后,会自动记录一个af_purchase事件,包含相关值。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.validateAndLogInAppPurchaseAndroid({} as AFAndroidInAppPurchase);validateAndLogInAppPurchaseIos
验证并登录iOS应用查看当前合同的源定义。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.validateAndLogInAppPurchaseIos({} as AFIosInAppPurchase);getSdkVersion
获取SDK版本获取应用Flyer SDK 版本
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.getSdkVersion();enableFacebookDeferredApplinks
Facebook延迟应用链接的收集启用Facebook延迟应用链接的收集。需要Facebook SDK 和 Facebook 应用程序在目标/客户端设备上。 此 API 必须在初始化 AppsFlyer SDK 之前才能正常工作。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableFacebookDeferredApplinks({} as AFFbDAL);sendPushNotificationData
推送通知数据测量和获取复制到剪贴板
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.sendPushNotificationData({} as AFPushPayload);setCurrentDeviceLanguage
setCurrentDeviceLanguage设置设备语言。数据将在原始数据报告中显示
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCurrentDeviceLanguage({} as AFLanguage);logCrossPromoteImpression
logCrossPromoteImpression记录跨促销活动的印象。确保使用在 AppsFlyer 控制台中显示的推广应用 ID。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logCrossPromoteImpression({} as AFPromotion);setUserEmails
setUserEmails设置用户电子邮件并加密
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setUserEmails({} as AFEmails);logLocation
logLocation手动记录用户位置
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logLocation({} as AFLatLng);setPhoneNumber
设置手机号将以SHA-256加密的字符串形式发送。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setPhoneNumber({} as AFPhone);setPartnerData
设置合作伙伴数据用于合作伙伴整合目的发送自定义数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setPartnerData({} as AFPartnerData);logInvite
设置用户邀请日志用于在应用中记录用户邀请事件(af_invite)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logInvite({} as AFLogInvite);setDisableNetworkData
设置禁用网络数据用于从设备中禁用收集网络运营商名称(运营商)和SIM卡运营商名称。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setDisableNetworkData({} as AFDisable);enableTCFDataCollection
启用TCF数据收集用于启用或禁用自动收集用户同意数据,适用于使用CMP的用户。 标志值将在应用程序会话之间持久化。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableTCFDataCollection({} as AFEnableTCFDataCollection);setConsentData
设置用户同意数据使用此方法手动设置用户同意数据。 如果您的应用程序不使用与TCF v2.2兼容的CMP,请使用以下方法手动向SDK提供同意数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentData({} as AFConsentData);logAdRevenue
记录广告收入通过为广告收入进行归因,应用程序所有者可以获得完整的用户LTV和营销活动ROI视图。 广告收入通过在应用程序中显示奖励视频、推广墙、插屏广告和横幅广告而产生。 您可以使用此方法记录广告收入。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logAdRevenue({} as AFAdRevenueData);setConsentDataV2
设置用户同意数据(v2)使用此方法手动设置用户同意数据。 如果您的应用程序不使用与TCF v2.2兼容的CMP,请使用以下方法手动向SDK提供同意数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentDataV2({} as AFConsentOptions);isSDKStarted
Section titled “isSDKStarted”检测是否已启动 AppsFlyer SDK
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.isSDKStarted();isSDKStopped
Section titled “isSDKStopped”检测是否已停止 AppsFlyer SDK
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.isSDKStopped();disableAppSetId
Section titled “disableAppSetId”禁用 AppSet ID 收集。若在 SDK 初始化之前调用,则 App Set ID 不会被收集。 若在初始化之后调用,则 App Set ID 会被收集但不会在请求包中发送。 仅限 Android。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableAppSetId();validateAndLogInAppPurchaseV2
Section titled “validateAndLogInAppPurchaseV2”API 服务器端验证内购 V2。 如果验证成功,则会自动记录 af_purchase 事件并包含相关值。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.validateAndLogInAppPurchaseV2({} as AFPurchaseDetailsV2);真实来源
名为“真实来源”的部分本页是根据插件生成的 src/definitions.ts当公共API上游发生变化时,请重新同步。