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:
-
Add a new string with the name
facebook_app_id
. Add your Facebook App ID as the value. -
Open your
strings.xml
file. Example path:/app/src/main/res/values/strings.xml
. -
Open
AndroidManifest.xml
. -
Add a uses-permission element to the manifest:
-
Add a meta-data element to the application element:
Facebook pixel configuration
Follow Facebook’s guide on how to integrate the Facebook pixel. The Javascript code should look something like this:
Next, update your Facebook pixel code. You can find the instructions in the Hybrid Mobile App Events guide under Update Your Pixel.
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.
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:
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.
Pixel event name | Facebook app event name |
---|---|
ViewContent | fb_mobile_content_view |
Search | fb_mobile_search |
AddToCart | fb_mobile_add_to_cart |
AddToWishlist | fb_mobile_add_to_wishlistt |
InitiateCheckout | fb_mobile_initiated_checkout |
AddPaymentInfo | fb_mobile_add_payment_info |
Purchase | fb_mobile_purchase |
CompleteRegistration | fb_mobile_complete_registration |
The Adjust SDK logs warnings if it can’t find a default event token for certain events.
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.