swift Facebook SDK应用事件不会在iOS 14+的事件管理器中记录事件

hgc7kmma  于 2022-11-28  发布在  Swift
关注(0)|答案(1)|浏览(245)

测试环境

  • Facebook软件开发工具包:第11.0.0版
  • 器械型号:iPhone X系列
  • iOS版本:14.1
    +预期结果

应记录iOS 14的应用事件(标准事件和自定义事件)。我们已通过设置启用AdvertiserTrackingEnabled。setAdvertiserTrackingEnabled(true)。并且我们已检查调试日志请求,发现SDK已成功发送事件。

+实际行为

即使我们设置了Settings.setAdvertiserTrackingEnabled(true)并调试日志请求成功发送事件。但它似乎没有记录在 Jmeter 板上。

hfsqlsce

hfsqlsce1#

我已经开发了这些Facebook SDK为我的一个应用程序获得应用程序事件。在iOS 14,15,16以下,一切都很好。
一旦您的应用程序在真实的设备上运行,并且在该设备中已安装Facebook应用程序及其登录信息,这些Facebook事件就会出现在事件管理器中,否则不会显示在事件管理器中。

1.应用程序添加到Facebook开发者页面,并获取应用程序ID和客户端令牌。
1.添加了信息plist下面这些行替换为您的应用程序ID和客户端令牌

<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>

稍后在AppDelegate中只导入这两个框架并将这些代码添加到didFinshlunch方法中。

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)

下一步,我们需要添加这些功能

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
            )

        }
}

在应用程序委托中添加这些传输安全权限警报,并在didbecome active方法或didfinsh lunch方法上调用这些函数。

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

最后一步在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()
        
        
        
         
    }

这样我们就可以编写事件了,请在类中添加这些框架,然后这样编写事件

import FBSDKCoreKit

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

----具有类似此参数事件----

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)

相关问题