Facebook App Events is Facebook's event tracking functionality which lets you track events via your app or web page, including user activities such as app installation, purchases, etc.

RudderStack supports Facebook App Events as a destination to which you can send your event data seamlessly.

Find the open source transformer code for this destination in the GitHub repository.

Getting started

Before configuring App Events as a destination in RudderStack, verify if the source platform is supported by App Events by referring to the table below:

Connection ModeWebMobileServer
Device mode-Supported-
Cloud modeSupportedSupported-
To learn more about the difference between cloud mode and device mode in RudderStack, refer to the RudderStack Connection Modes guide.

Once you have confirmed that the source supports sending events to Facebook App Events, follow these steps:

  1. From your RudderStack dashboard, add the source. From the list of destinations, select Facebook App Events.
  2. Assign a name to the destination and click Continue.

Connection settings

To successfully configure Facebook App Events as a destination, you will need to configure the following settings:

fb app events connection settings fb app events connection settings 2
  • APP ID: Enter your Facebook App ID.
Refer to the FAQ section for more information on getting your Facebook App ID.

The following settings are applicable only if you are sending events to Facebook using the device mode:

  • Limited Data Use: Enable this option to send the country and state of the end-user. Facebook processes the user data according to the data regulations set for that region.
For more information on this option, refer to the Limited Data Use section below.
  • Client-side Events Filtering: This setting lets you specify which events should be blocked or allowed to flow through to Facebook App Events.
For more information on this setting, refer to the Client-side Events Filtering guide.

Adding device mode integration

Depending on your platform of integration, follow the below steps below to integrate App Events with your app.

To add Facebook to your iOS project:
  1. Add the following line to your CocoaPods Podfile :
    pod 'Rudder-Facebook'
  2. Initialize the Facebook App Events iOS SDK just before intializing the RudderStack iOS SDK as shown:
    [[FBSDKApplicationDelegate sharedInstance] application:application
    didFinishLaunchingWithOptions:launchOptions];
  3. Send the user's consent to App Events as shown below:
    1. For Objective-C:
      // Set AdvertiserTrackingEnabled to YES if a user provides consent
      [FBSDKSettings setAdvertiserTrackingEnabled:YES];
      // Set AdvertiserTrackingEnabled to NO if a user does not provide consent
      [FBSDKSettings setAdvertiserTrackingEnabled:NO];
    2. For Swift:
      // Set AdvertiserTrackingEnabled to true if a user provides consent
      Settings.setAdvertiserTrackingEnabled(true)
      // Set AdvertiserTrackingEnabled to false if a user does not provide consent
      Settings.setAdvertiserTrackingEnabled(false)
  4. Configure your project by adding the following lines to (...) in your Info.plist :
    <key>CFBundleURLTypes</key>
    <array>
    <dict>
    <key>CFBundleURLSchemes</key>
    <array>
    <string>fbAPP-ID</string>
    </array>
    </dict>
    </array>
    <key>FacebookAppID</key>
    <string>APP-ID</string>
    <key>FacebookClientToken</key>
    <string>CLIENT-TOKEN</string>
    <key>FacebookDisplayName</key>
    <string>APP-NAME</string>
    Make sure you replace fbAPP-ID , APP-ID, CLIENT-TOKEN, APP-NAME with the app-specific details from the Facebook for Developers platform.
  5. After adding the dependency, register the RudderFacebookFactory with your RudderClient initialization as a factory of RudderConfig. To do this, run the following command to import the RudderFacebookFactory.h file in your AppDelegate.m file:
    #import <Rudder-Facebook/RudderFacebookFactory.h>
  6. Then, add the RudderStack iOS SDK initialization as shown:
    RSConfigBuilder *builder = [[RSConfigBuilder alloc] init];
    [builder withDataPlaneUrl:DATA_PLANE_URL];
    [builder withFactory:[RudderFacebookFactory instance]];
    [RSClient getInstance:WRITE_KEY config:[builder build]];
This device mode integration is supported for Facebook App Events 13.0.0 and above.
Follow these steps to add Facebook App Events to your iOS project:
  1. Install RudderFacebookAppEvents (available through CocoaPods) by adding the following line to your Podfile:
    pod 'RudderFacebookAppEvents', '~> 1.0.0'
  2. Run the pod install command.
  3. Then, import the SDK depending on your preferred platform:
    import RudderFacebookAppEvents
    @import RudderFacebookAppEvents;
  4. Next, add the imports to your AppDelegate file under the didFinishLaunchingWithOptions method, as shown:

    let config: RSConfig = RSConfig(writeKey: WRITE_KEY)
    .dataPlaneURL(DATA_PLANE_URL)
    RSClient.sharedInstance().configure(with: config)
    RSClient.sharedInstance().addDestination(RudderFacebookAppEventsDestination())
    RSConfig *config = [[RSConfig alloc] initWithWriteKey:WRITE_KEY];
    [config dataPlaneURL:DATA_PLANE_URL];
    [[RSClient sharedInstance] configureWith:config];
    [[RSClient sharedInstance] addDestination:[[RudderFacebookAppEventsDestination alloc] init]];
