This Facebook SDK (JS) App Events API has been deprecated and is no longer supported starting July 1, 2022. There are no plans to add new features to this product.
Instead of using FB.AppEvents.LogEvent
, we recommend that you send these events through the Meta Pixel.
The method FB.AppEvents.LogEvent
logs events from your app via Facebook SDK for JavaScript. Events are one of 14 predefined events such as 'added to cart' in a commerce app or 'level achieved' in a game, or other custom events. Learn more.
logEvent: function( eventName, /* string, required */ valueToSum, /* float, optional */ parameters, /* object, optional */ ), logPurchase: function( purchaseAmount, /* float */ currency, /* string, http://en.wikipedia.org/wiki/ISO_4217 */ parameters, /* object, optional */ ), activateApp(): void, logPageView(): void, setUserID( userID: string, ): void, getUserID(): string, clearUserID(): void, updateUserProperties( params: {[key: string]: string | number}, cb: ?(response: Object) => void, ): void, setAppVersion( appVersion: string, ): void, getAppVersion(): string, clearAppVersion(): void,
Each of these events can be logged with a valueToSum
and a set of parameters (up to 25 parameters). The table below shows the recommended events and what are typically useful parameters for each event (the common parameter names are defined in the next table). You should include the events that make sense based on the user actions in your app. All predefined event names are under FB.AppEvents.EventNames
.
Note: If you also log App Events for your mobile app, it is recommended that you use the same naming convention for events and parameters for all of your apps.
FBAppEventName | valueToSum | Example Parameters |
---|---|---|
|
| |
|
| |
| Price of item added |
|
| Price of item added |
|
|
| |
|
| |
| Total price of items in cart |
|
| Rating given |
|
|
| |
| Total value of credits spent |
|
|
| |
| Price of item viewed (if applicable) |
|
Useful parameters to include with the events shown above or with your own custom events. Future enhancements to our insights product will use the recommended parameters, but note that you can provide your own parameters as well. All predefined parameters are under FB.AppEvents.ParameterNames
.
Note: If you also log App Events for your mobile app, it is recommended that you use the same naming convention for events and parameters for all of your apps.
AppEventConstants::EVENT_PARAM_* | Possible Values | Description |
---|---|---|
| string | International Article Number (EAN) when applicable, or other product or content identifier |
| string | For example music, video, or product description |
| string | ISO 4217 code, e.g., "EUR", "USD", "JPY" |
| string | A string description |
| string | Player's Level |
| int | Upper bounds of a rating scale, for example 5 on a 5 star scale |
| int | Number of items |
| '1' or '0' | 1 for yes, 0 for no |
| string | Facebook, Email, Twitter, etc. |
| string | The text string that was searched for |
| '1' or '0' | 1 for yes, 0 for no |
Log Application Launch
Note: App Launches and App Installs are now logged automatically. It's no longer necessary to call activateApp to log those events.
Using logEvent
Events can be logged via a simple call to the logEvent
method. For instance, to log the completion of an in-app tutorial:
FB.AppEvents.logEvent(FB.AppEvents.EventNames.COMPLETED_TUTORIAL);
Add Parameters
You can add parameters associated with an event:
var params = {}; params[FB.AppEvents.ParameterNames.LEVEL] = 'Dungeon 1'; FB.AppEvents.logEvent( FB.AppEvents.EventNames.ACHIEVED_LEVEL, null, // numeric value for this event - in this case, none params );
Set the App Version You can set the version of the app with an event:
FB.AppEvents.setAppVersion('1.2.3.r4');