FMTrackEventManager.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // FMTrackEventManager.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2024/2/7.
  6. //
  7. import Foundation
  8. import AppCenterAnalytics
  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. if let props = properties {
  27. Analytics.trackEvent(event, withProperties: props)
  28. } else {
  29. Analytics.trackEvent(event)
  30. }
  31. }
  32. func trackOnceEvent(event: String, withProperties properties: [String: String]?) {
  33. if event.count < 1 { return }
  34. var eventString = event
  35. if properties?.keys.count ?? 0 > 0 && properties?.values.count ?? 0 > 0 {
  36. var keyString = ""
  37. for key in properties!.keys {
  38. keyString += key
  39. }
  40. for value in properties!.values {
  41. keyString += value
  42. }
  43. eventString += keyString
  44. }
  45. if let props = properties {
  46. Analytics.trackEvent(event, withProperties: props)
  47. } else {
  48. Analytics.trackEvent(event)
  49. }
  50. }
  51. }