Aggregated Event Measurement

You can use Aggregated Event Measurement (AEM) for iOS apps to measure app events from iOS 14.5+ users who have opted out of app tracking. You can integrate with AEM by using the Facebook SDK for iOS.

Use the Facebook SDK

Step 1: Set Up Your Development Environment

Follow the instructions in Get Started - iOS through Step 5. When you reach Step 6, return to this page and continue with Step 2 following.

Step 2: Support iOS Universal Links

Support deep linking into your mobile app by meeting the prerequisites to support iOS Universal Links.

Step 3: Connect Your App Delegate and Scene Delegate

Use the following method to integrate with AEM when you support iOS Universal Links.

Facebook SDK for iOS v14.0.0 and Later

To ensure that your app properly supports deep linking from app ads with Universal Links, implement application(:continue:restorationHandler:) in your app delegate, and call ApplicationDelegate.shared.application(_:continue:) from your implementation. Your code might look like the following:

func application(_ application: UIApplication,
                   continue userActivity: NSUserActivity,
                   restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
                 ) -> Bool
{
  ApplicationDelegate.shared.application(application, continue: userActivity)
  
  // Rest of implementation...
  
  return true
}

If your app is opted into scenes, add the following code in your scene delegate implementation in scene(_:continue:) and in scene(_:willConnectTo:options:):

func scene(_ scene: UIScene,
             continue userActivity: NSUserActivity
           )
{
  ApplicationDelegate.shared.application(.shared, continue: userActivity)
  
  // Rest of implementation...
}
  
  
func scene(_ scene: UIScene,
             willConnectTo session: UISceneSession,
             options connectionOptions: UIScene.ConnectionOptions
           )
{
  if let userActivity = connectionOptions.userActivities.first,
         userActivity.activityType == NSUserActivityTypeBrowsingWeb
  {
    ApplicationDelegate.shared.application(.shared, continue: userActivity)
  }
  
  // Rest of implementation...
}  

Facebook SDK for iOS v13.2.0 and Earlier

To ensure that your app properly supports deep linking from app ads with Universal Links, implement application(:continue:restorationHandler:) in your app delegate, and call ApplicationDelegate.shared.application(_:open:options:) from your implementation. Your code might look like the following:

func application(_ application: UIApplication,
                   continue userActivity: NSUserActivity,
                   restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
                ) -> Bool
{
  if userActivity.activityType == NSUserActivityTypeBrowsingWeb,
     let url = userActivity.webpageURL
  {
    ApplicationDelegate.shared.application(application, open: url, options: [:])
  }
  
  // Rest of implementation...

  return true
}

If your app is opted into scenes, add the following code in your scene delegate implementation in scene(_:continue:) and in scene(_:willConnectTo:options:):

func scene(_ scene: UIScene,
             continue userActivity: NSUserActivity
           )
{
  if let url = userActivity.webpageURL,
     userActivity.activityType == NSUserActivityTypeBrowsingWeb
  {
    ApplicationDelegate.shared.application(.shared, open: url, options: [:])
  }
    
  // Rest of implementation...
}
  
  
func scene(_ scene: UIScene,
             willConnectTo session: UISceneSession,
             options connectionOptions: UIScene.ConnectionOptions
          )
{
  if let userActivity = connectionOptions.userActivities.first,
     let url = userActivity.webpageURL,
     userActivity.activityType == NSUserActivityTypeBrowsingWeb
  {
    ApplicationDelegate.shared.application(.shared, open: url, options: [:])
  }

  // Rest of implementation...
}

To support AEM when you use Custom URLs in your mobile app

Replace the code in AppDelegate.swift method with the following code. This code initializes the SDK when your app launches and passes the DeepLink URL to the SDK. The DeepLink URL from the re-engagement ads should be passed to the iOS SDK even if the app is opened in cold start.

If you programmatically set the Facebook App ID, please set the App ID before the SDK initialization.

// AppDelegate.swift
import UIKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{    
  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
                   ) -> Bool
  {  
    // You don’t need to set App ID if you have configured App ID in info.plist
    Settings.shared.appID  = APP_ID    

    // Initialize iOS SDK
    ApplicationDelegate.shared.application
    (
      application,
      didFinishLaunchingWithOptions: launchOptions
    )

    return true
  }
  

  func application(_ app: UIApplication,
                   open url: URL,
                   options: [UIApplication.OpenURLOptionsKey : Any] = [:]
                   ) -> Bool
  {
    // Pass DeepLink URL to iOS SDK
    ApplicationDelegate.shared.application
    (
      app,
      open: url,
      sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
      annotation: options[UIApplication.OpenURLOptionsKey.annotation]
    )
  }  
}

iOS 13 moved opening URL functionality to the SceneDelegate. If you are using iOS 13, add the following method to your SceneDelegate:

// SceneDelegate.swift
import FBSDKCoreKit
  ...
func scene(_ scene: UIScene, 
           openURLContexts URLContexts: Set<UIOpenURLContext>
           )
{
  guard let url = URLContexts.first?.url else
  {
    return
  }

  // Pass DeepLink URL to iOS SDK
  ApplicationDelegate.shared.application
  (
    UIApplication.shared,
    open: url,
    sourceApplication: nil,
    annotation: [UIApplication.OpenURLOptionsKey.annotation]
  )
}

Step 3: Add App Events

To add the app events that you want to track, follow the instructions in Get Started - iOS beginning with Step 7.