Getting Started
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
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”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen use the following prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-facebook-analytics` plugin in my project.If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
npm install @capgo/capacitor-facebook-analyticsnpx cap syncImport
Section titled “Import”import { FacebookAnalytics, FacebookEventName, FacebookEventParameterName,} from '@capgo/capacitor-facebook-analytics';Quick start
Section titled “Quick start”import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
// Initialize only after your consent or ATT flow allows analytics.if (userGrantedAnalyticsConsent) { await FacebookAnalytics.initAppEvents();}Example: logEvent
Section titled “Example: logEvent”import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
await FacebookAnalytics.logEvent({ event: "fb_mobile_complete_registration" });Example: logPurchase
Section titled “Example: logPurchase”import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
await FacebookAnalytics.logPurchase({ amount: 1, currency: "USD",});Common pitfalls
Section titled “Common pitfalls”- Native sync: run
npx cap syncafter plugin upgrades. - Source of truth: trust
src/definitions.tsin the GitHub repo.
Native Setup
Section titled “Native Setup”Configure your Meta app id and client token in the native app. The plugin does not create these values for you.
Add your Meta values to 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
Section titled “Android”Add your Meta values to 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" />Add the string resources in 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>Metadata collection and product improvement (SDK 19)
Section titled “Metadata collection and product improvement (SDK 19)”Facebook SDK 19 turns two extra collection features on by default. @capgo/capacitor-facebook-analytics does not set either flag, so apps that upgrade to the plugin’s SDK 19 pins inherit those defaults. Both features are independent of automatic App Event logging. Setting com.facebook.sdk.AutoLogAppEventsEnabled or FacebookAutoLogAppEventsEnabled to false does not turn them off.
Event metadata (AutoLogMetaDataEnabled)
Section titled “Event metadata (AutoLogMetaDataEnabled)”Starting on 31 October 2026, the SDK includes the current screen title and the AppLink URL with events logged through the Facebook SDK. This is on by default. Disable it with the snippets below, or turn off “Automatically include more app event details” in Events Manager.
Product improvement (AutoLogProductImprovementEnabled)
Section titled “Product improvement (AutoLogProductImprovementEnabled)”The SDK can also automatically send sampled information about your app, such as the layout of elements on app screens. Meta says this helps improve ads systems and build new features, and is not used for ads delivery. This is on by default and is independent of metadata collection and automatic App Event logging. Disable it with the snippets below, or turn off “Automatically send more app information” in Events Manager.
Set the Android manifest and iOS Info.plist values before Meta SDK initialization (before FacebookInitProvider on Android or early FBSDK setup on iOS). Runtime assignments are persisted and take precedence over the manifest or Info.plist values on later launches.
Android opt-out
Section titled “Android opt-out”Add these entries inside the application element of your app AndroidManifest.xml:
<meta-data android:name="com.facebook.sdk.AutoLogMetaDataEnabled" android:value="false" /><meta-data android:name="com.facebook.sdk.AutoLogProductImprovementEnabled" android:value="false" />At runtime, you can also call FacebookSdk.setAutoLogMetaDataEnabled(false) and FacebookSdk.setAutoLogProductImprovementEnabled(false) before initialization.
iOS opt-out
Section titled “iOS opt-out”Add these keys to Info.plist:
<key>FBSDKAutoLogMetaDataEnabled</key><false/><key>FBSDKAutoLogProductImprovementEnabled</key><false/>After Meta SDK initialization, set Settings.shared.isMetaDataCollectionEnabled = false and Settings.shared.isAutoLogProductImprovementEnabled = false to change the values at runtime. A previously persisted value takes precedence over Info.plist until you change it at runtime.
Setting the metadata flag to false clears cached metadata on the device, including the stored screen title and AppLink URLs. Metadata already attached to queued events may still be sent after the flag is disabled. Collection requires both the client flag and the server-side Events Manager control to be enabled.
Enable Advertiser Tracking
Section titled “Enable Advertiser Tracking”Call this after your consent flow allows tracking.
await FacebookAnalytics.enableAdvertiserTracking();On iOS 17 and above, FBSDK v17+ reads App Tracking Transparency directly. Use your app’s ATT flow before logging tracking-dependent events.
Log A Standard Event
Section titled “Log A Standard Event”await FacebookAnalytics.logEvent({ event: FacebookEventName.CompletedRegistration, params: { [FacebookEventParameterName.RegistrationMethod]: 'email', },});Log A Value Event With Currency
Section titled “Log A Value Event With Currency”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 to plan native plugin work, connect it with Using @capgo/capacitor-facebook-analytics for the native capability in Using @capgo/capacitor-facebook-analytics, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins, and Ionic Enterprise Plugin Alternatives for the product workflow in Ionic Enterprise Plugin Alternatives.