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.


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.