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
bun add @capgo/capacitor-facebook-analytics
bunx cap sync
import {
FacebookAnalytics,
FacebookEventName,
FacebookEventParameterName,
} from '@capgo/capacitor-facebook-analytics';

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>

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.