To add Facebook App Events to your Android project, follow these steps:
  1. Add the repository, as shown:
    repositories {
    mavenCentral()
    }
  2. Add the following lines to your app/build.gradle file under the dependencies section, as shown:
    implementation 'com.rudderstack.android.sdk:core:1.+'
    implementation 'com.rudderstack.android.integration:facebook:1.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:11.1.0'
  3. Open your /app/res/values/strings.xml file and add the following lines. **Remember to replace [APP_ID] with your actual app ID**.
    <string name="facebook_app_id">[APP_ID]</string>
    <string name="fb_login_protocol_scheme">fb[APP_ID]</string>
  4. In the app/manifests/AndroidManifest.xmlfile, add a meta-data element to the application element as shown:
  5. Finally, change the initialization of your RudderClient in your Application class, as shown:
    val rudderClient = RudderClient.getInstance(
    this,
    WRITE_KEY,
    RudderConfig.Builder()
    .withDataPlaneUrl(DATA_PLANE_URL)
    .withFactory(FacebookIntegrationFactory.FACTORY)
    .build()
    )

Identify

For Facebook App Events, RudderStack supports the identify calls only in the mobile device mode.

You can use the identify call to set the userId through the setUserID method from AppEventsLogger.

RudderStack sets the following properties (if available) using the setUserData method.

  • email
  • firstName
  • lastName
  • phone
  • birthday
  • gender
  • city
  • state
  • zip
  • country

A sample identify call for an iOS application is shown below:

[[RSClient sharedInstance] identify:@"developer_user_id"
traits:@{@"email": @"bar@foo.com"}];

Track

RudderStack logs the track call to Facebook using the logEvent method of the AppEventsLogger class. It uses the same eventName as you have passed in the track call along with all the properties, after converting them into the accepted format.

A sample track call for an iOS application is as shown:.

[[RSClient sharedInstance] track:@"Accepted Terms of Service"
properties:@{
@"foo": @"bar",
@"foo_int": @134
}];
When revenue and currency are present in the event properties of any track call, RudderStack makes a Purchase call to Facebook using its logPurchase API along with the normal track call using the logEvent API.

If currency is absent in the event properties, RudderStack sets the default value to USD.

Supported mappings for iOS v2

This section lists some track event and property mappings which are applicable only when sending events via the iOS v2 device mode.

The following table lists the track event properties mappings between RudderStack and Facebook App Events:

RudderStack propertyFacebook App Events property
product_idContentID
ratingMaxRatingValue
nameAdType
order_idOrderID
currencyCurrency
queryQuery
descriptionDescription

The following table lists the ecommerce events mappings between RudderStack and Facebook App Events:

RudderStack eventFacebook App Events event
Products SearchedSearch
Products ViewedView Content
Product AddedAdd to Cart
Product Added To WishlistAdd to Wishlist
Payment Info EnteredAdd Payment Info
Checkout StartedInitiate Checkout
Order CompletedPurchase
Promotion ClickedIn-App Ad Click
Promotion ViewedIn-App Ad Impression
Product ReviewedRate
Spend CreditsSpent Credits

RudderStack also supports the following Lifecycle events and maps them as it is before sending them to Facebook App Events:

  • Complete Registration
  • Achieve Level
  • Complete Tutorial
  • Unlock Achievement
  • Subscribe
  • Start Trial

Page

The page method lets you record your website's page views with any additional relevant information about the viewed page. You need not pass the event name as RudderStack automatically sets it to Viewed Page.

A sample page call using the RudderStack Android SDK is as shown:

rudderanalytics.page();
The page call is directly passed on to Facebook as a track event via its logEvent API, with the event name as Viewed Page along with the the associated properties.

Screen

The screen call lets you record whenever your user views their mobile screen, with any additional relevant information about the screen.

A sample screen call using the RudderStack Android SDK is as shown:

[[RSClient sharedInstance] screen:@"Home" properties:@{
@"category" : @"launcher"
}];

In the above snippet, RudderStack captures the information related to the viewed screen, such as screen name and category.

The above screen call is directly passed on to Facebook as a track event via its logEvent API, with the event name as Viewed {screen name} screen along with the the associated properties. The above example will be sent as a track event with name Viewed Home screen along with its properties.

Limited Data Use

In July 2020, Facebook released a Limited Data Use feature to give businesses better control over how their data is used in their California Consumer Privacy Act (CCPA) compliance efforts.

Using this, you can send the Limited Data Use data processing parameters to Facebook for each event via RudderStack, so that Facebook can appropriately apply the user’s data choice.

To use this feature, enable the Limited Data Use setting in the RudderStack dashboard and control its behavior via the following data processing parameters:

