Przeglądaj źródła

1.add appLaunch report

wenweiwei 3 lat temu
rodzic
commit
ff22181edb

+ 16 - 0
BFAnalyzeKit/Classes/BFAnalyzeFunc.swift

@@ -21,6 +21,22 @@ public func bf_dictionaryToJsonString(_ dic: [String: Any]) -> String? {
     return str
 }
 
+// MARK: 字符串转字典
+
+public func bf_jsonStringToDictionary(_ str: String) -> [String: Any]? {
+    if str.count <= 0 {
+        return [:]
+    }
+    let data = str.data(using: String.Encoding.utf8)
+    if data == nil || (data?.count ?? 0) <= 0 {
+        return [:]
+    }
+    if let dict = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any] {
+        return dict
+    }
+    return [:]
+}
+
 /// 数组转为string
 /// - Parameter array: <#array description#>
 /// - Returns: <#description#>

+ 48 - 0
BFAnalyzeKit/Classes/BFBaseEventTrack.swift

@@ -289,4 +289,52 @@ public class BFBaseEventTrack: NSObject {
             }
         }
     }
+
+    /// 冷热启动数据上报
+    /// - Parameters:
+    ///   - url: 上报地址
+    ///   - isFirstLaunch: 是否是第一次安装 1-是 0-否
+    ///   - firstParams: 第一次启动未上报数据
+    ///   - isHotLaunch: 是否是热启动
+    ///   - launchType:启动类型
+    ///   - commandLaunchParams: 剪切板数据
+    ///   - commandReportParams: 剪切板上报数据
+    ///   - params: <#params description#>
+    ///   - eventData: <#eventData description#>
+    ///   - extParams: <#extParams description#>
+    ///   - commonParams: <#commonParams description#>
+    public class func appLaunchReportUpload(url: String, isFirstLaunch: Int = 1, firstParams: [String: Any]? = nil, isHotLaunch: Bool = false, launchType: String = "userActiveOpen", commandLaunchParams: [String: Any]? = nil, commandReportParams: [String: Any]? = nil, params: [String: Any]? = nil, eventData _: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]?) {
+        DispatchQueue.global().async {
+            var params: [String: Any] = params ?? [:]
+            params["LogType"] = "60"
+            // 参数
+            var extParams: [String: Any] = Dictionary<String, Any>.init()
+            extParams["downloadChannel"] = "AppStore"
+            if commandLaunchParams != nil {
+                extParams["launchParams"] = commandLaunchParams!
+            }
+            if commandReportParams != nil {
+                for (key, value) in commandReportParams!.reversed() {
+                    extParams[key] = value
+                }
+            }
+            if !isHotLaunch {
+                extParams["coldLaunchType"] = launchType
+            } else {
+                extParams["hotLaunchType"] = launchType
+            }
+            // 是否第一次安装
+            extParams["isFirstLaunch"] = isFirstLaunch
+            params["extParams"] = bf_dictionaryToJsonString(extParams)
+            // 第一次未启动数据
+            if isFirstLaunch == 1, firstParams != nil, (firstParams?.keys.count ?? 0) > 0 {
+                for (key, value) in firstParams!.reversed() {
+                    params[key] = value
+                }
+            }
+            BFNetRequestAdaptor.postRequestData(url: url, parames: params, commonParams: commonParams) { response, _, error, _ in
+                BFLog(message: "冷热启动上报:\(String(describing: error)),\(response ?? [:]),params = \(params)")
+            }
+        }
+    }
 }

+ 11 - 71
BFAnalyzeKit/Classes/BFEventTrackAdaptor.swift

@@ -156,78 +156,18 @@ public class BFEventTrackAdaptor: NSObject {
         }
     }
 
-    /// 冷热启动数据上报
+    
+    /// app冷热启动上报
     /// - Parameters:
