Skip to content

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Terminal window
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Then 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:

Terminal window
npm install @capgo/capacitor-facebook-analytics
npx cap sync
import {
FacebookAnalytics,
FacebookEventName,
FacebookEventParameterName,
} from '@capgo/capacitor-facebook-analytics';
import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
// Initialize only after your consent or ATT flow allows analytics.
if (userGrantedAnalyticsConsent) {
await FacebookAnalytics.initAppEvents();
}
import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
await FacebookAnalytics.logEvent({ event: "fb_mobile_complete_registration" });
import { FacebookAnalytics } from '@capgo/capacitor-facebook-analytics';
await FacebookAnalytics.logPurchase({
amount: 1,
currency: "USD",
});
  • Native sync: run npx cap sync after plugin upgrades.
  • Source of truth: trust src/definitions.ts in the GitHub repo.

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>

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.

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.

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.

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.

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.

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',
},
});
await FacebookAnalytics.logPurchase({
amount: 9.99,
currency: 'USD',
});
const { status } = await FacebookAnalytics.getAdvertiserTrackingStatus();
console.log('Advertiser tracking enabled:', status);

This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.

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.