Browse Source

【埋点】埋点工具类编写

tangchao 1 year ago
parent
commit
4c77ed0c67

+ 22 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -2294,6 +2294,10 @@
 		BB2F615B2966B69D001CB369 /* KMWatermarkPropertyHomeController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB2F61572966B69D001CB369 /* KMWatermarkPropertyHomeController.xib */; };
 		BB2F615C2966B69D001CB369 /* KMWatermarkPropertyHomeController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB2F61572966B69D001CB369 /* KMWatermarkPropertyHomeController.xib */; };
 		BB2F615D2966B69D001CB369 /* KMWatermarkPropertyHomeController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB2F61572966B69D001CB369 /* KMWatermarkPropertyHomeController.xib */; };
+		BB32BF232A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
+		BB32BF242A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
+		BB32BF252A5EA05900D11348 /* KMAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB32BF222A5EA05900D11348 /* KMAnalytics.swift */; };
+		BB32BF272A5EB12C00D11348 /* AppCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F00CCC22A2F2E2300AC462E /* AppCenter.framework */; };
 		BB332D532995D8B500CABB58 /* KMCloudDocumentTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB332D522995D8B500CABB58 /* KMCloudDocumentTools.swift */; };
 		BB332D542995D8B500CABB58 /* KMCloudDocumentTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB332D522995D8B500CABB58 /* KMCloudDocumentTools.swift */; };
 		BB332D552995D8B500CABB58 /* KMCloudDocumentTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB332D522995D8B500CABB58 /* KMCloudDocumentTools.swift */; };
@@ -4496,6 +4500,7 @@
 		BB2F614F2966A91D001CB369 /* KMBackgroundPropertyHomeController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMBackgroundPropertyHomeController.xib; sourceTree = "<group>"; };
 		BB2F61562966B69D001CB369 /* KMWatermarkPropertyHomeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMWatermarkPropertyHomeController.swift; sourceTree = "<group>"; };
 		BB2F61572966B69D001CB369 /* KMWatermarkPropertyHomeController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMWatermarkPropertyHomeController.xib; sourceTree = "<group>"; };
+		BB32BF222A5EA05900D11348 /* KMAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMAnalytics.swift; sourceTree = "<group>"; };
 		BB332D522995D8B500CABB58 /* KMCloudDocumentTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCloudDocumentTools.swift; sourceTree = "<group>"; };
 		BB35C4972974E18C00D46EE2 /* CustomAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAlertView.h; sourceTree = "<group>"; };
 		BB35C4982974E18D00D46EE2 /* CustomAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomAlertView.m; sourceTree = "<group>"; };
@@ -5013,6 +5018,7 @@
 				9F00CF5E2A386B8000AC462E /* libsqlite3.0.tbd in Frameworks */,
 				89752DAB2936ECED003FF08E /* Masonry.framework in Frameworks */,
 				9F00CF7D2A386DC500AC462E /* GoogleAppMeasurementIdentitySupport.framework in Frameworks */,
+				BB32BF272A5EB12C00D11348 /* AppCenter.framework in Frameworks */,
 				9F00CF5C2A386B3F00AC462E /* SystemConfiguration.framework in Frameworks */,
 				ADA08A8429F1430E009B2A7B /* ComPDFKit.framework in Frameworks */,
 				BB9DCC862A09FC760024A6F1 /* libDocumentAI.dylib in Frameworks */,
