Hybrid Mobile App Events

Overview

Beginning with FB SDK v4.34 for iOS and Android, Hybrid Mobile App Events are available. This feature provides a way for developers to use App Events for a native Android or iOS web app by converting Facebook Pixel events into App Events. With App Events you get more reliable optimization, more detailed integration with Facebook Analytics, the benefits of retry, batching, and other native Facebook SDK persistence assurances.

Getting Started

How to Intercept Pixel Events

When you augment a webview from iOS or Android, we inject a window level object called fbmq_<YOUR_APP_ID>. The Pixel, when set up to look for a mobile bridge, finds this window level fbmq object each time an fbq call is made. If the fbmq object is found, the Pixel issues a call to a method on this object. This in turn triggers a native iOS or Android callback where we fire an SDK logEvent call.

Requirements

Update Your Pixel

Update the Facebook Pixel code within the application web container to reference your Facebook App ID. This sends an event to the Pixel that you would like to send App Events instead of Pixel Events.

fbq('init', <YOUR_PIXEL_ID>);
fbq('set', 'mobileBridge', <YOUR_PIXEL_ID>, <YOUR_APP_ID>);

Update Your Native App

Update your native app with a call to augment your webview.

For Android

AppEventsLogger.augmentWebView(<YOUR_WEBVIEW_OBJECT>, <YOUR_ANDROID_CONTEXT>)

Calling augmentWebView adds a new Android JavascriptInterface to the web view that would send the AppEvents using the specified context.

For technical reasons, we only support WebView on Android 4.2 and higher.

For iOS

[FBSDKAppEvents augmentHybridWKWebView:<YOUR_WK_WEB_VIEW_OBJECT>];

For technical reasons, we only support WKWebView on iOS 8.0 and higher.

Log Events

After your code changes log Pixel Events as usual. We will intercept these events and send them as native App Events instead of Pixel Events.

Learn More

Visit our App Events Guide to learn more.