adjust-icon

Facebook pixel

A Facebook pixel is a web-only analytics tool from Facebook. As of v4.34 of the Facebook SDK, you can record pixel events in an app’s webview. You can also convert Facebook Pixel events into Facebook App events. To do this, use Hybrid Mobile App Events.

It’s also now possible to use a Facebook pixel with the Adjust SDK, without integrating the Facebook SDK.

Example app

Facebook integration

Facebook App ID

To start working with Facebook pixels, follow the steps below:

As described in Facebook’s Android SDK guide you will need to add your Facebook App ID to the app by doing the following:

  1. Add a new string with the name facebook_app_id. Add your Facebook App ID as the value.

  2. Open your strings.xml file. Example path: /app/src/main/res/values/strings.xml.

  3. Open AndroidManifest.xml.

  4. Add a uses-permission element to the manifest:

    AndroidManifest.xml
    <uses-permission android:name="android.permission.INTERNET"/>
  5. Add a meta-data element to the application element:

    AndroidManifest.xml
    <application android:label="@string/app_name" ...>
    ...
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    ...
    </application>

Facebook pixel configuration

Follow Facebook’s guide on how to integrate the Facebook pixel. The Javascript code should look something like this:

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
...
fbq('init', {YOUR_PIXEL_ID});
fbq('track', 'PageView');
</script>
...
<!-- End Facebook Pixel Code -->

Next, update your Facebook pixel code. You can find the instructions in the Hybrid Mobile App Events guide under Update Your Pixel.

<script>
!function(f,b,e,v,n,t,s)
...
fbq('init', {YOUR_PIXEL_ID});
fbq('set', 'mobileBridge', {YOUR_PIXEL_ID}, {YOUR_FB_APP_ID});
</script>

Adjust SDK integration

Augment the web view

Follow the integration guide for Android web view apps. Add a call to the augmentHybridWebView method when loading the Web View bridge.

AdjustBridge.registerAndGetInstance(getApplication(), webview);

When you reach this step, save the returned instance as something like adjustBridgeInstance. You can then use this to register the Facebook interface like so:

adjustBridgeInstance.registerFacebookSDKJSInterface();

Event name registration

The Adjust web bridge SDK translates Facebook pixel events into Adjust events.

To use this feature, you need to map Facebook pixels to specific Adjust events. You can also configure a default Adjust event token. To use a default token, you need to add the token before starting the Adjust SDK and recording any pixel event. This includes the copy-pasted fbq('track', 'PageView'); event from the Facebook pixel configuration.

To map events, call the addFbPixelMapping method on your config instance. Use the Facebook event name and Adjust event token as parameters. You need to call this before you initialize the Adjust SDK.

adjustConfig.addFbPixelMapping("fb_mobile_search", adjustEventTokenForSearch);
adjustConfig.addFbPixelMapping(
"fb_mobile_purchase",
adjustEventTokenForPurchase,
);
Pixel event nameFacebook app event name
ViewContentfb_mobile_content_view
Searchfb_mobile_search
AddToCartfb_mobile_add_to_cart
AddToWishlistfb_mobile_add_to_wishlistt
InitiateCheckoutfb_mobile_initiated_checkout
AddPaymentInfofb_mobile_add_payment_info
Purchasefb_mobile_purchase
CompleteRegistrationfb_mobile_complete_registration

The Adjust SDK logs warnings if it can’t find a default event token for certain events.

There is not a default event token configured or a mapping found for event named: 'fb_mobile_search'. It won't be tracked as an adjust event.

You can also set a default Adjust event if you don’t have mapping configured. To do this, call adjustConfig.setFbPixelDefaultEventToken(defaultEventToken); before initializing the Adjust SDK.