KMAnalytics+KMExtensions.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // KMAnalytics+KMExtensions.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/9/6.
  6. //
  7. import Foundation
  8. // 数据埋点 Category 参数
  9. //extension KMAnalytics.Parameter.Category {
  10. // public static let purchase_Tools = "Purchase_Tools"
  11. // public static let purchase_PageEdit = "Purchase_PageEdit"
  12. // public static let purchase_Editor = "Purchase_Editor"
  13. // public static let purchase_Converter = "Purchase_Converter"
  14. //
  15. // public static let purchase_Form = "Purchase_Form"
  16. // public static let purchase_Sign = "Purchase_Sign"
  17. // public static let purchase_EditPDF = "Purchase_EditPDF"
  18. // public static let purchase_Redact = "Purchase_Redact"
  19. //
  20. // public static let purchase_OCR = "Purchase_OCR"
  21. // public static let purchase_PageDisplay = "Purchase_PageDisplay"
  22. // public static let purchase_Others = "Purchase_Others"
  23. //}
  24. @objc extension NSViewController {
  25. private static var _eventNameKey = "KMEventNameKey"
  26. var kEventName: String? {
  27. get {
  28. return objc_getAssociatedObject(self, &Self._eventNameKey) as? String
  29. }
  30. set {
  31. objc_setAssociatedObject(self, &Self._eventNameKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
  32. }
  33. }
  34. private static var _eventParamsKey = "KMEventParamsKey"
  35. var kEventParams: [String : Any]? {
  36. get {
  37. return objc_getAssociatedObject(self, &Self._eventParamsKey) as? [String : Any]
  38. }
  39. set {
  40. objc_setAssociatedObject(self, &Self._eventParamsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
  41. }
  42. }
  43. private static var _eventTagKey = "KMEventTagKey"
  44. var kEventTag: Int {
  45. get {
  46. return objc_getAssociatedObject(self, &Self._eventTagKey) as? Int ?? 0
  47. }
  48. set {
  49. objc_setAssociatedObject(self, &Self._eventTagKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
  50. }
  51. }
  52. @objc func trackEvent_buyNow_tool(type: CAnnotationType, index: Int) {
  53. // KMAnalytics._trackEvent_buyNow_tool(type: type, index: index, appTarget: .all)
  54. }
  55. // MARK: - Track Events Basic
  56. // @objc func trackEvent(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  57. // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .all)
  58. // }
  59. // @objc func trackEvent_dmg(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  60. // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .dmg)
  61. // }
  62. // @objc func trackEvent_free(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  63. // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .free)
  64. // }
  65. // @objc func trackEvent_pro(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  66. // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .pro)
  67. // }
  68. // @objc func trackEvent_appstore(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  69. // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: [.free, .pro])
  70. // }
  71. func clearEventData() {
  72. self.kEventName = nil
  73. self.kEventTag = 0
  74. self.kEventParams = nil
  75. }
  76. }
  77. @objc extension NSWindowController {
  78. private static var _eventNameKey = "KMEventNameKey"
  79. var kEventName: String? {
  80. get {
  81. return objc_getAssociatedObject(self, &Self._eventNameKey) as? String
  82. }
  83. set {
  84. objc_setAssociatedObject(self, &Self._eventNameKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
  85. }
  86. }
  87. private static var _eventParamsKey = "KMEventParamsKey"
  88. var kEventParams: [String : Any]? {
  89. get {
  90. return objc_getAssociatedObject(self, &Self._eventParamsKey) as? [String : Any]
  91. }
  92. set {
  93. objc_setAssociatedObject(self, &Self._eventParamsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
  94. }
  95. }
  96. private static var _eventTagKey = "KMEventTagKey"
  97. var kEventTag: Int {
  98. get {
  99. return objc_getAssociatedObject(self, &Self._eventTagKey) as? Int ?? 0
  100. }
  101. set {
  102. objc_setAssociatedObject(self, &Self._eventTagKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
  103. }
  104. }
  105. // MARK: - Track Events Basic
  106. // @objc func trackEvent(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  107. // if let data = eveN {
  108. // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .all)
  109. // }
  110. // }
  111. //
  112. // @objc func trackEvent_dmg(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  113. // if let data = eveN {
  114. // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .dmg)
  115. // }
  116. // }
  117. //
  118. // @objc func trackEvent_free(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  119. // if let data = eveN {
  120. // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .free)
  121. // }
  122. // }
  123. //
  124. // @objc func trackEvent_pro(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  125. // if let data = eveN {
  126. // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .pro)
  127. // }
  128. // }
  129. //
  130. // @objc func trackEvent_appstore(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) {
  131. // if let data = eveN {
  132. // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: [.free, .pro])
  133. // }
  134. // }
  135. func clearEventData() {
  136. self.kEventName = nil
  137. self.kEventTag = 0
  138. self.kEventParams = nil
  139. }
  140. }
  141. // MARK: - KMAnalytics Private Methods
  142. extension KMAnalytics {
  143. // fileprivate static func _trackEvent_buyNow_tool(type: CAnnotationType, index: Int, platform: KMAnalyticsPlatform = .firebase, appTarget: AppTarget = [.free]) {
  144. // if let eventName = KMBuyNowEventNameFromCAnnotationType(type, index: index) {
  145. // let params: [String : Any]? = [KMAnalytics.Parameter.categoryKey : "Purchase_Tools", KMAnalytics.Parameter.labelKey : "SubTbr_Tools"]
  146. // KMAnalytics.trackEvent(eventName: eventName, parameters: params, platform: platform, appTarget: appTarget)
  147. // }
  148. // }
  149. }
  150. // MARK: - Pulick Methods
  151. public func KMBuyNowEventNameFromCAnnotationType(_ type: CAnnotationType, index: Int) -> String? {
  152. if type == .link {
  153. if index == 2 {
  154. return "Reading_WebsiteLink_BuyNow"
  155. } else if index == 3 {
  156. return "Reading_EmailLink_BuyNow"
  157. }
  158. } else if type == .stamp {
  159. if index == 2 {
  160. return "Reading_DynamicStamp_BuyNow"
  161. } else if index == 3 {
  162. return "Reading_CustomStamp_BuyNow"
  163. }
  164. } else if type == .signature {
  165. return "Reading_Signature_BuyNow"
  166. }
  167. return nil
  168. }