App Events for iOS

App Events help you understand the makeup of people who engage with your app and measure and reach specific sets of your users with Facebook mobile app ads. This is done by logging events from your app via the Facebook SDK for iOS. The event can be one of 14 predefined events such as added to cart in a commerce app or achieved level in a game, or any custom events you can define.

The examples in this document are written in Objective-C. If you are using Swift, refer to App Events with the Facebook SDK for Swift.

Prerequisites

Before including the code to measure events, you'll need to register your app with Facebook and download and configure the Facebook SDK. See our getting started guide to learn more.

The instructions below are for version 4.0 and higher of the SDK. If you are still using version 3.X, you will need to omit the word SDK from your App Event calls. For instance in the example below, you would use FBAppEvents instead of FBSDKAppEvents.

Implementation

Facebook's SDK provides two helper methods for app activation and purchases, the two most common types of events.

Logging app activations

Logging app activations as an App Event enables almost all other functionality and should be the first thing that you add to your app. The SDK provides a helper method to log app activation. By logging an activation event, you can observe how frequently users activate your app, how much time they spend using it, and view other demographic information through Facebook Analytics for Apps.

Insert this piece of code in your app delegate's applicationDidBecomeActive method:

- (void)applicationDidBecomeActive:(UIApplication *)application {    
    // Call the 'activateApp' method to log an app event for use
    // in analytics and advertising reporting.
    [FBSDKAppEvents activateApp];
    // ...
}

The activateApp method is the preferred way to log app activations, even though there's an event that you can send manually via the SDK. The helper method performs a few other tasks that are necessary for proper accounting for Mobile App Install Ads.

Purchases

Much like logging app activations, the Facebook SDK provides a helper method to log purchases with a single line of code. For example, a purchase of USD $4.32, can be be logged with:

[FBSDKAppEvents logPurchase:4.32 currency:@"USD"];

The currency specification is expected to be an ISO 4217 currency code. This is used to determine a uniform value for use in ads optimization.

Automatic In-App Purchase Logging

We suggest that you use the manual logging method if you can, but if you can't change your code for some reason, Facebook has made it possible to automatically log app events related to in-app purchases. To enable automatic purchase logging, call the activateApp method during app activation and enable the “Automatic In-App Purchase” switch in the iOS settings section of the app's dashboard. Automatic logging requires version iOS SDK 3.22 or higher.

You can learn more about this feature in this FAQ.

The maximum number of different event names is 1000. 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.

Logging Events Manually

For all other types of events, use the logEvent method:

[FBSDKAppEvents logEvent:FBSDKAppEventName{XXXX}];

where FBSDKAppEventName{XXXX} is one of the FBSDKAppEventName* constants shown in the Events table below.

You can also specify a set of parameters and a valueToSum property which is an arbitrary number that can represent any value (e.g., a price or a quantity). When reported, all of the valueToSum properties will be summed together in Facebook Analytics for Apps. For example, if 10 people each purchased one item that cost $10 (and passed in valueToSum) then they would be summed to report a number of $100.

[FBSDKAppEvents logEvent:FBSDKAppEventNameAddedToCart
              valueToSum:54.23
              parameters:@{ FBSDKAppEventParameterNameCurrency    : @"USD",
                            FBSDKAppEventParameterNameContentType : @"product",
                            FBSDKAppEventParameterNameContentID   : @"HDFU-8452" } ];

Note that both the valueToSum and parameters arguments are optional.

The full list of pre-defined events and pre-defined parameters are listed below.

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.

Event Name: FBSDKAppEventName valueToSum Parameters

Achieved Level:

FBSDKAppEventNameAchievedLevel

Level

App Launched:

FBSDKAppEventNameActivatedApp

Added Payment Info:

FBSDKAppEventNameAddedPaymentInfo

Success

Added To Cart:

FBSDKAppEventNameAddedToCart

Price of item added

ContentType, ContentID and Currency

Added To Wishlist:

FBSDKAppEventNameAddedToWishlist

Price of item added

ContentType, ContentID and Currency

Completed Registration:

FBSDKAppEventNameCompletedRegistration

RegistrationMethod

Completed Tutorial:

FBSDKAppEventNameCompletedTutorial

Success and ContentID

Initiated Checkout:

FBSDKAppEventNameInitiatedCheckout

Total price of items in cart

ContentType, ContentID, NumItems, PaymentInfoAvailable and Currency

Purchased:

`FBSDKAppEventNamePurchased`

Use the logPurchase method instead.

Purchase price

NumItems, ContentType, ContentID and Currency

Rated:

FBSDKAppEventNameRated

Rating given

ContentType , ContentID and MaxRatingValue

Searched:

FBSDKAppEventNameSearched

ContentType, SearchString and Success

Spent Credits:

FBSDKAppEventNameSpentCredits

Total value of credits spent

ContentType and ContentID

Unlocked Achievement:

FBSDKAppEventNameUnlockedAchievement

Description

Viewed Content:

FBSDKAppEventNameViewedContent

Price of item viewed (if applicable)

ContentType, ContentID and Currency

Parameters

The table below are typically useful parameters for inclusion with the events shown above, or with your own custom events. You can also provide your own parameters as well.

