123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // 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
- }
|