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, 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
        // 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
      // 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 the Dashboard.

To see events, open Facebook Analytics. Choose your app and navigate to Activity > Event Debugging.
You should see your app launch event as well as your custom events. 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. You may have to wait up to 20 minutes before events appear in the dashboard.

6. Add a Custom Event

App events are the key actions that people take as they use your app, such as launching your app, viewing content or making a purchase.

You can log app events for any meaningful actions people take in your app. There are many pre-defined events such as completed registration, viewed content, searched, added to cart, spent credits and more.

In this step, you add code to your project that appears as a custom event in the dashboard.

a. Add the following code to the viewDidLoad() function in the ViewController.swift file.

AppEventsLogger.log("My custom event.");

a. Add the following code to the viewDidLoad() function in the ViewController.m file.

[FBSDKAppEvents logEvent:@"My custom event"];

b. Build the project and then run the project in the Simulator.

c. See the results in the Dashboard.

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.