iOS Facebook SDK installation - App Events
Asked Answered
C

1

8

I'm having a nightmare trying to install the Facebook SDK on iOS for app events analytics. The facebook documentation is terrible, and inconsistent, and I can't find any up to date installation documents that work. All I want to do is install the SDK so that I can track app installations and app open events. I'm using cocoapods for installation

pod 'Facebook-iOS-SDK'

In my app delegate didFinishLaunchingWithOptions I have the following code

import FBSDKCoreKit

class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
    ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    
    Settings.isAutoLogAppEventsEnabled = true
    Settings.isAdvertiserIDCollectionEnabled = true
    Settings.loggingBehaviors = [LoggingBehavior.appEvents,LoggingBehavior.networkRequests]
    
    return true
}
    
// ...

}

In my info.plist I have the following as per the documentation:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb396923698487528</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>396923698487528</string>
    <key>FacebookDisplayName</key>
    <string>Where4Test</string>

And from the logs it shows the analytics events sending and returning with success to the facebook api. But in the event manager https://www.facebook.com/events_manager2 no events are showing and it says I still haven't installed the SDK.

Facebook Event Manager

I've tried a million different things, but just can not get the events to register with facebook. Please can someone give an up to date installation instruction or see something I'm doing wrong!

Cubitiere answered 31/3, 2022 at 17:16 Comment(0)
C
5

The solution to this problem was to request ad tracking permissions from the user as follows

import AppTrackingTransparency
import AdSupport
//… 

if #available(iOS 14, *) {
    ATTrackingManager.requestTrackingAuthorization { status in
        switch status {
        case .authorized:
            // Tracking authorization dialog was shown
            // and we are authorized
            print("Authorized")
            
            // Now that we are authorized we can get the IDFA
            print(ASIdentifierManager.shared().advertisingIdentifier)
        case .denied:
            // Tracking authorization dialog was
            // shown and permission is denied
            print("Denied")
        case .notDetermined:
            // Tracking authorization dialog has not been shown
            print("Not Determined")
        case .restricted:
            print("Restricted")
        @unknown default:
            print("Unknown")
        }
    }
}

Facebook documentation doesn’t mention this as a required installation step for the app events to work, but it turns out it is. This isn’t for any coding reason but instead because of legal compliance reasons. They really should say it is a necessary step and inform you that events won’t be tracked in the SDK logs if you haven’t requested authorisation.

Cubitiere answered 1/4, 2022 at 10:19 Comment(2)
Hi TimWhiting your issue fixedIzettaizhevsk
facebook meta sucks with their ads manager platform and documentation, written by 18 year olds literallyDonee

© 2022 - 2024 — McMap. All rights reserved.