FMTrackEventManager.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // FMTrackEventManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2024/2/7.
  6. //
  7. import Foundation
  8. import FirebaseAnalytics
  9. let kTrackEventManager = FMTrackEventManager.defaultManager
  10. @objcMembers class FMTrackEventManager: NSObject{
  11. static let defaultManager: FMTrackEventManager = {
  12. let manager = FMTrackEventManager()
  13. return manager
  14. }()
  15. override init() {
  16. super.init()
  17. }
  18. func trackEvent(event: String, withProperties properties: [String: String]?) {
  19. if event.count < 1 { return }
  20. #if DEBUG
  21. let keyStr: String = properties?.keys.first ?? ""
  22. let vStr: String = properties?.values.first ?? ""
  23. NSLog("###-FireBaseEvent-(%@)-properties(%@):(%@)",event,keyStr,vStr)
  24. #endif
  25. // if RIAnalytics.isNewUserForCurrentVersion()
  26. var theParams: [String : String] = [:]
  27. for (key, value) in properties ?? [:] {
  28. theParams["itemname"] = key
  29. theParams["action"] = value
  30. }
  31. Analytics.logEvent(event, parameters: theParams)
  32. }
  33. func trackOnceEvent(event: String, withProperties properties: [String: String]?) {
  34. if event.count < 1 { return }
  35. var eventString = event
  36. if properties?.keys.count ?? 0 > 0 && properties?.values.count ?? 0 > 0 {
  37. var keyString = ""
  38. for key in properties!.keys {
  39. keyString += key
  40. }
  41. for value in properties!.values {
  42. keyString += value
  43. }
  44. eventString += keyString
  45. }
  46. var theParams: [String : String] = [:]
  47. for (key, value) in properties ?? [:] {
  48. theParams["itemname"] = key
  49. theParams["action"] = value
  50. }
  51. Analytics.logEvent(event, parameters: theParams)
  52. }
  53. }