开始入门
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-facebook-analytics`
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/facebook-analytics/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.
Install
Section titled “Install”bun add @capgo/capacitor-facebook-analyticsbunx cap syncImport
Section titled “Import”import { FacebookAnalytics, FacebookEventName, FacebookEventParameterName,} from '@capgo/capacitor-facebook-analytics';原生设置
原生设置在原生应用中配置您的Meta应用ID和客户端令牌。插件不会为您创建这些值。
iOS
iOS将您的Meta值添加到 Info.plist:
<key>FacebookAppID</key><string>YOUR_FACEBOOK_APP_ID</string><key>FacebookClientToken</key><string>YOUR_FACEBOOK_CLIENT_TOKEN</string><key>FacebookDisplayName</key><string>YOUR_APP_NAME</string>Android
Android将您的Meta值添加到 AndroidManifest.xml:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" /><meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token" />添加原生字符串资源 android/app/src/main/res/values/strings.xml:
<string name="facebook_app_id">YOUR_FACEBOOK_APP_ID</string><string name="facebook_client_token">YOUR_FACEBOOK_CLIENT_TOKEN</string>启用广告商跟踪
启用广告商跟踪在允许跟踪的-consent 流程之后,调用此函数。
await FacebookAnalytics.enableAdvertiserTracking();在 iOS 17 及以上版本中,FBSDK v17+ 可直接读取 App Tracking Transparency。 在登录跟踪依赖事件之前,请在您的应用中使用 ATT 流程。
记录标准事件
启用记录标准事件await FacebookAnalytics.logEvent({ event: FacebookEventName.CompletedRegistration, params: { [FacebookEventParameterName.RegistrationMethod]: 'email', },});记录带有货币的值事件
启用记录带有货币的值事件await FacebookAnalytics.logEvent({ event: FacebookEventName.AddedToCart, valueToSum: 19.99, currency: 'USD', params: { [FacebookEventParameterName.ContentType]: 'product', [FacebookEventParameterName.ContentId]: 'sku-123', },});Log A Purchase
Section titled “Log A Purchase”await FacebookAnalytics.logPurchase({ amount: 9.99, currency: 'USD',});Read Tracking Status
Section titled “Read Tracking Status”const { status } = await FacebookAnalytics.getAdvertiserTrackingStatus();console.log('Advertiser tracking enabled:', status);Source Of Truth
Section titled “Source Of Truth”This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.
Keep going from Getting Started
Section titled “Keep going from Getting Started”If you are using Getting Started 为native插件工作做好准备,连接它 使用@capgo/capacitor-facebook-analytics 在使用@capgo/capacitor-facebook-analytics时, Capgo插件目录 在Capgo插件目录中 Capacitor由Capgo提供 在Capacitor由Capgo提供时, 添加或更新插件 添加或更新插件的实现细节, Ionic企业插件替代方案 了解Ionic企业版插件替代方案的产品工作流程。