Facebook Analytics Quickstart Guide for iOS

This Quickstart shows how to integrate Facebook Analytics into a new or existing Swift or Objective-C app.

1. Login

Please log in to Facebook to create apps or register as a developer.

2. Set up Your Development Environment

In the following list, select the appropriate SDK for the language you will use in this app. If your app uses Swift, select SDK: Cocoapods. If your app uses Objective-C, select SDK: FB SDK.

a. Install Cocoapods.

If you already installed Cocoapods and created a pod file, go to the next step to install the Facebook SDK. To install Cocoapods, open a terminal window and run the following command in a terminal window:
sudo gem install cocoapods

b. Install the Facebook SDK.

  1. Create a new Swift project and go to the project directory. If you are using an existing project, go to project directory of the existing project.
  2. In a terminal window, run the following command to create a pod file for the project:
    pod init
  3. Add the following line to the pod file of your project:
    pod 'FacebookCore'
  4. In the terminal window, run the following command to install the Facebook SDK for Swift:
    pod install

c. Modify the AppDelegate.swift file:

  1. Add the following import statement:
  2. import FacebookCore
    	
  3. Add the following statement to the applicationDidBecomeActive function:
  4. AppEventsLogger.activate(application)
    	

a. Download the Facebook SDK for iOS.

Download the SDK and unzip the archive to ~/Documents/FacebookSDK.

b. In xCode, create a single view Objective-C project.

c. Add the necessary Frameworks to your Xcode Project.

  1. Open ~/Documents/FacebookSDK
  2. Drag the following frameworks to Frameworks in the Project Navigator.
    • Bolts
    • FBSDKCoreKit
  3. Add the path to ~/Documents/FacebookSDK to Framework Search Paths in the Build Settings of your project.

When you use the Facebook SDK, some events in your app are automatically logged and collected for Facebook Analytics unless you disable automatic event logging. For details about what information is collected and how to disable automatic event logging, see Automatic App Event Logging.

d. Make the following changes to the AppDelegate.m file.

  1. At the top, add an import statement that points to <path_to>/FBSDKCoreKit.framework/Headers/FBSDKCoreKit.h.
  2. Replace the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function with the following code:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; // Add any custom logic here. return YES; }

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey] ]; // Add any custom logic here. return handled; }

3. Configure Your Information Property List.

a. Enter you Bundle Identifier (Bundle ID) in the Box.

You need to login to complete this step.

b. In Xcode, right-click info.plist and choose Open As Source Code.

c. Copy the XML snippet into the body of your file just before the final </dict> element.

<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb[APP_ID]</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

4. Build and then run the project in the Simulator

In Xcode, select an iOS simulator and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator.

5. See the Results in the Dashboard.

To see events, open Facebook Analytics. Choose your app and navigate to Activity > Event Debugging.
You should see your app launch event. If not, click the refresh button to load the latest events for your app.
Note: Events may take up to 20 minutes to appear in the dashboard.
Once you've verified that your events are being delivered, you're ready to create your first funnel to help you measure conversion for a sequence of events in your app.

6. Add More Events

Use the App Event Builder to generate the code in your language to implement either a custom or pre-defined app event that you can then add to your app.

To Generate Code for a Standard Event

  1. Choose the Standard Event tab.
  2. In Event Name, choose a standard event.
  3. Choose Get Code.
  4. In the window, select a language to see the code to copy and paste into your app.

Automatically Logged Events

After you integrate the Facebook SDK into your app, the following events are automatically logged:

EventDetails

App Install

The first time a new user activates an app or the first time an app starts on a particular device.

App Launch

When the Facebook SDK is initialized in your app for each session.

In-App Purchase

When a purchase processed by the Apple App Store or Google Play has been completed. If you use other payments platforms, you will need to add purchase event code manually.

Pre-defined Events

The following table contains the pre-defined events. Use the App Event Builder to get the code for these events.

Event NameDescription

Achieved Level

Log this event when the user has achieved the level in the app.


Required Parameter

  • Level

Ad Click

Log this event when the user clicks on an advertisement.


Required Parameter

  • Advertisement type

Ad Impression

Log this event when an advertisement appears to the user.


Required Parameter

  • Advertisement type

Add Payment Info

Log this event when the user has enters payment information as part of the checkout process.


Required Parameter

  • Success

Add To Cart

Log this event after the user adds an item to their cart.


Required Parameters

  • Content
  • Content ID
  • Content Type
  • Price of added item

Add To Wishlist

Log this event after the user add an item to their wish list.


Required Parameters

  • Content
  • Content ID
  • Content Type
  • Price of added item

Complete Registration

Log this event after the user completes registration in the app or website.


Required Parameter

  • RegistrationMethod

Complete Tutorial

Log this event after the user completes a tutorial in the app or website.


Required Parameter

  • None

Contact

Log this event after the user submits their contact information.


Required Parameter

  • None

Customize Product

Log this event after the user modifies a product selection using your tool to modify a product.


Required Parameter

  • None

Donate

Log this event after the user donates funds to your organization or cause.


Required Parameter

  • None

Find Location

Log this event after the user finds one of your locations with an intention to visit. For example, when the user selects a button that displays the closest store with the product in stock.


Required Parameter

  • None

Initiate Checkout

Log this event after the user starts the checkout process.


Required Parameters

  • Content
  • Content ID
  • Content Type
  • Currency
  • Number of items
  • Payment information available
  • Total price of items in cart

Purchase

Log this event after the user uses your own purchase method to complete a purchase. If you use Facebook to manage your in-app purchases, the purchase events are automatically logged.


Required Parameters

  • Content Type
  • Content ID
  • Content
  • Currency
  • Number of Items
  • Purchase price

Rate

Log this event after the user gives a rating.


Required Parameter

  • Rating given by the user.

Schedule

Log this event after the user makes an appointment to visit your location.


Required Parameter

  • None

Search

Log this event after the user performs a search within the app.


Required Parameters

  • Content type
  • Search string
  • Success

Spent Credits

Log this event after the user has spends their app credits.


Required Parameters

  • Content
  • Content ID
  • Content Type
  • Total value of credits spent

Start Trial

Log this event after the user chooses to start a free trial of your product or service.


Required Parameters

  • Currency
  • Order ID
  • Price of Subscription

Submit Application

Log this event after the user submits an application for a product, service, or program.


Required Parameter

  • None

Subscribed

Log this event after the user subscribes to a product or service.


Required Parameters

  • Currency
  • Order ID
  • Price of Subscription

Unlocked Achievement

Log this event after the user unlocks an achievement in the app.


Required Parameter

  • None

Viewed Content

Log this event after the user views a form of content in the app.


Required Parameters

  • Content Type
  • Content ID
  • Content
  • Currency

Test your events with the App Ads Helper

The App Ads Helper allows you to test your app events to ensure that your app is sending events to Facebook.

a. Open the App Ads Helper.

b. In Select an App, choose your app and choose Submit.

c. Go to the bottom and choose Test App Events.

d. Start your app and send an event. The event appears on the web page.

Take a Guided Tour of Facebook Analytics

Now that you're logging app events, visit our demo app to take a guided tour of all of the key features that Facebook Analytics offers you and your business.

The demo app does not have an Event Debugging link. This link is only available in apps that you create.

Next Steps

Be sure to check out our other documentation pages for more advanced guides.