These pre-defined parameters are intended to provide guidance on typically useful logging patterns, and may have a more readable form in reporting and other UI. Log the set of parameters you're interested in seeing broken down in Analytics for Apps. The recommended description for these are guidance only - you can use these parameters for whatever makes sense for your app.

The parameters are passed via an NSDictionary where the key holds the parameter name as an NSString (iOS SDK constants for the pre-defined ones are listed below), and the value must be either an NSString or an NSNumber:

Parameter: FBSDKAppEventParameterName Possible Values Description

Content ID:

FBSDKAppEventParameterNameContentID

string

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

Content Type:

FBSDKAppEventParameterNameContentType

string

product or product_group

Currency:

FBSDKAppEventParameterNameCurrency

string

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

Description:

FBSDKAppEventParameterNameDescription

string

A string description

Level:

FBSDKAppEventParameterNameLevel

string

Level of a player

Max. Rating Value:

FBSDKAppEventParameterNameMaxRatingValue

int

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

Number of Items:

FBSDKAppEventParameterNameNumItems

int

Number of items

Payment Info Available:

FBSDKAppEventParameterNamePaymentInfoAvailable

1 or 0

1 for yes, 0 for no

Registration Method:

FBSDKAppEventParameterNameRegistrationMethod

string

Facebook, Email, Twitter, etc.

Search String:

FBSDKAppEventParameterNameSearchString

string

The text string that was searched for

Success:

FBSDKAppEventParameterNameSuccess

1 or 0

1 for yes, 0 for no

Custom App Events

You can also choose to create your own custom events. To log a custom event, just pass the name of the event as an NSString:

[FBSDKAppEvents logEvent:@"battledAnOrc"];

API Reference

More details about the FBSDKAppEvents class can be found in the reference documentation.

Verifying Event Logging in Facebook Analytics for Apps

If you're an Admin or a Developer of an app, you can validate that you've correctly implemented app events in Facebook Analytics for Apps. Please see our documentation on debugging events in Facebook Analytics for Apps to learn how to verify that events are being logged.

Enabling Debug Logs

Developers can enable debug logs so they can easily verify App Event usages from client sides. The debug logs contain detailed request and response in JSON. You can enable debug logs by adding this code:

[FBSDKSettings enableLoggingBehavior:FBSDKLoggingBehaviorAppEvents];

This is only for debugging purpose. Please make sure to disable debug logs before deploying app in production.

Analytics for Apps

Enabling App Events means that you can automatically start using Facebook Analytics for Apps. This analytics channel provides demographic info about the people using your app, offers tools for better understanding the flows people follow in your app, and lets you compare cohorts of different kids of people performing the same actions.

See our documentation for Facebook Analytics for Apps for more information.

Facebook Ads

Mobile App Ad Performance

You can use app events to better understand the engagement and ROI coming from your mobile ads on Facebook. If you've set up app events, they will be reported as different types of actions in Ads Manager so you can see which ads and campaigns resulted in what actions within your app. For example, you may see that a particular ad resulted in 10 total actions. Those actions could be 8 checkouts and 2 registrations, which will be specified in Ads Manager.


Mobile App Ad Targeting

Measuring app events also opens up an easier way to reach your existing app users for mobile app ads. After integrating app events, you will be able to reach your existing users, specific subsets of users based on what actions they have taken within your app, or even percentages of your most active users. For instance you can run ads to bring recent purchasers back into your app to complete more purchases or to your top 25% of purchasers. You can choose an audience to reach based on the app events you are measuring in your app.

To learn more about our mobile app ads, go to our tutorial on mobile app ads for installs or mobile app ads for engagement.


Ads Attribution

Once you've implemented app events into your iOS app, the App Events you've added will automatically be tracked when you run Facebook mobile app ads for installs or mobile app ads for engagement and conversion. Initially, we will only track the 14 predefined events described above.

If using Power Editor to set up your ad, please ensure you use the default tracking settings, or if you manually configure tracking settings that the following tracking_spec is present, with {app_id} replaced with your app's Facebook App Id.

{"action.type" : ["app_custom_event"], 
 "application" : [{app_id}]} 

What's reported:

If you have set up app events, they will be reported as different types of actions in Ads Manager. For example, you may see that a particular ad resulted in 10 total actions. Those actions could be 8 checkouts and 2 registrations, which will be specified in Ads Manager. You can learn more about measuring performance of mobile app ads in Ads Manager here and Post Install Reports in Power Editor

Data Control

The Facebook SDK offers a tool to give your users control over how app events data is used by the Facebook ads system. Our Platform Policy requires that you provide users with an option to opt out from sharing this info with Facebook. We recommend that you use our SDK tools to offer the opt-out. The tool is described below. Facebook also respects device-level controls where available, including the Advertising Identifier control on iOS6 and beyond.

setLimitEventAndDataUsage behavior

If the user has set the limitEventAndDataUsage flag to YES, your app will continue to send this data to Facebook, but Facebook will not use the data to serve targeted ads. Facebook may continue to use the information for other purposes, including frequency capping, conversion events, estimating the number of unique users, security and fraud detection, and debugging.

[FBSDKSettings setLimitEventAndDataUsage:YES];

The limitEventAndDataUsage setting will persist across app sessions. To use this property, you can match your opt-out's UI to the value of the limitEventAndDataUsage flag.

Data Sharing

App Event data you share with Facebook will not be shared with advertisers or other third parties, unless we have your permission or are required to do so by law.