FB.LogAppEvent

Publishes an App Event. App Events allow you to measure the effectiveness of your Facebook app ads and better understand the makeup of users engaging with your app. You can use one of 14 predefined events such as 'level achieved', or use custom events you define.

Log events that could help you understand player behavior and measure engagement coming from your App Ads on Facebook. How often these events occur is reported in aggregate with through Facebook Analytics for Apps.

Users do not need to be logged in with Facebook in order for you to log App Events.

Parameters

public static void LogAppEvent(
    string logEvent,
    float? valueToSum = null,
    Dictionary<string, object> parameters = null
)
NameTypeDescriptionDefault

logEvent

string

The name of the event to log

Required

valueToSum

float?

A number representing a value to be summed when reported

null

parameters

Dictionary <string, object>

Any parameters needed to describe the event

null

Predefined events in Facebook.Unity.AppEventName

For many common types of events, constant values are provided in the Facebook.Unity.AppEventName class. (e.g. Facebook.Unity.AppEventName.AchievedLevel)

NameWhen to log

AchievedLevel

The user has achieved a level in the app.

ActivatedApp

An app is being activated, typically in the AppDelegate's applicationDidBecomeActive.

AddedPaymentInfo

The user has entered their payment info.

AddedToCart

The user has added an item to their cart. The valueToSum passed should be the item's price.

AddedToWishlist

The user has added an item to their wishlist. The valueToSum passed should be the item's price.

CompletedRegistration

A user has completed registration with the app.

CompletedTutorial

The user has completed a tutorial in the app.

InitiatedCheckout

The user has entered the checkout process. The valueToSum passed should be the total price in the cart.

Purchased

The user has completed a purchase. The FB.LogPurchase method is a shortcut for logging this event.

Rated

The user has rated an item in the app. The valueToSum passed should be the numeric rating.

Searched

A user has performed a search within the app.

SpentCredits

The user has spent app credits. The valueToSum passed should be the number of credits spent.

UnlockedAchievement

The user has unlocked an achievement in the app.

ViewedContent

A user has viewed a form of content in the app.

Predefined parameter names in Facebook.Unity.AppEventParameterName

All parameter name constants are provided in the Facebook.Unity.AppEventParameterName class. (e.g. Facebook.Unity.AppEventParameterName.ContentID)

Parameter NameUse to specify...

ContentID

An ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app.

ContentType

A generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about.

Currency

ISO-4217 3-letter code for currency used (e.g. "USD", "EUR", "GBP").

Description

A description appropriate to the event being logged. E.g., the name of the achievement unlocked in the UnlockedAchievement event.

Level

Level parameter, e.g. The level achieved in a AchievedLevel event.

MaxRatingValue

The maximum rating available for the Rated event. E.g., "5" or "10".

NumItems

How many items are being processed for an InitiatedCheckout or Purchased event.

PaymentInfoAvailable

Whether payment info is available for the InitiatedCheckout event. 1 and 0 are good canonical values to use for this parameter.

RegistrationMethod

Method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc

SearchString

The string provided by the user for a search operation.

Success

Whether the activity being logged about was successful or not. 1 and 0 are good canonical values to use for this parameter.

FB.LogPurchase

A convenience method has been provided to log real-money in-app purchases, which is the most common use of event logging.

public static void LogPurchase(
    float logPurchase,
    string currency = null,
    Dictionary<string, object> parameters = null
)
NameTypeDescriptionDefault

logPurchase

float

The amount of currency the user spent

Required

currency

string

The 3-letter ISO currency code

"USD" (i.e. US dollars)

parameters

Dictionary <string,object>

Any parameters needed to describe the event. Elements included in this dictionary can't be null

null

Examples

Log that a user has bought, and then spent, some of your in-app currency.

// priceCurrency is a string containing the 3-letter ISO code for the currency
// that the user spent, and priceAmount is a float containing the quantity spent;
// packageName is a string containing your SKU code for the thing they bought
var iapParameters = new Dictionary<string, object>();
iapParameters["mygame_packagename"] = packageName;
FB.LogPurchase(priceAmount, priceCurrency, iapParameters);

// numGold is the number of in-app currency the user spent in this purchase,
// storeItem is a string naming the item the user bought
var softPurchaseParameters = new Dictionary<string, object>();
softPurchaseParameters["mygame_purchased_item"] = storeItem;
FB.LogAppEvent(Facebook.Unity.AppEventName.SpentCredits, (float)numGold, softPurchaseParameters);

More Examples

See additional FB.LogAppEvent examples at SDK Examples.