Mike Bailey
Mike Bailey

Reputation: 29

How to log a custom event with parms using Facebook analytics using swift

I know this a basic question, but I can't work out how to log a custom event with custom parameters using facebook analytics. For example, I would like to log the following:

Please see the below code (which does not work):

    let dict = AppEvent.ParametersDictionary(AppEventParameterName.Custom("title), AppEventParameterName.Custom("artist"))

    AppEvent.ViewedContent(contentType: "test", contentId: "test", extraParameters: dict)

I get the error message:

"Cannot invoke value of type 'ParametersDictionary.Type' (aka 'Dictionary.Type') with argument list '(AppEventParameterName, AppEventParameterName)"

I have also tried:

let dict = AppEvent.ParametersDictionary(AppEventParameterName.Custom("title"), "test") 

Any help would be greatly appreciated.

Upvotes: 2

Views: 3179

Answers (2)

Latchezar Mladenov
Latchezar Mladenov

Reputation: 31

Addition to Daniel's answer

For Swift 4:

let fbParams: [AppEventParameterName : AppEventParameterValueType] = [AppEventParameterName.init("id") : id]

Upvotes: 1

Daniel Hsu
Daniel Hsu

Reputation: 96

As mentioned in the documentation, the dictionary needs to be of type [AppEventParameterName : AppEventParameterValueType].

You can construct the dictionary like:

[.Custom["Song Played]: "Sunday Morning", .Custom["Artist"]: "Maroon 5"]

Then just input it into the AppEventsLogger log call like this:

AppEventsLogger.log("trackedNewSong", parameters: dictionary, valueToSum: nil, accessToken: nil), where "trackedNewSong" would be the event you are logging and the parameters you are attaching to it are embedded in the dictionary.

Hope this helps!

Upvotes: 6

Related Questions