跳转到正文

快速入门

GitHub

你可以使用我们的 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-appsflyer
npx 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);
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.startSDK();
console.log(result);
import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logEvent({ eventName: 'event' });
console.log(result);
  • 监听器: 在页面卸载时移除句柄。
  • 原生同步:运行 npx cap sync 在插件升级后。
  • 唯一可信来源:信任 src/definitions.ts 在 GitHub 仓库中。

使用此方法来初始化并启动 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);

仅在手动启动模式下,使用此方法启动 AppsFlyer SDK。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.startSDK();
console.log(result);

记录一个 App 内事件。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logEvent({ eventName: 'event' });
console.log(result);

设置你自己的 customer ID 后,就能将自己的唯一 ID 与 AppsFlyer 的唯一 ID 以及其他设备的 ID 进行交叉比对。 该 ID 会出现在原始数据报告和 Postback API 中,可用于与你的内部 ID 交叉比对。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setCustomerUserId({ cuid: 'cuid' });

设置应用内购买使用的货币。请提供三位字符的 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' });

设置用作邀请归因基础链接的 OneLink ID。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAppInviteOneLink({ onelinkID: 'onelink-id-123' });

注册品牌 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: {},
});

当 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'] });

阻止事件传播到指定的 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'] });

设置要发送给 AppsFlyer 的额外键值数据。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setAdditionalData({ additionalData: {} });

获取 AppsFlyer 的唯一设备 ID(每次新安装应用时创建)。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.getAppsFlyerUID();
console.log(result);

终端用户选择退出 AppsFlyer 分析(匿名化用户数据)。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.anonymizeUser({ anonymizeUser: true });

一旦调用此 API,我们的 SDK 将不再与服务器通信并停止工作。 适用于实现用户选择加入/退出(opt-in/opt-out)功能。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.stop();
console.log(result);

退出 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 });

选择退出 Apple Search Ads 归因。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableCollectASA({ shouldDisable: true });

设置自定义 host。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setHost({
hostPrefixName: 'host-prefix',
hostName: 'host',
});

允许现有用户邀请好友及联系人加入您的应用

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);

获取 App 中使用的 AppsFlyer SDK 版本。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.getSdkVersion();
console.log(result);
“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);

衡量并获取推送通知营销活动的数据。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.sendPushNotificationData({ pushPayload: {} });

设置设备语言。该数据将显示在 Raw Data Reports 中

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setCurrentDeviceLanguage({ language: 'en-US' });
console.log(result);

记录交叉推广活动中的曝光 (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);

设置用户邮箱并进行加密。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setUserEmails({ emails: ['user@example.com'] });
console.log(result);

手动记录用户位置

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logLocation({
latitude: 48.8566,
longitude: 2.3522,
});
console.log(result);

将以 SHA-256 加密字符串的形式发送。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setPhoneNumber({ phone: '+15555550123' });
console.log(result);

允许发送自定义数据以用于合作伙伴集成。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.setPartnerData({
data: {},
partnerId: 'partner-id-123',
});
console.log(result);

用于记录应用内用户邀请事件 (af_invite)。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.logInvite({
eventParameters: {},
channel: 'channel',
});
console.log(result);

用于选择不从设备中收集网络运营商名称 (carrier) 和 SIM 卡运营商名称。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setDisableNetworkData({ shouldDisable: true });

用于针对使用 CMP 的用户,选择开启或关闭同意数据 (consent data) 的自动收集。 该 Flag 值将在不同应用会话间持久化。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.enableTCFDataCollection({ shouldEnableTCFDataCollection: true });

使用此方法手动设置用户同意数据。 如果你的应用没有使用兼容 TCF v2.2 的 CMP,请使用以下方法将同意数据直接手动提供给 SDK。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentData({ data: { isUserSubjectToGDPR: true } });

通过归因广告收入,应用所有者可以全面掌握用户 LTV 和广告活动 ROI。 广告收入来自在应用内展示激励视频、积分墙、插屏广告和横幅广告。 你可以使用此方法记录广告收入。

import { AppsFlyer, MediationNetwork } from '@capgo/capacitor-appsflyer';
await AppsFlyer.logAdRevenue({
monetizationNetwork: 'monetization-network',
mediationNetwork: MediationNetwork.IRONSOURCE,
currencyIso4217Code: 'USD',
revenue: 1,
});

使用此方法手动设置用户同意数据。 如果你的应用没有使用兼容 TCF v2.2 的 CMP,请使用以下方法将同意数据直接手动提供给 SDK。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.setConsentDataV2({
isUserSubjectToGDPR: true,
hasConsentForDataUsage: true,
hasConsentForAdsPersonalization: true,
hasConsentForAdStorage: true,
});

使用此方法检查 AppsFlyer SDK 是否已在当前会话中启动。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.isSDKStarted();
console.log(result);

使用此方法检查 AppsFlyer SDK 当前是否已停止。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
const result = await AppsFlyer.isSDKStopped();
console.log(result);

禁用 AppSet ID 收集。如果在此之前调用 SDK 初始化,则不会收集 App Set ID。 如果在此之后调用,则会收集 App Set ID,但不会将其包含在请求负载中。 仅限 Android。

import { AppsFlyer } from '@capgo/capacitor-appsflyer';
await AppsFlyer.disableAppSetId();

用于应用内购买 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 的实现细节。