App Events - Log Event

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 about: Analytics for Apps | App Events

Methods

  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 */
  ),

Events

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

ACHIEVED_LEVEL

LEVEL

ADDED_PAYMENT_INFO

SUCCESS

ADDED_TO_CART

Price of item added

CONTENT_TYPE, CONTENT_ID and CURRENCY

ADDED_TO_WISHLIST

Price of item added

CONTENT_TYPE, CONTENT_ID and CURRENCY

COMPLETED_REGISTRATION

REGISTRATION_METHOD

COMPLETED_TUTORIAL

SUCCESS and CONTENT_ID

INITIATED_CHECKOUT

Total price of items in cart

CONTENT_TYPE, CONTENT_ID ,NUM_ITEMS, PAYMENT_INFO_AVAILABLE and CURRENCY

RATED

Rating given

CONTENT_TYPE , CONTENT_ID and MAX_RATING_VALUE

SEARCHED

CONTENT_ID, SEARCH_STRING and SUCCESS

SPENT_CREDITS

Total value of credits spent

CONTENT_TYPE and CONTENT_ID

UNLOCKED_ACHIEVEMENT

DESCRIPTION

VIEWED_CONTENT

Price of item viewed (if applicable)

CONTENT_TYPE, CONTENT_ID and CURRENCY

Parameters

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 ValuesDescription

CONTENT_ID

string

International Article Number (EAN) when applicable, or other product or content identifier

CONTENT_TYPE

string

For example music, video, or product description

CURRENCY

string

ISO 4217 code, e.g., "EUR", "USD", "JPY"

DESCRIPTION

string

A string description

LEVEL

string

Player's Level

MAX_RATING_VALUE

int

Upper bounds of a rating scale, for example 5 on a 5 star scale

NUM_ITEMS

int

Number of items

PAYMENT_INFO_AVAILABLE

'1' or '0'

1 for yes, 0 for no

REGISTRATION_METHOD

string

Facebook, Email, Twitter, etc.

SEARCH_STRING

string

The text string that was searched for

SUCCESS

'1' or '0'

1 for yes, 0 for no

Examples

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
  );