KMAnalytics.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // KMAnalytics.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/7/12.
  6. //
  7. import Cocoa
  8. // 数据埋点 平台
  9. @objc enum KMAnalyticsPlatform: Int {
  10. case AppCenter
  11. case firebase
  12. }
  13. // 数据埋点 Category 参数
  14. extension KMAnalytics.Parameter.Category {
  15. public static let tbr = "Tbr"
  16. public static let subTbr_annotation = "SubTbr_Annotation"
  17. public static let subTbr_editPDF = "SubTbr_EditPDF"
  18. public static let subTbr_PageEdit = "SubTbr_PageEdit"
  19. public static let subTbr_Converter = "SubTbr_Converter"
  20. public static let subTbr_Tools = "SubTbr_Tools"
  21. public static let home = "Home"
  22. public static let leftSideBar = "LeftSideBar"
  23. public static let puw = "PUW"
  24. }
  25. // 数据埋点 Label 参数
  26. extension KMAnalytics.Parameter.Label {
  27. public static let tbr_Btn = "Tbr_Btn"
  28. public static let subTbr_Btn = "SubTbr_Btn"
  29. public static let ai_Btn = "AI_Btn"
  30. public static let create_Btn = "Create_Btn"
  31. public static let leftSideBar_Btn = "LeftSideBar_Btn"
  32. public static let sub_PUW = "Sub_PUW"
  33. }
  34. // 数据埋点 参数
  35. extension KMAnalytics.Parameter {
  36. public static let categoryKey = "Category"
  37. public static let labelKey = "Label"
  38. public struct Category {
  39. }
  40. public struct Label {
  41. }
  42. }
  43. // 数据埋点 工具类
  44. @objc class KMAnalytics: NSObject {
  45. public struct AppTarget: OptionSet, Codable {
  46. let rawValue: Int
  47. public static var free = AppTarget(rawValue: 1 << 0)
  48. public static var pro = AppTarget(rawValue: 1 << 1)
  49. public static var dmg = AppTarget(rawValue: 1 << 2)
  50. public static var all: AppTarget = [.free, .pro, .dmg]
  51. }
  52. public struct Parameter {
  53. }
  54. public static let Category = KMAnalytics.Parameter.Category.self
  55. public static let Label = KMAnalytics.Parameter.Label.self
  56. // 配置
  57. static func configure() {
  58. #if DEBUG
  59. #if VERSION_FREE
  60. #if VERSION_DMG
  61. let appSecret = "fb9d37aa-e3f2-4969-bd06-f65ce529a565"
  62. #else
  63. let appSecret = "8c08296d-ca5c-44da-b68a-b4382f119b1f"
  64. #endif
  65. #else
  66. let appSecret = "54212f10-3ac9-42d9-96c0-5387f4b78d30"
  67. #endif
  68. #else
  69. #if VERSION_FREE
  70. #if VERSION_DMG
  71. let appSecret = "fb9d37aa-e3f2-4969-bd06-f65ce529a565"
  72. #else
  73. let appSecret = "8c08296d-ca5c-44da-b68a-b4382f119b1f"
  74. #endif
  75. #else
  76. let appSecret = "54212f10-3ac9-42d9-96c0-5387f4b78d30"
  77. #endif
  78. #endif
  79. }
  80. // 发送事件
  81. static func trackEvent(eventName: String, parameters: [String : Any]? = nil, platform: KMAnalyticsPlatform = .firebase, appTarget: AppTarget = [.free]) {
  82. // Swift.debugPrint("trackEvent: \(eventName)")
  83. if (appTarget.contains(.free)) {
  84. #if VERSION_FREE
  85. #if VERSION_DMG
  86. #else
  87. self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
  88. #endif
  89. #endif
  90. }
  91. if (appTarget.contains(.pro)) {
  92. #if VERSION_FREE
  93. #else
  94. self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
  95. #endif
  96. }
  97. if (appTarget.contains(.dmg)) {
  98. #if VERSION_DMG
  99. self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
  100. #endif
  101. }
  102. }
  103. // MARK: - Private Methods
  104. // 发送事件
  105. fileprivate static func _trackEvent(eventName: String, parameters: [String : Any]? = nil, platform: KMAnalyticsPlatform = .firebase) {
  106. if (platform == .firebase) {
  107. } else if (platform == .AppCenter) {
  108. if let data = parameters as? [String : String] {
  109. }
  110. }
  111. }
  112. }