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, you can select your preferred method of installing dependencies in your project.
Using Swift Package Manager (SPM)
Only available for Xcode 11.2 and above.
  1. In Xcode, click File > Swift Packages > Add Package Dependency.
  2. In the dialog that appears, enter the repository URL: https://github.com/facebook/facebook-ios-sdk.
  3. In Version, select Up to Next Major and take the default option.
  4. Complete the prompts to select the libraries you'd like to use in your project.
  5. To use the Objective-C interface exclusively, import the 'FBSDK'-prefixed module.
    Example: import FBSDKCoreKit
    To use the enhanced Swift interface in your code, import the 'Facebook'-prefixed module.
    Example: import FacebookCore
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
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 'FBSDKCoreKit/Swift'
  4. In the terminal window, run the following command to install the Facebook SDK for Swift:
    pod install
Modify the AppDelegate.swift file:
  1. Add the following import statement:
  2. import FBSDKCoreKit
    	
  3. Add the following statement to the applicationDidBecomeActive function:
  4. AppEventsLogger.activate(application)
    	
Your Cartfile should look something like:

github "facebook/facebook-ios-sdk"

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

3. Configure Your Information Property List.

Enter you Bundle Identifier (Bundle ID) in the Box.
You need to login to complete this step.
In Xcode, right-click info.plist and choose Open As Source Code.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 Events Manager.

The Events Manager displays the events you send to Facebook Analytics. If this is the first time you launched your app with this code, you may have to wait at least 20 minutes before your events appear.
Note: Events may take up to 20 minutes to appear in the dashboard.

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.