Meta pixel integration

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

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

Before you begin

Availability

You need to download and set up the Adjust SDK for your platform. Follow the instructions linked below to get started.

⚙️ iOS / Android

Example apps

Meta integration

Meta App ID

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

iOS Web View
Android Web View

As described in Meta's iOS SDK guide you will need to add your Meta App ID to the app by doing the following:

  1. In Xcode, right click on your project's Info.plist file and select Open As -> Source Code.
  2. Insert the following XML snippet into the body of your file just before the final </dict> element:
<dict>
  ...
  <key>FacebookAppID</key>
  <string>{your-app-id}</string>
  ...
</dict>

Replace {your-app-id} with your app's App ID. You can find this in the Meta App Dashboard.

Meta pixel configuration

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

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

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

fbq('init', <YOUR_PIXEL_ID>);
fbq('set', 'mobileBridge', <YOUR_PIXEL_ID>, <YOUR_FB_APP_ID>);
Important:
You need to call init and then set immediately afterwards. The snippet provided by Meta contains a track method. You can use this method to track a page view event right after you call the init method. To track the view event, you need to call set between init and track.

Adjust SDK integration

Augment the web view

iOS
Android

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

- (void)viewWillAppear:(BOOL)animated {
    ...
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    // or with WKWebView:
    // WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];

    // add @property (nonatomic, strong) AdjustBridge *adjustBridge; on your interface
    self.adjustBridge = [[AdjustBridge alloc] init];
    [self.adjustBridge loadUIWebViewBridge:webView];
    // optionally you can add a web view delegate so that you can also capture its events
    // [self.adjustBridge loadUIWebViewBridge:webView webViewDelegate:(UIWebViewDelegate*)self];

    // or with WKWebView:
    // [self.adjustBridge loadWKWebViewBridge:webView];
    // optionally you can add a web view delegate so that you can also capture its events
    // [self.adjustBridge loadWKWebViewBridge:webView wkWebViewDelegate:(id<WKNavigationDelegate>)self];
    [self.adjustBridge augmentHybridWebView];
    ...

Event name registration

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

To use this feature, you need to map Meta 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 tracking any pixel event. This includes the copy-pasted fbq('track', 'PageView'); event from the Meta pixel configuration.

To map events, call the addFbPixelMapping method on your config instance. Use the Meta 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);
Note:
The above example would match when tracking fbq('track', 'Search') and fbq('track', 'Purchase'). Adjust does not have access to the full map between the Facebook SDK and Javascript events.

Known pixel events

The Adjust SDK will log warnings if it cannot 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 do not have mapping configured. To do this, call adjustConfig.setFbPixelDefaultEventToken(defaultEventToken); before initializing the Adjust SDK.