@@ -7911,6 +7917,7 @@
 		BB2C6A7128F2652500478A33 /* Class */ = {
 			isa = PBXGroup;
 			children = (
+				BB32BF212A5EA02900D11348 /* Analytics */,
 				ADE8BC3629F9453A00570F89 /* KMAdvertisement */,
 				BB9807F829CA93A900BEEB81 /* Welcome */,
 				BB135C2629B6CD4500FD5965 /* Common */,
@@ -8045,6 +8052,14 @@
 			path = Base;
 			sourceTree = "<group>";
 		};
+		BB32BF212A5EA02900D11348 /* Analytics */ = {
+			isa = PBXGroup;
+			children = (
+				BB32BF222A5EA05900D11348 /* KMAnalytics.swift */,
+			);
+			path = Analytics;
+			sourceTree = "<group>";
+		};
 		BB332D512995D8A100CABB58 /* Tools */ = {
 			isa = PBXGroup;
 			children = (
@@ -11009,6 +11024,7 @@
 				89E4E75A296429CF002DBA6F /* NSShadow_SKExtensions.m in Sources */,
 				8942F7F02926087200389627 /* KMSearchViewController.swift in Sources */,
 				89E4E7282963FB74002DBA6F /* KMPropertiesViewPopController.m in Sources */,
+				BB32BF232A5EA05900D11348 /* KMAnalytics.swift in Sources */,
 				BB86C21428F560D1005AD968 /* NSGraphics_SKExtensions.m in Sources */,
 				9F1FE4AE29406E4700E952CA /* CTPresentationModeController.m in Sources */,
 				BB146FC0299DC0D100784A6A /* GTMSessionFetcherLogging.m in Sources */,
@@ -11470,6 +11486,7 @@
 				BBC3484B2958222C008D2CD1 /* KMBackgroundOutsideView.swift in Sources */,
 				ADBC2CFB299CA6B9006280C8 /* KMPrintDuplexPrintingSetView.swift in Sources */,
 				BBA19F4429ADE6A3001A285A /* KMBookMarkRowView.swift in Sources */,
+				BB32BF242A5EA05900D11348 /* KMAnalytics.swift in Sources */,
 				BB86C21F28F561F8005AD968 /* SKRuntime.m in Sources */,
 				ADC075E2298766D9006C752F /* KMBatchConverPDFImageView.swift in Sources */,
 				BB89723B294B3C840045787C /* KMWatermarkPropertyController.swift in Sources */,
@@ -12427,6 +12444,7 @@
 				BB7F7BF929AA469F00A3E4E7 /* KMSigntureViewItem.m in Sources */,
 				BBFE6E772930E53000142C01 /* KMMergePopoverViewController.swift in Sources */,
 				ADF6B8782A48155E0090CB78 /* KMComparativeViewCollectionItem.swift in Sources */,
+				BB32BF252A5EA05900D11348 /* KMAnalytics.swift in Sources */,
 				89E4E7102963D62C002DBA6F /* KMAnnotationFontWindowController.m in Sources */,
 				AD9527C0295294E20039D2BC /* KMPrintPageModel.swift in Sources */,
 				BBB14A6529792D6900936EDB /* KMRedactPageRangeContentView.swift in Sources */,
@@ -13289,6 +13307,7 @@
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
+					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library",
 				);
 				GCC_C_LANGUAGE_STANDARD = gnu99;
 				GCC_PREPROCESSOR_DEFINITIONS = (
@@ -13376,6 +13395,7 @@
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
+					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library",
 				);
 				GCC_C_LANGUAGE_STANDARD = gnu99;
 				GCC_PREPROCESSOR_DEFINITIONS = "VERSION_FREE=1";
@@ -13550,6 +13570,7 @@
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
+					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library",
 				);
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"DEBUG=1",
@@ -13672,6 +13693,7 @@
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
 					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library/FirebaseAnalytics",
+					"$(PROJECT_DIR)/PDF\\ Master/Third\\ Pard\\ Library",
 				);
 				GCC_PREPROCESSOR_DEFINITIONS = "VERSION_PRO=1";
 				GENERATE_INFOPLIST_FILE = YES;

+ 22 - 6
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -228,12 +228,12 @@
             landmarkType = "7">
             <Locations>
                <Location
-                  uuid = "0351AA9B-986E-4553-8685-5A71EE4771C2 - d6a94eca6fc0bdfa"
+                  uuid = "0351AA9B-986E-4553-8685-5A71EE4771C2 - 4b4b5d6e3d195f59"
                   shouldBeEnabled = "Yes"
                   ignoreCount = "0"
                   continueAfterRunningActions = "No"
-                  symbolName = "PDF_Master.KMMainDocument.runModalSavePanel(for: __C.NSSaveOperationType, delegate: Swift.Optional&lt;Any&gt;, didSave: Swift.Optional&lt;ObjectiveC.Selector&gt;, contextInfo: Swift.Optional&lt;Swift.UnsafeMutableRawPointer&gt;) -&gt; ()"
-                  moduleName = "PDF Master"
+                  symbolName = "PDF_Master_DMG.KMMainDocument.runModalSavePanel(for: __C.NSSaveOperationType, delegate: Swift.Optional&lt;Any&gt;, didSave: Swift.Optional&lt;ObjectiveC.Selector&gt;, contextInfo: Swift.Optional&lt;Swift.UnsafeMutableRawPointer&gt;) -&gt; ()"
+                  moduleName = "PDF Master DMG"
                   usesParentBreakpointCondition = "Yes"
                   urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/Document/KMMainDocument.swift"
                   startingColumnNumber = "9223372036854775807"
@@ -243,12 +243,12 @@
                   offsetFromSymbolStart = "312">
                </Location>
                <Location
-                  uuid = "0351AA9B-986E-4553-8685-5A71EE4771C2 - 6fe9b9739f2693c9"
+                  uuid = "0351AA9B-986E-4553-8685-5A71EE4771C2 - 9ec3d8f8f83c7231"
                   shouldBeEnabled = "Yes"
                   ignoreCount = "0"
                   continueAfterRunningActions = "No"