ParameterDefault ValueDescription
Data Processing Options State0Use Facebook’s geolocation to determine the end-user's state.
Data Processing Options Country0Use Facebook’s geolocation to determine the end-user's country.
Learn more about the different data processing options accepted by Facebook.

This section highlights the different consent-based options for configuring the App Events SDK.

Disable Automatically Logged Events

  • To disable automatic event logging, open the application's .plist as code in Xcode and add the following XML to the property dictionary:
    <key>FacebookAutoLogAppEventsEnabled</key>
    <false/>
  • In some cases, you can delay the collection of automatically logged events to obtain user consent or fulfill legal obligations instead of disabling it entirely. To do so, call the setAutoLogAppEventsEnabled method of the FBSDKSettings class to re-enable auto-logging after the end-user provides the required consent.
    • In Objective-C:
      [FBSDKSettings setAutoLogAppEventsEnabled:YES];
    • In Swift:
      FBSDKSettings.setAutoLogAppEventsEnabled(true)
  • To suspend event collection for any reason, set the setAutoLogAppEventsEnabled method to NO for iOS or false for Swift, as shown:
    • In Objective-C:
      [FBSDKSettings setAutoLogAppEventsEnabled:NO];
    • In Swift:
      FBSDKSettings.setAutoLogAppEventsEnabled(false)
  • To disable automatically logged events, add the following to your AndroidManifest.xml file:
  • In some cases, you can delay the collection of automatically logged events to obtain user consent or fulfill legal obligations instead of disabling it entirely. To do so, call the setAutoLogAppEventsEnabled() method of the FacebookSDK class and set it to true . This re-enables event logging after the end-user has provided the required consent.
    setAutoLogAppEventsEnabled(true);
  • To suspend event logging again for any reason, set the setAutoLogAppEventsEnabled() method to false, as shown:
    setAutoLogAppEventsEnabled(false);

Disable Collection of Advertiser IDs

  • To disable the collection of advertiser ID, open the application's .plist as code in Xcode and add the following XML to the property dictionary:
    <key>FacebookAdvertiserIDCollectionEnabled</key>
    <false/>
  • In some cases, you can delay the collection of advertiser_id to obtain the user consent or fulfill any legal obligations instead of disabling it entirely. To do so, call the setAdvertiserIDCollectionEnabled method of the FBSDKSettings class and set it to YES for iOS, or true for Swift after the end-user provides consent, as shown:
    • In Objective-C:
      [FBSDKSettings setAdvertiserIDCollectionEnabled:@YES];
    • In Swift:
      FBSDKSettings.setAdvertiserIDCollectionEnabled(true);
  • To suspend collection for any reason, set the setAdvertiserIDCollectionEnabled method to NO for iOS or false for Swift.
    • In Objective-C:
      [FBSDKSettings setAdvertiserIDCollectionEnabled:@NO];
    • In Swift:
      FBSDKSettings.setAdvertiserIDCollectionEnabled(false)
  • To disable collection of advertiser-id, add the following code to your AndroidManifest.xml file:
    <application>
    ...
    <meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled"
    android:value="false"/>
    ...
    </application>
  • In some cases, you can delay the collection of advertiser_id to obtain user consent or fulfill any legal obligations instead of disabling it entirely. To do so, call the setAdvertiserIDCollectionEnabled() method of the FacebookSDK class and set it to true . This re-enables the collection of advertiser_id after the end-user provides the required consent, as shown:
    setAdvertiserIDCollectionEnabled(true);
  • To suspend collection for any reason, set the setAdvertiserIDCollectionEnabled() method to false, as shown:
    setAdvertiserIDCollectionEnabled(false)

Disable Automatic SDK Initialization

To disable automatic SDK initialization in case of the Android SDK, add the following to your AndroidManifest.xml file:
<application>
...
<meta-data androidName="com.facebook.sdk.AutoInitEnabled"
androidValue="false"/>
...
</application>
In some cases, you can delay the SDK initialization to obtain user consent or fulfill any legal obligations instead of disabling it entirely. To do so, call the class method setAutoInitEnabled and set it to true to manually initialize the SDK after the end-user provides the required consent.
FacebookSdk.setAutoInitEnabled(true)
FacebookSdk.fullyInitialize()
Starting from iOS version 14.5, you need to get the device consent to share data with Facebook by setting the isAdvertiserTrackingEnabled property. Refer to Facebook's Get device consent documentation for more information.

FAQ

Where do I get the Facebook App ID?

You can find the Facebook App ID by logging into your Facebook Developer account, and navigating to the Home page of your application's dashboard, as shown:

fb app events app id

Where do I get the Facebook Client Token?

You can find the Facebook Client Token by logging into your Facebook Developer account and navigating to Settings > Advanced > Security section in the application's dashboard, as shown:

fb app events client token

Contact us

For more information on the topics covered on this page, email us or start a conversation in our Slack community.