-    ///   - isHotLaunch 是否是热启动
-    ///   - logType: <#logType description#>
-    ///   - eventId: <#eventId description#>
-    ///   - eventData: <#eventData description#>
-    ///   - extParams: <#extParams description#>
-    ///   - pageSource: <#pageSource description#>
-    /// - Returns: <#description#>
-//     class public func reportStatisticsUpload(isHotLaunch: Bool = false, logType: statisticsLogType, coldLaunchType _: coldLaunchType = .coldLaunchType_userActiveOpen, eventId _: String?, eventData _: String?, pageSource: PAGESOURCE?) {
-//        DispatchQueue.global().async {
-//            var params: [String: Any] = ["LogType": logType.rawValue]
-//            if PQSingletoMemoryUtil.shared.isColdLaunch {
-//                // 1-请求中 2-请求成功 3-请求失败
-//                if PQSingletoMemoryUtil.shared.coldLaunchStatus != 2 {
-//                    PQSingletoMemoryUtil.shared.coldLaunchStatus = 1
-//                } else {
-//                    return
-//                }
-//            }
-//            params["eventData"] = dictionaryToJsonString(["tabIndex": PQSingletoMemoryUtil.shared.selectedTabIndex ?? "categoryTab"])
-//            // 参数
-//            var extParams: [String: Any] = Dictionary<String, Any>.init()
-//            extParams["downloadChannel"] = channelID
-//            extParams["launchParams"] = PQSingletoMemoryUtil.shared.commandLaunchParams
-//            if pageSource?.rawValue.contains("speedApp-category") ?? false {
-//                params["pageCategoryId"] = 55
-//            }
-//            if PQSingletoMemoryUtil.shared.commandReportParams != nil {
-//                for (key, value) in PQSingletoMemoryUtil.shared.commandReportParams!.reversed() {
-//                    extParams[key] = value
-//                }
-//            }
-//            if !isHotLaunch {
-//                extParams["coldLaunchType"] = (PQSingletoMemoryUtil.shared.coldLaunchType ?? .coldLaunchType_userActiveOpen).rawValue
-//            } else {
-//                extParams["hotLaunchType"] = (PQSingletoMemoryUtil.shared.coldLaunchType ?? .coldLaunchType_userActiveOpen).rawValue
-//            }
-//            if pageSource != nil {
-//                params["pageSource"] = pageSource!.rawValue
-//            }
-//            // 是否第一次安装
-//            let firstInstall: String? = getUserDefaults(key: cFirstInstall) as? String
-//            if firstInstall == nil || (firstInstall?.count ?? 0 <= 0) || firstInstall != "1" {
-//                extParams["isFirstLaunch"] = 1
-//            } else {
-//                extParams["isFirstLaunch"] = 0
-//            }
-//            params["extParams"] = dictionaryToJsonString(extParams)
-//            // 是否第一次安装
-//            let firstParams: String? = getUserDefaults(key: cFirstParams) as? String
-//            if (firstInstall == nil || firstInstall?.count ?? 0 <= 0 || firstInstall != "1") && (firstParams != nil && ((firstParams?.count ?? 0) > 0)) {
-//                params = jsonStringToDictionary(firstParams!) ?? Dictionary<String, Any>.init()
-//            }
-//            if firstParams == nil || ((firstParams?.count ?? 0) <= 0) {
-//                saveUserDefaults(key: cFirstParams, value: dictionaryToJsonString(params) ?? "")
-//            }
-//            BFNetRequestAdaptor.postRequestData(url: PQENVUtil.shared.commonapi + staticsFrontendReportUrl, parames: params,commonParams: commonParams()) { response, _, error, _ in
-//                BFLog(message: "冷热启动上报:\(String(describing: error)),\(response ?? [:]),params = \(params)")
-//                if PQSingletoMemoryUtil.shared.isColdLaunch {
-//                    PQSingletoMemoryUtil.shared.coldLaunchStatus = error == nil ? 2 : 3
-//                }
-//                // 清空启动数据
-//                PQSingletoMemoryUtil.shared.coldLaunchType = nil
-//                if error == nil, firstInstall == nil || firstInstall?.count ?? 0 <= 0 || firstInstall != "1" {
-//                    saveUserDefaults(key: cFirstInstall, value: "1")
-//                }
-//                saveUserDefaults(key: cSelectedTabIndex, value: "categoryTab")
-//            }
-//        }
-//    }
-//
+    ///   - isFirstLaunch: <#isFirstLaunch description#>
+    ///   - firstParams: <#firstParams description#>
+    ///   - isHotLaunch: <#isHotLaunch description#>
+    ///   - launchType: <#launchType description#>
+    ///   - commonParams: <#commonParams description#>
+    class public func appLaunchReportUpload(isFirstLaunch: Int = 1, firstParams: [String: Any]? = nil, isHotLaunch: Bool = false, launchType: String = "userActiveOpen", commonParams: [String: Any]?) {
+        BFBaseEventTrack.appLaunchReportUpload(url: PQENVUtil.shared.commonapi + staticsFrontendReportUrl, isFirstLaunch: isFirstLaunch, firstParams: firstParams, isHotLaunch: isHotLaunch, launchType: launchType, commonParams: commonParams)
+    }
+
     /// 推送点击数据上报
     /// - Parameters:
     ///   - pushId: 推送Id

+ 1 - 1
Example/Podfile

@@ -6,7 +6,7 @@ target 'BFAnalyzeKit_Example' do
   source 'https://git.yishihui.com/iOS/BFSpecs.git'
   source 'https://github.com/CocoaPods/Specs.git'
   
-  pod 'BFAnalyzeKit', :path => '../'
+  pod 'BFAnalyzeKit',           :path => '../'
   pod 'BFCommonKit',            :path => '../../../BFCommonKit/Trunk'
   pod 'BFNetRequestKit',        :path => '../../../BFNetRequestKit/Trunk'