-                  symbolName = "closure #1 (Swift.Bool, Any...) -&gt; () in PDF_Master.KMMainDocument.runModalSavePanel(for: __C.NSSaveOperationType, delegate: Swift.Optional&lt;Any&gt;, didSave: Swift.Optional&lt;ObjectiveC.Selector&gt;, contextInfo: Swift.Optional&lt;Swift.UnsafeMutableRawPointer&gt;) -&gt; ()"
-                  moduleName = "PDF Master"
+                  symbolName = "closure #1 (Swift.Bool, Any...) -&gt; () in PDF_Master_DMG.KMMainDocument.runModalSavePanel(for: __C.NSSaveOperationType, delegate: Swift.Optional&lt;Any&gt;, didSave: Swift.Optional&lt;ObjectiveC.Selector&gt;, contextInfo: Swift.Optional&lt;Swift.UnsafeMutableRawPointer&gt;) -&gt; ()"
+                  moduleName = "PDF Master DMG"
                   usesParentBreakpointCondition = "Yes"
                   urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/Document/KMMainDocument.swift"
                   startingColumnNumber = "9223372036854775807"
@@ -276,5 +276,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "59335A18-F711-4900-89F0-470D80336276"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/Analytics/KMAnalytics.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "88"
+            endingLineNumber = "88"
+            landmarkName = "trackEvent(eventName:parameters:platform:appTarget:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 1 - 12
PDF Office/PDF Master/AppDelegate.swift

@@ -7,13 +7,6 @@
 
 import Cocoa
 import KMAdvertisement
-#if VERSION_DMG
-import AppCenter
-import AppCenterAnalytics
-import AppCenterCrashes
-#endif
-import FirebaseCore
-import FirebaseAnalytics
 
 @main
 class AppDelegate: NSObject, NSApplicationDelegate {
@@ -71,11 +64,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
                 
         // 初版不支持暗黑模式
         NSApp.appearance = NSAppearance(named: .aqua)
-              
-#if VERSION_DMG
-        AppCenter.start(withAppSecret: appSecret, services: [Analytics.self, Crashes.self])
-#endif
-        FirebaseApp.configure()
+        KMAnalytics.configure()
 //        Analytics.logEvent(AnalyticsEventSignUp, parameters: [
 //          AnalyticsParameterMethod: "method"
 //          ])

+ 122 - 0
PDF Office/PDF Master/Class/Analytics/KMAnalytics.swift

@@ -0,0 +1,122 @@
+//
+//  KMAnalytics.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/7/12.
+//
+
+import Cocoa
+#if VERSION_DMG
+import AppCenter
+import AppCenterAnalytics
+import AppCenterCrashes
+#endif
+import FirebaseCore
+import FirebaseAnalytics
+
+@objc enum KMAnalyticsPlatform: Int {
+    case AppCenter
+    case firebase
+}
+
+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"
+}
+
+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 {
+
+    }
+    
+    // 配置
+    static func configure() {
+#if VERSION_DMG
+        var appSecret = "416b8e45-69bd-4a16-8fec-b5206e913c4a"
+        AppCenter.start(withAppSecret: appSecret, services: [Analytics.self, Crashes.self])
+#endif
+        FirebaseApp.configure()
+        
+        #if DEBUG
+        var newArguments = ProcessInfo.processInfo.arguments
+        newArguments.append("-FIRDebugEnabled")
+        ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")
+        #endif
+    }
+
+    // plat
+    static func trackEvent(eventName: String, parameters: [String : Any]? = nil, platform: KMAnalyticsPlatform = .firebase, appTarget: AppTarget = [.free]) {
+        if (appTarget.contains(.free)) {
+#if VERSION_FREE
+            if (platform == .firebase) {
+                Analytics.logEvent(eventName, parameters: parameters)
+            } else if (platform == .AppCenter) {
+                if let data = parameters as? [String : String] {
+                    Analytics.trackEvent(eventName, withProperties: data)
+                }
+            }
+#endif
+        }
+        if (appTarget.contains(.pro)) {
+#if VERSION_PRO
+            if (platform == .firebase) {
+                Analytics.logEvent(eventName, parameters: parameters)
+            } else if (platform == .AppCenter) {
+                if let data = parameters as? [String : String] {
+                    Analytics.trackEvent(eventName, withProperties: data)
+                }
+            }
+#endif
+        }
+        if (appTarget.contains(.dmg)) {
+#if VERSION_DMG
+            if (platform == .firebase) {
+                Analytics.logEvent(eventName, parameters: parameters)
+            } else if (platform == .AppCenter) {
+                if let data = parameters as? [String : String] {
+                    Analytics.trackEvent(eventName, withProperties: data)
+                }
+            }
+#endif
+        }
+    }
+}

+ 5 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2283,6 +2283,11 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
 //
 //            }
         }
+        if (type == .Annatiton) {
+            KMAnalytics.trackEvent(eventName: "Btn_Tbr_Annotation", parameters: [
+                KMAnalytics.Parameter.categoryKey : KMAnalytics.Parameter.Category.tbr,
+                KMAnalytics.Parameter.labelKey : KMAnalytics.Parameter.Label.tbr_Btn], platform: .AppCenter, appTarget: .dmg)
+        }
         
         if(type != .Page) {
             if (hasEnterPageEdit()) {