开始使用
复制一个包含安装步骤和此插件的完整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
标题为“initSDK”使用此方法初始化并启动 AppsFlyer SDK。此 API 应在应用启动时立即调用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.initSDK({} as AFInit);startSDK
标题为“startSDK”使用此方法在手动启动模式下启动 AppsFlyer SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.startSDK();logEvent
标题为“logEvent”记录应用内事件。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logEvent({} as AFEvent);setCustomerUserId
Section titled “setCustomerUserId”为您的客户设定唯一标识符,可让您在 AppsFlyer 的唯一标识符和其他设备的 ID 中进行交叉引用。 此 ID 在原始数据报告和 Postback API 中可用,用于与您的内部 ID 进行交叉引用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCustomerUserId({} as AFCuid);setCurrencyCode
Section titled “setCurrencyCode”设置应用内购买的货币。提供一个三位字符的 ISO 4217 code。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCurrencyCode({} as AFCurrency);updateServerUninstallToken
Section titled “updateServerUninstallToken”将 Android 上的 GCM/FCM token 或 iOS 上的 APNs token 传递给另一个插件。 使用此功能将卸载测量令牌传递给 AppsFlyer。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.updateServerUninstallToken({} as AFUninstall);setAppInviteOneLink
Section titled “setAppInviteOneLink”设置用于邀请归因的 OneLink ID。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAppInviteOneLink({} as AFOnelinkID);setOneLinkCustomDomain
设置自定义域名注册品牌 OneLink 域名,以便 AppsFlyer 可以解析在短链中隐藏的属性参数。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setOneLinkCustomDomain({} as AFOnelinkDomain);appendParametersToDeepLinkingURL
设置深度链接 URL启用 App Links 深度链接的属性功能,无需 OneLink。请在调用此方法之前 startSDK()至少包含 pid 和 is_retargeting=true 在参数映射中。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.appendParametersToDeepLinkingURL({} as AFAppendToDeepLink);setResolveDeepLinkURLs
使用此方法,当 AppsFlyer OneLink 包含在另一个 Universal Link 内时它让 SDK 解析包装的 URL,因此深度链接仍然正常工作。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setResolveDeepLinkURLs({} as AFUrls);addPushNotificationDeepLinkPath
添加推送通知深度链接路径配置SDK从推送通知包中提取深度链接值的方式。
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
设置所有AppsFlyer合作伙伴的分享过滤器阻止事件传播到所有AppsFlyer合作伙伴。会覆盖setSharingFilter。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilterForAllPartners();setSharingFilterForPartners
设置指定AppsFlyer合作伙伴的分享过滤器阻止事件传播到指定的AppsFlyer合作伙伴。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilterForPartners({} as AFFilters);setAdditionalData
设置额外数据将额外的键值对数据发送到 AppsFlyer。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAdditionalData({} as AFData);getAppsFlyerUID
获取 AppsFlyer 的设备 ID(每个新安装的应用程序都会创建一个)。复制到剪贴板
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.getAppsFlyerUID();anonymizeUser
复制到剪贴板当这个 __CAPGO_KEEP_0__ 被调用时,我们的 __CAPGO_KEEP_1__ 将不再与我们的服务器通信并停止运行。 在实施用户自愿或自愿退出时有用。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.anonymizeUser({} as AFAnonymizeUser);stop
__CAPGO_KEEP_0__Once this API is invoked, our SDK no longer communicates with our servers and stops functioning. Useful when implementing user opt-in/opt-out.
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.stop();disableSKAdNetwork
Section titled “disableSKAdNetwork”SKAdNetwork 选项
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableSKAdNetwork({} as AFDisable);disableAdvertisingIdentifier
Section titled “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
生成邀请链接允许您的现有用户邀请他们的朋友和联系人作为新用户加入您的应用
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.generateInviteLink({} as AFLinkGenerator);validateAndLogInAppPurchaseAndroid
验证并登录Android应用内购买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
获取AppsFlyer SDK版本获取应用中使用的AppsFlyer SDK版本
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.getSdkVersion();enableFacebookDeferredApplinks
启用Facebook延迟应用链接Enable the collection of Facebook Deferred AppLinks. Requires Facebook SDK and Facebook app on target/client device. This API must be invoked before initializing the AppsFlyer SDK in order to function properly.
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableFacebookDeferredApplinks({} as AFFbDAL);sendPushNotificationData
复制到剪贴板Section titled “sendPushNotificationData”
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.sendPushNotificationData({} as AFPushPayload);setCurrentDeviceLanguage
复制到剪贴板Section titled “setCurrentDeviceLanguage”
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCurrentDeviceLanguage({} as AFLanguage);logCrossPromoteImpression
复制到剪贴板Section titled “logCrossPromoteImpression”
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logCrossPromoteImpression({} as AFPromotion);setUserEmails
Section titled “setUserEmails”设置用户邮箱并加密。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setUserEmails({} as AFEmails);logLocation
Section titled “logLocation”手动记录用户位置。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logLocation({} as AFLatLng);setPhoneNumber
Section titled “setPhoneNumber”将以SHA-256加密的字符串发送。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setPhoneNumber({} as AFPhone);setPartnerData
Section titled “setPartnerData”用于合作伙伴集成目的发送自定义数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setPartnerData({} as AFPartnerData);logInvite
logInvite用于记录用户邀请内应用事件(af_invite)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logInvite({} as AFLogInvite);setDisableNetworkData
setDisableNetworkData用于在设备上禁用收集网络运营商名称(carrier)和SIM卡运营商名称。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setDisableNetworkData({} as AFDisable);enableTCFDataCollection
enableTCFDataCollection用于开启/关闭自动收集用户同意数据,针对使用CMP的用户。 标志值将在应用程序会话之间持久化。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableTCFDataCollection({} as AFEnableTCFDataCollection);setConsentData
setConsentData用于手动设置用户同意数据。 如果您的应用程序不使用兼容TCF v2.2的CMP,请使用以下方法手动提供同意数据直接到SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentData({} as AFConsentData);logAdRevenue
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
是否已启动SDK使用此方法检查是否在当前会话中已启动AppsFlyerSDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.isSDKStarted();isSDKStopped
是否已停止SDK使用此方法检查AppsFlyerSDK是否当前已停止。
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);本页面由插件生成的。
重新同步公共 __CAPGO_KEEP_0__ 时,重新运行同步。 src/definitions.ts. Re-run the sync when the public API changes upstream.