Facebook App Events API
Track user actions with the WebToNative Facebook App Events API. Integrate event logging to measure app engagement and conversions.
Use the Facebook App Events API to log what users do in your app, such as sign-ups, add-to-carts and purchases, so you can measure engagement and conversions and optimise your ads in Facebook Events Manager. You can also turn the Facebook SDK's automatic event logging on or off at runtime, for example to respect a user's consent choice.
You'll need to import the javascript file in your website before starting from this link.
This page covers:
Logs a custom or standard event.
Logs a purchase with an amount and currency.
Turns automatic event logging on or off.
Tells you whether automatic event logging is currently on.
Automatically Logged Events
When the Facebook SDK is active, it logs certain events (such as app installs and app launches) automatically and sends them to Facebook Events Manager. These events are used for targeting, measurement and optimisation.
Learn more about automatically logged events:
You can turn this automatic logging on or off from your website with setFacebookAnalyticsCollection, and check its current state with getFacebookAnalyticsCollectionStatus.
Manually Log Events (Custom Events)
Besides the automatic events, you can log your own events whenever something meaningful happens on your website, such as a completed registration or a viewed product.
Facebook Analytics must be enabled in your app configuration. If it is not,
sendandsendPurchasedo nothing on both Android and iOS, and no error is reported.
Send a custom event
Sends a custom or standard event to Facebook.
Parameters:
event
String
Yes
Name of the event. Use a Facebook standard event name (see Event names and parameter keys) or your own custom name.
valueToSum
Number
No
A numeric value Facebook adds up across events, for example an order value.
parameters
Object
No
Extra key-value data to attach to the event.
This function does not take a callback.
Send a purchase event
Purchases have their own function. Facebook's SDK sends purchase events more quickly than regular events.
Parameters:
amount
Number
Yes
The purchase amount.
currency
String
Yes
A valid ISO 4217 currency code in uppercase, for example "USD" or "INR".
parameters
Object
No
Extra key-value data to attach to the event.
This function does not take a callback.
Event names and parameter keys
The list of standard event names and parameter keys is available here:
Enable or Disable Automatic Event Logging
Turns the Facebook SDK's automatic event logging on or off. Use this to stop sending data to Facebook until the user gives consent, and to turn it back on once they do.
The choice is saved on the device and is applied again every time the app starts. Until it is set, the app uses the automatic logging default from your app configuration.
This setting only controls automatically logged events. Events you send with
events.sendandevents.sendPurchaseare still sent while it is off, so check the user's consent in your own code before calling them (see the example below).
Parameters:
enabled
Boolean
Yes
true to enable automatic event logging, false to disable it. Pass a real boolean, not "true" or 1.
callback
Function
No
Receives the response object.
Callback responses:
Success (Android and iOS):
Invalid enabled value (Android only):
Save or apply failed (Android only):
If the exception has no message, error is "Failed to update Facebook Analytics collection".
Get Automatic Event Logging Status
Tells you whether automatic event logging is currently on. Use it to show the right state in a privacy or consent setting.
Parameters:
callback
Function
No
Receives the response object.
Callback response:
enabled is true when automatic event logging is on and false when it is off.
Example: Consent Toggle
A privacy setting that shows the current state when the page loads and turns automatic event logging on or off when the user changes it. A purchase event is only sent while logging is enabled.
Last updated