Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log a custom Event in Facebook Analytics SDK 2020 for swift Documentation is deprecated

UPDATE

The problem is that facebook documentation for swift is outdated so to solve this you will have to log your custom event like this:

func logMyEvent(name : String, value : String) {
    let params : [String: Any] = ["myParamName" : "myParamValue"]
    let eventName: AppEvents.Name = AppEvents.Name(rawValue: "myEventName")
    AppEvents.logEvent(eventName, parameters: params)
}

IMPORTANT!

Take into account that facebook will log your event in its console about 20 minutes after you called it. So do not stress if the data is not there, just wait (I'm talking from experience hahaha). If you have any doubts don't hesitate to contact me, maybe I can help :D


I'm integrating Swift FacebookCore SDK so I can use Facebook Analytics! The problem is that facebooks official documentation DOES NOT WORK! It seems that they haven`t updated the code so I can not get the real code to log my own customized Event!

This is the code that Facebook gives you!

 * For more details, please take a look at:
 * developers.facebook.com/docs/swift/appevents
 */
func logMyEventEvent(name : String, value : String) {
    let params : AppEvent.ParametersDictionary = [
      "name" : name,
      "value" : value
      ]
    let event = AppEvent(name: "myEvent", parameters: params)
    AppEventsLogger.log(event)
}

Got it from here: https://developers.facebook.com/docs/app-events/getting-started-app-events-ios in the Manually Log Events section.

But AppEvent NO LONGER EXISTS.

Searching the web I found out that is because Facebook renamed it to AppEvents

IMAGE WERE I FOUND IT Here is the link to the GitHub poll. https://github.com/facebookarchive/facebook-swift-sdk/issues/433

But this still does not solve my issue, because I can not log a custom event.

Has anyone solved the same problem without going to the previous version?

Thank you very much!

like image 767
Daira Bezzato Avatar asked Feb 04 '23 15:02

Daira Bezzato


2 Answers

It's hard to believe, but I couldn't find any documentation on this either.

However, I worked out the following code from looking though the FBSDKCoreKit source. I haven't tested it yet, but I am posting it here just in case I meet with a sudden unexpected death in the next few minutes.

import FBSDKCoreKit

let name = "myEvent"
let parameters: [String: Any] = [
    "myParameter": "myParameterValue"
]

let event = AppEvents.Name(name)
AppEvents.logEvent(event, parameters: parameters)
like image 157
Drew Avatar answered Feb 13 '23 05:02

Drew


For Custom Event you can use

import FBSDKCoreKit

AppEvents.shared.logEvent(AppEvents.Name(rawValue: "AppEventName"), parameters: [AppEvents.ParameterName.init("Key"):"Value"])
like image 36
Narendra Prajapati Avatar answered Feb 13 '23 07:02

Narendra Prajapati