App events allow you to view analytics, 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 12 predefined events such as 'added to cart' in a commerce app or 'level achieved' in a game, or other custom events.
Games on Facebook now automatically log the following events: App Install, App Launched, Initiated Checkout, and Purchased, and Purchase Cancelled. It is not necessary to manually log these 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.
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 cancelled event may not be logged if the person closes their browser window mid-purchase. This is why purchase cancelled events may not equal the difference between initated checkout events and purchases events.
You can view your automatically logged events within Facebook Analytics for Apps
You can decide to log additional 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 12 pre-defined events which can be found here. 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. However it is possible to deactivate obsolete events. 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.
Note that 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);Note: to use the predefined parameters, you have to create the params object first, 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, which is done simply by specifying their name as a string:
FB.AppEvents.logEvent('battledAnOrc');Note the maximum length for a customized event name is 40 characters and should consist only of alphanumerics, underscores, or dashes.
Note that 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.
Events.Or use the URL www.facebook.com/analytics/{YourAppIdHere}?section=AppEvents and replace {YourAppIdHere} with your app ID.
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 = "//connect.facebook.net/en_US/sdk/debug.js";