如何使用swift使用Facebook分析使用parms记录自定义事件

Mik*_*ley 1 facebook facebook-analytics

我知道这是一个基本问题,但我无法弄清楚如何使用facebook analytics使用自定义参数记录自定义事件.例如,我想记录以下内容:

  • 歌曲播放
  • 标题
  • 艺术家

请参阅以下代码(不起作用):

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

    AppEvent.ViewedContent(contentType: "test", contentId: "test", extraParameters: dict)
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

"无法使用参数列表'(AppEventParameterName,AppEventParameterName)"调用'ParametersDictionary.Type'类型的值(也称为'Dictionary.Type')

我也尝试过:

let dict = AppEvent.ParametersDictionary(AppEventParameterName.Custom("title"), "test") 
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

Dan*_*Hsu 6

如文档中所述,字典需要是类型[AppEventParameterName : AppEventParameterValueType].

您可以构建字典,如:

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

然后将其输入到AppEventsLogger日志调用中,如下所示:

AppEventsLogger.log("trackedNewSong", parameters: dictionary, valueToSum: nil, accessToken: nil),"trackedNewSong"您将记录的事件将在哪里,并且您附加到它的参数将嵌入到字典中.

希望这可以帮助!