FMTrackEventManager.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. @objcMembers class FMTrackEventManager: NSObject{
  10. static let defaultManager: FMTrackEventManager = {
  11. let manager = FMTrackEventManager()
  12. return manager
  13. }()
  14. override init() {
  15. super.init()
  16. }
  17. func trackEvent(event: String, withProperties properties: [String: String]?) {
  18. if event.count < 1 { return }
  19. #if DEBUG
  20. let keyStr: String = properties?.keys.first ?? ""
  21. let vStr: String = properties?.values.first ?? ""
  22. NSLog("###-FireBaseEvent-(%@)-properties(%@):(%@)",event,keyStr,vStr)
  23. #endif
  24. // if RIAnalytics.isNewUserForCurrentVersion()
  25. if let props = properties {
  26. Analytics.trackEvent(event, withProperties: props)
  27. } else {
  28. Analytics.trackEvent(event)
  29. }
  30. }
  31. func trackOnceEvent(event: String, withProperties properties: [String: String]?) {
  32. if event.count < 1 { return }
  33. var eventString = event
  34. if properties?.keys.count ?? 0 > 0 && properties?.values.count ?? 0 > 0 {
  35. var keyString = ""
  36. for key in properties!.keys {
  37. keyString += key
  38. }
  39. for value in properties!.values {
  40. keyString += value
  41. }
  42. eventString += keyString
  43. }
  44. if let props = properties {
  45. Analytics.trackEvent(event, withProperties: props)
  46. } else {
  47. Analytics.trackEvent(event)
  48. }
  49. }
  50. }