// // 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" //} @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) } } private static var _eventTagKey = "KMEventTagKey" var kEventTag: Int { get { return objc_getAssociatedObject(self, &Self._eventTagKey) as? Int ?? 0 } set { objc_setAssociatedObject(self, &Self._eventTagKey, newValue, .OBJC_ASSOCIATION_ASSIGN) } } @objc func trackEvent_buyNow_tool(type: CAnnotationType, index: Int) { // KMAnalytics._trackEvent_buyNow_tool(type: type, index: index, appTarget: .all) } // MARK: - Track Events Basic // @objc func trackEvent(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) { // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .all) // } // @objc func trackEvent_dmg(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) { // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .dmg) // } // @objc func trackEvent_free(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) { // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .free) // } // @objc func trackEvent_pro(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) { // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: .pro) // } // @objc func trackEvent_appstore(eventName eveN: String, params: [String : Any]?, platform: KMAnalyticsPlatform) { // KMAnalytics.trackEvent(eventName: eveN, parameters: params, platform: platform, appTarget: [.free, .pro]) // } func clearEventData() { self.kEventName = nil self.kEventTag = 0 self.kEventParams = nil } } @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) } } private static var _eventTagKey = "KMEventTagKey" var kEventTag: Int { get { return objc_getAssociatedObject(self, &Self._eventTagKey) as? Int ?? 0 } set { objc_setAssociatedObject(self, &Self._eventTagKey, newValue, .OBJC_ASSOCIATION_ASSIGN) } } // MARK: - Track Events Basic // @objc func trackEvent(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) { // if let data = eveN { // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .all) // } // } // // @objc func trackEvent_dmg(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) { // if let data = eveN { // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .dmg) // } // } // // @objc func trackEvent_free(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) { // if let data = eveN { // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .free) // } // } // // @objc func trackEvent_pro(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) { // if let data = eveN { // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: .pro) // } // } // // @objc func trackEvent_appstore(eventName eveN: String?, params: [String : Any]?, platform: KMAnalyticsPlatform) { // if let data = eveN { // KMAnalytics.trackEvent(eventName: data, parameters: params, platform: platform, appTarget: [.free, .pro]) // } // } func clearEventData() { self.kEventName = nil self.kEventTag = 0 self.kEventParams = nil } } // 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 }