QSLCentralEventManager.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // QSLCentralEventManager.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/10/13.
  6. //
  7. import Foundation
  8. import UIKit
  9. import AppTrackingTransparency
  10. import AdSupport
  11. import StoreKit
  12. import AdServices
  13. class QSLCentralEventManager {
  14. // 中台
  15. static let centralUrl = "https://project-api.atmob.com"
  16. static let appKey = "a3794176067047728826578522a34e5f"
  17. static let bundleId = "com.manbu.shouji"
  18. static let event_push = "/central/open/v1/event/push"
  19. static let ssid_detail = "/central/open/v1/ssid/detail"
  20. static let shared = QSLCentralEventManager()
  21. private init() {}
  22. }
  23. extension QSLCentralEventManager {
  24. func uploadEvent(eventType: String, eventName: String, eventProps: [String:Any]) {
  25. let timestamp = Int(Date.milliStamp) ?? 0
  26. var currentPropos = eventProps;
  27. currentPropos["$snid"] = QSLDeviceTool.shared.sessionId
  28. baseEventUpload(param: ["ak":QSLCentralEventManager.appKey,"cp":baseDic(),"ft":timestamp, "es":[["ti":timestamp, "ty":eventType, "ev":eventName,"pr":currentPropos]]])
  29. }
  30. func uploadEvent(eventType: String, eventName: String, eventPropsArr: [[String:Any]]) {
  31. let timestamp = Int(Date.milliStamp) ?? 0
  32. baseEventUpload(param: ["ak":QSLCentralEventManager.appKey,"cp":baseDic(),"ft":timestamp, "es":eventPropsArr])
  33. }
  34. func baseDic() -> [String:Any]{
  35. // 获取包名
  36. var bundleId = QSLCentralEventManager.bundleId
  37. if let bundleIdentifier = Bundle.main.bundleIdentifier {
  38. bundleId = bundleIdentifier
  39. }
  40. var cpDict : [String : Any] = ["$aplf":2, "$chnl":"Appstore"]
  41. cpDict["$pkg"] = bundleId
  42. cpDict["$aver"] = QSLDeviceTool.shared.appVersionName
  43. cpDict["$avec"] = QSLDeviceTool.shared.appVersionCode
  44. cpDict["$modl"] = QSLDeviceTool.shared.phoneModel
  45. cpDict["$osv"] = QSLDeviceTool.shared.OSVersion
  46. cpDict["$idfa"] = QSLDeviceTool.shared.idfa
  47. cpDict["$idfv"] = QSLDeviceTool.shared.idfv
  48. return cpDict
  49. }
  50. func baseEventUpload(param: [String:Any]) {
  51. QSLCentralNetwork().request(.eventPush(dict: param)) { response in
  52. debugPrint("上报事件成功")
  53. } fail: { code, error in
  54. debugPrint("上报事件失败")
  55. }
  56. }
  57. }