seyha
seyha

Reputation: 554

Facebook SDK App events won't record events in events manager for iOS 14+

Testing Environment

+Expected Result

App events both Standard Events and Custom Events should be record for iOS 14. We've enable AdvertiserTrackingEnabled by Settings.setAdvertiserTrackingEnabled(true). And we've check debug log request saw SDK sent events success.

+ Actual behaviour

Even though we do set Settings.setAdvertiserTrackingEnabled(true) and debug log request success sent event. But it doesn't seem to be recording on dashboard.

Upvotes: 0

Views: 2354

Answers (1)

Gangireddy Rami Reddy
Gangireddy Rami Reddy

Reputation: 989

I have developed these Facebook SDK for my one of the app for get the app events. In iOS under 14,15,16, everything works well.

These Facebook events appear once your application runs on real device and in that device have already installed facebook app and its login then the events will be appear in event manager otherwise not shows in event manager.

  1. app added into Facebook developer page and get the app id and client token.

  2. added info plist these below lines replace with your App ID and client token

    <key>NSUserTrackingUsageDescription</key>
    <string>${PRODUCT_NAME} please allow to tracking used to provide you a better and personalized ad experience.</string>
    
    
    
       <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb674454383521423</string>
        </array>
      </dict>
    
<key>FacebookAppID</key>
    <string>674454383521423</string>
    <key>FacebookClientToken</key>
    <string>3067e472e89ff8d7c39a18f38d931301</string>
    <key>FacebookDisplayName</key>
    <string>AppName</string>

Later in AppDelegate just import these two frameworks and added these code in to didFinshlunch method.

import FBSDKCoreKit
import AppTrackingTransparency




 ApplicationDelegate.shared.initializeSDK()
     Settings.shared.isAdvertiserTrackingEnabled = true
    Settings.shared.enableLoggingBehavior(.appEvents)
    Settings.shared.isAutoLogAppEventsEnabled = true
    Settings.shared.isAdvertiserIDCollectionEnabled = true
    Settings.shared.enableLoggingBehavior(.developerErrors)
    Settings.shared.enableLoggingBehavior(.cacheErrors)
    Settings.shared.enableLoggingBehavior(.uiControlErrors)

NEXT STEP WE NEED ADD THESE FUNCTION

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        

        if (url.scheme?.hasPrefix("fb"))! {

            ApplicationDelegate.shared.application(
                application,
                open: url,
                sourceApplication: sourceApplication,
                annotation: annotation
            )

        }
}

Add these transport security permisssion alert in app delegate and call these function on didbecome active method or else didfinsh lunch methos.

func getTrackingPermission() {
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization { status in
                switch status {
                case .authorized:
                    // Tracking authorization dialog was shown
                    // and we are authorized
                    Settings.shared.isAutoLogAppEventsEnabled = true
                    Settings.shared.isAdvertiserTrackingEnabled = true
                    print("Authorized")
                    
                    // Now that we are authorized we can get the IDFA
                    print(ASIdentifierManager.shared().advertisingIdentifier)
                case .denied:
                    Settings.shared.isAutoLogAppEventsEnabled = false
                    Settings.shared.isAdvertiserTrackingEnabled = false

                    // 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")
                }
            }
        }
    }

Last step added these method in appdelegate

func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
       //AppUpdater.shared.showUpdate(withConfirmation: false)
        
        
        if #available(iOS 15.0, *) {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                switch status{
                case .authorized:
                    Settings.shared.isAutoLogAppEventsEnabled = true
                    Settings.shared.isAdvertiserTrackingEnabled = true
                    print(ASIdentifierManager.shared().advertisingIdentifier)
                    
                    break
                case .denied:
                    Settings.shared.isAutoLogAppEventsEnabled = false
                    Settings.shared.isAdvertiserTrackingEnabled = false
                    print(ASIdentifierManager.shared().advertisingIdentifier)
                    
                default:
                    break
                }
                
            })
        }
         
        AppEvents.shared.activateApp()
        
        
        
         
    }

In these way we can write the events please added these framework in your class and write the event like this

import FBSDKCoreKit

AppEvents.shared.logEvent(AppEvents.Name(FACEBOOK_EVENTS.paymentDone.rawValue))

----event with params like this one----

var fbParams: [AppEvents.ParameterName : AppEvents.ParameterValue] = [:]
        
        fbParams[AppEvents.ParameterName.content] = AppEvents.ParameterValue.init(rawValue: "10")
        fbParams[AppEvents.ParameterName.init(rawValue: "number")] = AppEvents.ParameterValue.init(rawValue: "200")
        
        AppEvents.shared.logEvent(AppEvents.Name.purchased, parameters: fbParams)

Upvotes: 5

Related Questions