This Facebook SDK (JS) App Events API has been deprecated and is no longer supported as of 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.
App events allow you to measure ad performance and build audiences for ad targeting for your Game on Facebook.
This is done by sending an event from your app via Facebook SDK for JavaScript. This event can be one of pre-defined events such as 'added to cart' in a commerce app or 'level achieved' in a game, or other custom events.
Before including the code to measure events, you will need to register your app with Facebook. If you haven't registered your app with Facebook, you can do so here: Games on Facebook Quickstart.
Your Game on Facebook should already be including the Facebook SDK for JavaScript. If not, read our JavaScript quickstart guide.
You can view your logged events using the Facebook Events Manager.
We automatically log the following events for Games on Facebook:
If you have enabled payments through Facebook - the following additional events are logged:
Note: A Purchase Canceled event may not be logged if the person closes their browser window mid-purchase. This is why Purchase Canceled events may not equal the difference between Initiated Checkout events and Purchases events.
You can view your logged events using the Facebook Events Manager.
You can decide to log information in addition to the automatically logged events to better measure the performance of your app on Facebook.com. For instance, you may want to log an event any time someone completes a level in your game.
Below is an example of how you can log an event along with a parameter that describe your event:
var params = {}; params[FB.AppEvents.ParameterNames.LEVEL] = '12'; //player level FB.AppEvents.logEvent( FB.AppEvents.EventNames.ACHIEVED_LEVEL, null, // numeric value for this event - in this case, none params );
We recommend using one of the pre-defined events. However, we also support logging custom events.
The maximum number of different event names is 1,000. Note: No new event types will be logged once this cap is hit and if you exceed this limit you may see an 100 Invalid parameter
error when logging. Read more about event limits in the FAQ.
The Facebook SDK includes a dedicated function for logging purchases, which requires the specification of a currency.
Payments done via Games on Facebook are automatically logged as purchase events. It is only necessary to use the following code for sales of physical items.
var params = {}; params[FB.AppEvents.ParameterNames.CONTENT_ID] = 'QW-12345'; FB.AppEvents.logPurchase(98.76, 'USD', params);
To use the predefined parameters, create the params object then pass it to the function as shown below.
var params = {}; params[FB.AppEvents.ParameterNames.CONTENT_ID] = '12345'; FB.AppEvents.logPurchase(98.76, 'USD', params);
You can also choose to create your own custom events by specifying their name as a string:
FB.AppEvents.logEvent('battledAnOrc');
The maximum length for a customized event name is 40 characters and should consist only of alphanumerics, underscores, or dashes.
If you call the provided SDK JavaScript function with incorrect parameters the function will throw an exception. Make sure your code passes the correct parameters, and catch any exceptions if they occur.
To improve performance, the JavaScript SDK is loaded minified. You can also load a debug version of the JavaScript SDK that includes more logging and stricter argument checking as well as being non-minified. To do so, change the js.src
value in your loading code to this:
js.src = "https://connect.facebook.net/en_US/sdk/debug.js";