Back to News for Developers

Sending Events from Hybrid Web Apps

July 31, 2018BySean Bedford

A commonly asked question that the Facebook Solutions Engineering team are faced with is “How do I send you events from my hybrid web app?”.

A hybrid web app is a native mobile application where some of the functionality and UI is contained within a web view. This web view typically loads static HTML/CSS/JS content bundled within the application.

The common way to send events to Facebook within a website is the Facebook Pixel. This is JavaScript code bundled within a web container, which can be fired in the circumstance where a user performs certain actions. However, in the case of a web view within a native application container, there is another way to send events to Facebook. We call this mechanism App Events.

Sending App Events in the context of a mobile application can provide a number of advantages over sending pixel events:

  • The launch of the application typically fires an installation event if you also use the Facebook SDK or the SDKs of one of our Mobile Measurement Partners (MMPs). Tying all down-funnel events as App Events allows for easier use of some of the common Facebook mobile advertising features, such as App Event Optimisation.

  • Sending App Events can also lead to better optimization for users of your application, leading to a higher likelihood of positive advertising outcomes. If you elect to send pixel events instead, you may lose a lot of this environment-specific context.

  • Sending App Events through a mobile SDK helps account for mobile network reliability with batch and retry behavior, ensuring that your events eventually reach Facebook.

  • Sending App Events helps you track application specific metrics in Facebook Analytics, such as application version and mobile device model.

For these reasons, we recently developed and released a feature in our SDK that enables you to easily set this up.

The total code change required in your application is two lines (one native, one web). You can keep all calls to the fbq() method in your website the same as usual. Once configured, these events are redirected to be sent as app events through the Facebook SDK instead. This feature also works if your pixel is implemented inside a tag manager container.

For details on how to implement this, see our documentation.

Note: This functionality is only available in the Facebook iOS and Android SDKs version 4.34 and higher.

We're also working with our Mobile Measurement Partners to also make this more widely available in their SDKs.

Learn more: