|
@@ -0,0 +1,157 @@
|
|
|
+//
|
|
|
+// KMAnalytics+KMExtensions.swift
|
|
|
+// PDF Reader Pro
|
|
|
+//
|
|
|
+// Created by User-Tangchao on 2024/9/6.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+
|
|
|
+// 数据埋点 Category 参数
|
|
|
+extension KMAnalytics.Parameter.Category {
|
|
|
+ public static let purchase_Tools = "Purchase_Tools"
|
|
|
+ public static let purchase_PageEdit = "Purchase_PageEdit"
|
|
|
+ public static let purchase_Editor = "Purchase_Editor"
|
|
|
+ public static let purchase_Converter = "Purchase_Converter"
|
|
|
+
|
|
|
+ public static let purchase_Form = "Purchase_Form"
|
|
|
+ public static let purchase_Sign = "Purchase_Sign"
|
|
|
+ public static let purchase_EditPDF = "Purchase_EditPDF"
|
|
|
+ public static let purchase_Redact = "Purchase_Redact"
|
|
|
+
|
|
|
+ public static let purchase_OCR = "Purchase_OCR"
|
|
|
+ public static let purchase_PageDisplay = "Purchase_PageDisplay"
|
|
|
+ public static let purchase_Others = "Purchase_Others"
|
|
|
+}
|
|
|
+
|
|
|
+// 数据埋点 Label 参数
|
|
|
+//extension KMAnalytics.Parameter.Label {
|
|
|
+// public static let tbr_Btn = "Tbr_Btn"
|
|
|
+//}
|
|
|
+
|
|
|
+@objc extension NSViewController {
|
|
|
+ private static var _eventNameKey = "KMEventNameKey"
|
|
|
+ var kEventName: String? {
|
|
|
+ get {
|
|
|
+ return objc_getAssociatedObject(self, &Self._eventNameKey) as? String
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ objc_setAssociatedObject(self, &Self._eventNameKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static var _eventParamsKey = "KMEventParamsKey"
|
|
|
+ var kEventParams: [String : Any]? {
|
|
|
+ get {
|
|
|
+ return objc_getAssociatedObject(self, &Self._eventParamsKey) as? [String : Any]
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ objc_setAssociatedObject(self, &Self._eventParamsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func trackEvent_buyNow_tool(type: CAnnotationType, index: Int) {
|
|
|
+ KMAnalytics._trackEvent_buyNow_tool(type: type, index: index, appTarget: .all)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@objc extension NSWindowController {
|
|
|
+ private static var _eventNameKey = "KMEventNameKey"
|
|
|
+ var kEventName: String? {
|
|
|
+ get {
|
|
|
+ return objc_getAssociatedObject(self, &Self._eventNameKey) as? String
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ objc_setAssociatedObject(self, &Self._eventNameKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static var _eventParamsKey = "KMEventParamsKey"
|
|
|
+ var kEventParams: [String : Any]? {
|
|
|
+ get {
|
|
|
+ return objc_getAssociatedObject(self, &Self._eventParamsKey) as? [String : Any]
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ objc_setAssociatedObject(self, &Self._eventParamsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func saveEventName(_ eventN: String?) {
|
|
|
+ self.kEventName = eventN
|
|
|
+ self.kEventParams = KMGetBuyNowEventParams(for: eventN)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func trackEvent_buyNow_click(eventName eveN: String, params: [String : Any]?) {
|
|
|
+ KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: .firebase, appTarget: .dmg)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func trackEvent() {
|
|
|
+ if let e = self.kEventName {
|
|
|
+ KMAnalytics.trackEvent(eventName: e, parameters: self.kEventParams, platform: .firebase, appTarget: .all)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func trackEvent_dmg() {
|
|
|
+ if let e = self.kEventName {
|
|
|
+ KMAnalytics.trackEvent(eventName: e, parameters: self.kEventParams, platform: .firebase, appTarget: .dmg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func trackEvent_appStore() {
|
|
|
+ if let e = self.kEventName {
|
|
|
+ KMAnalytics.trackEvent(eventName: e, parameters: self.kEventParams, platform: .firebase, appTarget: [.free, .pro])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - KMAnalytics Private Methods
|
|
|
+
|
|
|
+extension KMAnalytics {
|
|
|
+ fileprivate static func _trackEvent_buyNow_tool(type: CAnnotationType, index: Int, platform: KMAnalyticsPlatform = .firebase, appTarget: AppTarget = [.free]) {
|
|
|
+ if let eventName = KMBuyNowEventNameFromCAnnotationType(type, index: index) {
|
|
|
+ let params: [String : Any]? = [KMAnalytics.Parameter.categoryKey : "Purchase_Tools", KMAnalytics.Parameter.labelKey : "SubTbr_Tools"]
|
|
|
+ KMAnalytics.trackEvent(eventName: eventName, parameters: params, platform: platform, appTarget: appTarget)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Pulick Methods
|
|
|
+
|
|
|
+public func KMBuyNowEventNameFromCAnnotationType(_ type: CAnnotationType, index: Int) -> String? {
|
|
|
+ if type == .link {
|
|
|
+ if index == 2 {
|
|
|
+ return "Reading_WebsiteLink_BuyNow"
|
|
|
+ } else if index == 3 {
|
|
|
+ return "Reading_EmailLink_BuyNow"
|
|
|
+ }
|
|
|
+ } else if type == .stamp {
|
|
|
+ if index == 2 {
|
|
|
+ return "Reading_DynamicStamp_BuyNow"
|
|
|
+ } else if index == 3 {
|
|
|
+ return "Reading_CustomStamp_BuyNow"
|
|
|
+ }
|
|
|
+ } else if type == .signature {
|
|
|
+ return "Reading_Signature_BuyNow"
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+public func KMGetBuyNowEventParams(for eventN: String?) -> [String : Any]? {
|
|
|
+ guard let eveN = eventN else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if eveN == "Reading_WebsiteLink_BuyNow" || eveN == "Reading_EmailLink_BuyNow" ||
|
|
|
+ eveN == "Reading_DynamicStamp_BuyNow" || eveN == "Reading_CustomStamp_BuyNow" ||
|
|
|
+ eveN == "Reading_Signature_BuyNow" || eveN == "Reading_Table_BuyNow" {
|
|
|
+ return ["Purchase_Tools" : "SubTbr_Tools"]
|
|
|
+ } else if eveN == "Reading_InsertBlankPage_BuyNow" || eveN == "Reading_InsertPDF_BuyNow" ||
|
|
|
+ eveN == "Reading_InsertSacnner_BuyNow" || eveN == "Reading_InsertImage_BuyNow" || eveN == "Reading_InsertClipboard_BuyNow" ||
|
|
|
+ eveN == "Reading_Replace_BuyNow" || eveN == "Reading_Extract_BuyNow" || eveN == "Reading_Split_BuyNow" ||
|
|
|
+ eveN == "Reading_Rotate_BuyNow" || eveN == "Reading_Reverse_BuyNow" || eveN == "Reading_Copy_BuyNow" ||
|
|
|
+ eveN == "Reading_Delete_BuyNow" || eveN == "Reading_Merge_BuyNow" {
|
|
|
+ return ["Purchase_PageEdit" : "SubTbr_PageEdit"]
|
|
|
+ } else if eveN == "Onbrd_EditPage_BuyNow" || eveN == "Onbrd_Merge_BuyNow" {
|
|
|
+ return ["Purchase_PageEdit" : "Home_PageEdit"]
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|