快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
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.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-appsflyer` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-appsflyernpx 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';快速入门
章节标题为“快速入门”import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.initSDK({ devKey: 'dev-key-123', appID: 'app-id-123',});console.log(result);示例:startSDK
章节标题:“示例:startSDK”import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.startSDK();console.log(result);示例:logEvent
标题为“示例:logEvent”的章节import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logEvent({ eventName: 'event' });console.log(result);常见坑点
章节标题为“常见陷阱”- 监听器: 在页面卸载时移除句柄。
- 原生同步:运行
npx cap sync在插件升级后。 - 唯一可信来源:信任
src/definitions.ts在 GitHub 仓库中。
API 概览
章节标题:“API 概览”initSDK
“initSDK” 章节使用此方法来初始化并启动 AppsFlyer SDK。应当在应用启动时立即调用此 API。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.initSDK({ devKey: 'dev-key-123', appID: 'app-id-123',});console.log(result);startSDK
“startSDK” 章节仅在手动启动模式下,使用此方法启动 AppsFlyer SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.startSDK();console.log(result);logEvent
标题为“logEvent”的章节记录一个 App 内事件。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logEvent({ eventName: 'event' });console.log(result);setCustomerUserId
“setCustomerUserId”章节设置你自己的 customer ID 后,就能将自己的唯一 ID 与 AppsFlyer 的唯一 ID 以及其他设备的 ID 进行交叉比对。 该 ID 会出现在原始数据报告和 Postback API 中,可用于与你的内部 ID 交叉比对。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCustomerUserId({ cuid: 'cuid' });setCurrencyCode
“setCurrencyCode”章节设置应用内购买使用的货币。请提供三位字符的 ISO 4217 code。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCurrencyCode({ currencyCode: 'USD' });updateServerUninstallToken
“updateServerUninstallToken”章节当其他插件已收集这些 token 时,在 Android 上传递 GCM/FCM token,在 iOS 上传递 APNs token。 使用此方法将卸载测量 token 转发给 AppsFlyer。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.updateServerUninstallToken({ token: 'token-123' });setAppInviteOneLink
“setAppInviteOneLink”章节设置用作邀请归因基础链接的 OneLink ID。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAppInviteOneLink({ onelinkID: 'onelink-id-123' });setOneLinkCustomDomain
“setOneLinkCustomDomain” 章节注册品牌 OneLink 域名,以便 AppsFlyer 解析隐藏在短链接中的归因参数。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setOneLinkCustomDomain({ domains: ['example.com'] });appendParametersToDeepLinkingURL
“appendParametersToDeepLinkingURL” 章节为不使用 OneLink 的 App Links deep link 启用归因。请在此之前调用此方法 startSDK().
至少包含 pid 以及 is_retargeting=true 在参数 map 中。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.appendParametersToDeepLinkingURL({ contains: 'contains', parameters: {},});setResolveDeepLinkURLs
“setResolveDeepLinkURLs” 章节当 AppsFlyer OneLink 被包裹在另一个 Universal Link 中时使用。 它让 SDK 能解析被包裹的 URL,从而保证 deep linking 仍能正常工作。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setResolveDeepLinkURLs({ urls: ['https://example.com'] });addPushNotificationDeepLinkPath
“addPushNotificationDeepLinkPath” 章节配置 SDK 如何从推送通知 payload 中提取 deep link 值。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.addPushNotificationDeepLinkPath({ path: ['path/to/file'] });setSharingFilter
“setSharingFilter” 章节阻止事件传播到指定的 AppsFlyer 合作伙伴。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setSharingFilter({ filters: ['filter'] });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({ filters: ['filter'] });setAdditionalData
“setAdditionalData” 章节设置要发送给 AppsFlyer 的额外键值数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAdditionalData({ additionalData: {} });getAppsFlyerUID
“getAppsFlyerUID” 章节获取 AppsFlyer 的唯一设备 ID(每次新安装应用时创建)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.getAppsFlyerUID();console.log(result);anonymizeUser
“anonymizeUser” 章节终端用户选择退出 AppsFlyer 分析(匿名化用户数据)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.anonymizeUser({ anonymizeUser: true });stop
标题为“stop”的章节一旦调用此 API,我们的 SDK 将不再与服务器通信并停止工作。 适用于实现用户选择加入/退出(opt-in/opt-out)功能。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.stop();console.log(result);disableSKAdNetwork
“disableSKAdNetwork” 章节退出 SKAdNetwork
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableSKAdNetwork({ shouldDisable: true });disableAdvertisingIdentifier
“disableAdvertisingIdentifier” 章节禁用 SDK 对各类广告 ID 的收集,包括 Apple 广告标识符 (IDFA)、Google 广告 ID (GAID)、OAID 和 Amazon 广告 ID (AAID)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableAdvertisingIdentifier({ shouldDisable: true });disableCollectASA
“disableCollectASA” 章节选择退出 Apple Search Ads 归因。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableCollectASA({ shouldDisable: true });setHost
“setHost” 章节设置自定义 host。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setHost({ hostPrefixName: 'host-prefix', hostName: 'host',});generateInviteLink
“generateInviteLink” 章节允许现有用户邀请好友及联系人加入您的应用
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.generateInviteLink({ brandDomain: 'example.com' });console.log(result);validateAndLogInAppPurchaseAndroid
“validateAndLogInAppPurchaseAndroid” 章节用于应用内购买服务器验证的 API。验证成功后,会自动记录带有相关值的 af_purchase 事件。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.validateAndLogInAppPurchaseAndroid({ currency: 'USD', publicKey: 'public-key-123', signature: 'signature', purchaseData: 'purchase-data', price: 'price',});console.log(result);validateAndLogInAppPurchaseIos
“validateAndLogInAppPurchaseIos” 章节查看当前契约的源码定义。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.validateAndLogInAppPurchaseIos({ currency: 'USD', inAppPurchase: 'in-app-purchase', price: 'price', transactionId: 'transaction-id-123',});console.log(result);getSdkVersion
“getSdkVersion” 章节获取 App 中使用的 AppsFlyer SDK 版本。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.getSdkVersion();console.log(result);enableFacebookDeferredApplinks
“enableFacebookDeferredApplinks” 章节启用 Facebook Deferred AppLinks 数据采集。需要目标/客户端设备安装 Facebook SDK 和 Facebook App。 必须在初始化 AppsFlyer SDK 之前调用此 API 才能正常工作。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.enableFacebookDeferredApplinks({ enableFacebookDAL: true });console.log(result);sendPushNotificationData
“sendPushNotificationData” 章节衡量并获取推送通知营销活动的数据。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.sendPushNotificationData({ pushPayload: {} });setCurrentDeviceLanguage
“setCurrentDeviceLanguage” 章节设置设备语言。该数据将显示在 Raw Data Reports 中
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setCurrentDeviceLanguage({ language: 'en-US' });console.log(result);logCrossPromoteImpression
“logCrossPromoteImpression” 章节记录交叉推广活动中的曝光 (impression)。请确保使用 AppsFlyer dashboard 中显示的推广 App ID。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logCrossPromoteImpression({ appID: 'app-id-123', campaign: 'campaign', parameters: {},});console.log(result);setUserEmails
“setUserEmails” 章节设置用户邮箱并进行加密。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setUserEmails({ emails: ['user@example.com'] });console.log(result);logLocation
“logLocation” 章节手动记录用户位置
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logLocation({ latitude: 48.8566, longitude: 2.3522,});console.log(result);setPhoneNumber
“setPhoneNumber” 章节将以 SHA-256 加密字符串的形式发送。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setPhoneNumber({ phone: '+15555550123' });console.log(result);setPartnerData
“setPartnerData” 章节允许发送自定义数据以用于合作伙伴集成。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setPartnerData({ data: {}, partnerId: 'partner-id-123',});console.log(result);logInvite
“logInvite” 章节用于记录应用内用户邀请事件 (af_invite)。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logInvite({ eventParameters: {}, channel: 'channel',});console.log(result);setDisableNetworkData
“setDisableNetworkData” 章节用于选择不从设备中收集网络运营商名称 (carrier) 和 SIM 卡运营商名称。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setDisableNetworkData({ shouldDisable: true });enableTCFDataCollection
“enableTCFDataCollection” 章节用于针对使用 CMP 的用户,选择开启或关闭同意数据 (consent data) 的自动收集。 该 Flag 值将在不同应用会话间持久化。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableTCFDataCollection({ shouldEnableTCFDataCollection: true });setConsentData
“setConsentData” 章节使用此方法手动设置用户同意数据。 如果你的应用没有使用兼容 TCF v2.2 的 CMP,请使用以下方法将同意数据直接手动提供给 SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentData({ data: { isUserSubjectToGDPR: true } });logAdRevenue
标题为 “logAdRevenue” 的章节通过归因广告收入,应用所有者可以全面掌握用户 LTV 和广告活动 ROI。 广告收入来自在应用内展示激励视频、积分墙、插屏广告和横幅广告。 你可以使用此方法记录广告收入。
import { AppsFlyer, MediationNetwork } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logAdRevenue({ monetizationNetwork: 'monetization-network', mediationNetwork: MediationNetwork.IRONSOURCE, currencyIso4217Code: 'USD', revenue: 1,});setConsentDataV2
标题为 “setConsentDataV2” 的章节使用此方法手动设置用户同意数据。 如果你的应用没有使用兼容 TCF v2.2 的 CMP,请使用以下方法将同意数据直接手动提供给 SDK。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentDataV2({ isUserSubjectToGDPR: true, hasConsentForDataUsage: true, hasConsentForAdsPersonalization: true, hasConsentForAdStorage: true,});isSDKStarted
标题为 “isSDKStarted” 的章节使用此方法检查 AppsFlyer SDK 是否已在当前会话中启动。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.isSDKStarted();console.log(result);isSDKStopped
标题为 “isSDKStopped” 的章节使用此方法检查 AppsFlyer SDK 当前是否已停止。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.isSDKStopped();console.log(result);disableAppSetId
标题为 “disableAppSetId” 的章节禁用 AppSet ID 收集。如果在此之前调用 SDK 初始化,则不会收集 App Set ID。 如果在此之后调用,则会收集 App Set ID,但不会将其包含在请求负载中。 仅限 Android。
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableAppSetId();validateAndLogInAppPurchaseV2
标题为 “validateAndLogInAppPurchaseV2” 的章节用于应用内购买 V2 服务端验证的 API。 如果验证成功,系统会自动记录带有相关值的 af_purchase 事件。
import { AppsFlyer, AFPurchaseType } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.validateAndLogInAppPurchaseV2({ purchaseDetails: { purchaseType: AFPurchaseType.oneTimePurchase, purchaseToken: 'purchase-token-123', productId: 'product-id-123', },});console.log(result);单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-appsflyer 用于“使用 @capgo/capacitor-appsflyer”中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。