123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //
- // KMAnalytics.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/7/12.
- //
- import Cocoa
- import AppCenter
- import AppCenterAnalytics
- import AppCenterCrashes
- import FirebaseCore
- import FirebaseAnalytics
- // 数据埋点 平台
- @objc enum KMAnalyticsPlatform: Int {
- case AppCenter
- case firebase
- }
- // 数据埋点 Category 参数
- extension KMAnalytics.Parameter.Category {
- public static let tbr = "Tbr"
- public static let subTbr_annotation = "SubTbr_Annotation"
- public static let subTbr_editPDF = "SubTbr_EditPDF"
- public static let subTbr_PageEdit = "SubTbr_PageEdit"
- public static let subTbr_Converter = "SubTbr_Converter"
- public static let subTbr_Tools = "SubTbr_Tools"
- public static let home = "Home"
- public static let leftSideBar = "LeftSideBar"
- public static let puw = "PUW"
- }
- // 数据埋点 Label 参数
- extension KMAnalytics.Parameter.Label {
- public static let tbr_Btn = "Tbr_Btn"
-
- public static let subTbr_Btn = "SubTbr_Btn"
- public static let ai_Btn = "AI_Btn"
- public static let create_Btn = "Create_Btn"
- public static let leftSideBar_Btn = "LeftSideBar_Btn"
- public static let sub_PUW = "Sub_PUW"
- }
- // 数据埋点 参数
- extension KMAnalytics.Parameter {
- public static let categoryKey = "Category"
- public static let labelKey = "Label"
-
- public struct Category {
-
- }
-
- public struct Label {
-
- }
- }
- // 数据埋点 工具类
- @objc class KMAnalytics: NSObject {
- public struct AppTarget: OptionSet, Codable {
- let rawValue: Int
-
- public static var free = AppTarget(rawValue: 1 << 0)
- public static var pro = AppTarget(rawValue: 1 << 1)
- public static var dmg = AppTarget(rawValue: 1 << 2)
- public static var all: AppTarget = [.free, .pro, .dmg]
- }
-
- public struct Parameter {
- }
-
- public static let Category = KMAnalytics.Parameter.Category.self
- public static let Label = KMAnalytics.Parameter.Label.self
-
- // 配置
- static func configure() {
- #if DEBUG
- #if VERSION_FREE
- #if VERSION_DMG
- let appSecret = "fb9d37aa-e3f2-4969-bd06-f65ce529a565"
- #else
- let appSecret = "8c08296d-ca5c-44da-b68a-b4382f119b1f"
- #endif
- #else
- let appSecret = "54212f10-3ac9-42d9-96c0-5387f4b78d30"
- #endif
- AppCenter.start(withAppSecret: appSecret, services: [Analytics.self, Crashes.self])
- #else
- // #if VERSION_DMG
- // AppCenter.start(withAppSecret: "416b8e45-69bd-4a16-8fec-b5206e913c4a", services: [Analytics.self, Crashes.self])
- // #else
- // AppCenter.start(withAppSecret: "f0d082d0-9581-458c-9069-7aaf0a2b0a8c", services: [Analytics.self, Crashes.self])
- // #endif
- #if VERSION_FREE
- #if VERSION_DMG
- let appSecret = "fb9d37aa-e3f2-4969-bd06-f65ce529a565"
- #else
- let appSecret = "8c08296d-ca5c-44da-b68a-b4382f119b1f"
- #endif
- #else
- let appSecret = "54212f10-3ac9-42d9-96c0-5387f4b78d30"
- #endif
- AppCenter.start(withAppSecret: appSecret, services: [Analytics.self, Crashes.self])
- #endif
- // let version = AppCenter.sdkVersion
- // KMPrint("AppCenter version is \(version)")
- FirebaseApp.configure()
- // Analytics.logEvent(AnalyticsEventSignUp, parameters: [
- // AnalyticsParameterMethod: "method"
- // ])
-
- #if DEBUG
- // var newArguments = ProcessInfo.processInfo.arguments
- // newArguments.append("-FIRDebugEnabled")
- // ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
- #endif
- }
- // 发送事件
- static func trackEvent(eventName: String, parameters: [String : Any]? = nil, platform: KMAnalyticsPlatform = .firebase, appTarget: AppTarget = [.free]) {
- // Swift.debugPrint("trackEvent: \(eventName)")
-
- if (appTarget.contains(.free)) {
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
- #endif
- #endif
- }
- if (appTarget.contains(.pro)) {
- #if VERSION_FREE
- #else
- self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
- #endif
- }
- if (appTarget.contains(.dmg)) {
- #if VERSION_DMG
- self._trackEvent(eventName: eventName, parameters: parameters, platform: platform)
- #endif
- }
- }
-
- // MARK: - Private Methods
- // 发送事件
- fileprivate static func _trackEvent(eventName: String, parameters: [String : Any]? = nil, platform: KMAnalyticsPlatform = .firebase) {
- if (platform == .firebase) {
- Analytics.logEvent(eventName, parameters: parameters)
- } else if (platform == .AppCenter) {
- if let data = parameters as? [String : String] {
- Analytics.trackEvent(eventName, withProperties: data)
- }
- }
- }
- }
|