BFEventTrackAdaptor.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //
  2. // BFEventTrackAdaptor.swift
  3. // BFAnalyzeKit
  4. //
  5. // Created by SanW on 2021/12/10.
  6. //
  7. import BFCommonKit
  8. import BFNetRequestKit
  9. import UIKit
  10. public class BFEventTrackAdaptor: NSObject {
  11. /// 基础埋点上报
  12. /// - Parameters:
  13. /// - logType: 数据库类型
  14. /// - businessType: businessType
  15. /// - objectType: objectType
  16. /// - eventData: eventData
  17. /// - pageSource: 页面场景
  18. /// - extParams: extParams 扩展字段,为json对象
  19. /// - remindmsg: remindmsg 打印提示信息
  20. /// - Returns: <#description#>
  21. public class func baseReportUpload(logType: statisticsLogType = .st_log_type_simpleevent, businessType: businessType?, objectType: objectType?, pageSource: PAGESOURCE?, params: [String: Any]? = nil, eventData: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]?) {
  22. BFBaseEventTrack.bf_frontendReportUpload(url: PQENVUtil.shared.commonapi + staticsFrontendReportUrl, logType: logType.rawValue, businessType: businessType?.rawValue, objectType: objectType?.rawValue, pageSource: pageSource?.rawValue, params: params, eventData: eventData, extParams: extParams, commonParams: commonParams)
  23. }
  24. /// 视频相关上报
  25. /// - Parameters:
  26. /// - reportLogType: 上报库类型
  27. /// - videoData: 视频数据
  28. /// - pageSource: 页面
  29. /// - businessType: <#businessType description#>
  30. /// - objectType: <#objectType description#>
  31. /// - extParams: <#extParams description#>
  32. /// - shareId: <#shareId description#>
  33. /// - videoIds: <#videoIds description#>
  34. /// - playId: <#playId description#>
  35. /// - headVideoId: <#headVideoId description#>
  36. public class func videoRelationReportUpload(reportLogType: reportLogType, videoData: BFVideoItemProtocol?, pageSource: PAGESOURCE? = nil, businessType: businessType?, objectType: objectType? = nil, extParams: [String: Any]? = nil, shareId: String? = nil, videoIds: String? = nil, playId: String? = nil, headVideoId: String? = nil, projectId: String?, parentProjectId: String?, rootProjectId: String?, canProduce: Int?, parentVideoId: String?, commonParams: [String: Any]?) {
  37. DispatchQueue.global().async {
  38. var tempExtParams: [String: Any] = extParams ?? [:]
  39. if videoData?.topicData != nil {
  40. if videoData?.pageSource == .sp_cmunit_joinTopic || pageSource == .sp_cmunit_joinTopic, "\(tempExtParams["topicId"] ?? "")".count <= 0 {
  41. tempExtParams["topicId"] = "\(videoData?.topicData?["id"] ?? "")"
  42. } else if videoData?.pageSource == .sp_cmunit_follow || pageSource == .sp_cmunit_follow, "\(tempExtParams["followedUid"] ?? "")".count <= 0 {
  43. tempExtParams["followedUid"] = "\(videoData?.user?["uid"] ?? "")"
  44. }
  45. }
  46. if projectId != nil && (projectId?.count ?? 0) > 0 {
  47. tempExtParams["projectId"] = projectId ?? ""
  48. }
  49. if parentProjectId != nil && (parentProjectId?.count ?? 0) > 0 {
  50. tempExtParams["parentProjectId"] = parentProjectId ?? ""
  51. }
  52. if rootProjectId != nil && (rootProjectId?.count ?? 0) > 0 {
  53. tempExtParams["rootProjectId"] = rootProjectId ?? ""
  54. }
  55. if canProduce != nil {
  56. tempExtParams["canProduce"] = canProduce ?? 0
  57. }
  58. if parentVideoId != nil && (parentVideoId?.count ?? 0) > 0 {
  59. tempExtParams["parentVideoId"] = parentVideoId ?? ""
  60. }
  61. if !tempExtParams.keys.contains("clickedVideoId") {
  62. tempExtParams["videoId"] = "\(videoData?.id ?? 0)"
  63. }
  64. if headVideoId != nil, (headVideoId?.count ?? 0) > 0 {
  65. tempExtParams["headVideoId"] = (headVideoId ?? "0")
  66. }
  67. if objectType == .ot_reproduce_clickButton || objectType == .ot_reproduce_collectionBar || objectType == .ot_reproduce_collectionClicButton || objectType == .ot_reproduce_sameSourceButton {
  68. baseReportUpload(businessType: businessType, objectType: objectType, pageSource: pageSource != nil ? pageSource! : (videoData?.pageSource ?? .sp_category), extParams: tempExtParams, commonParams: commonParams)
  69. } else {
  70. var url: String = PQENVUtil.shared.longvideoapi
  71. var params: [String: Any] = [:]
  72. switch reportLogType {
  73. case .reportLogType_view:
  74. url = url + videoViewReportUrl
  75. if videoIds != nil, !videoIds!.isEmpty {
  76. params["videoIds"] = videoIds
  77. } else {
  78. params["videoIds"] = "\(videoData?.id ?? 0)"
  79. }
  80. params["viewId"] = ("\(Date().timeIntervalSince1970)" + "\(videoData?.id ?? 0)viewId" + "\(arc4random_uniform(1_000_000_000))")
  81. case .reportLogType_realPlay:
  82. url = url + videoRealPlayReportUrl
  83. if businessType != nil {
  84. params["actionTriggerType"] = businessType?.rawValue
  85. }
  86. case .reportLogType_play:
  87. url = url + videoPlayReportUrl
  88. case .reportLogType_Action:
  89. url = url + videoActionReportUrl
  90. if businessType != nil, businessType == .bt_videoShareH5 || businessType == .bt_videoShareFriend {
  91. params["shareId"] = shareId
  92. params["rootLaunchShareId"] = shareId
  93. params["parentShareId"] = shareId
  94. params["shareDepth"] = "0"
  95. params["videoId"] = videoIds
  96. }
  97. if businessType != nil {
  98. params["businessType"] = businessType?.rawValue
  99. }
  100. case .reportLogType_Frontend:
  101. url = PQENVUtil.shared.commonapi + staticsFrontendReportUrl
  102. params["LogType"] = 30
  103. params["eventData"] = bf_dictionaryToJsonString(["businessType": businessType?.rawValue ?? ""])
  104. }
  105. DispatchQueue.main.async {
  106. BFBaseEventTrack.bf_videoReportUpload(url: url, videoId: "\(videoData?.id ?? 0)", headVideoId: headVideoId ?? videoData?.headVideoId, playId: playId ?? "", recommendId: videoData?.recommendId, recommendLogVO: videoData?.recommendLogVO, flowPool: videoData?.flowPool, abInfoData: videoData?.abInfoData, measureType: videoData?.measureType, measureId: videoData?.measureId, businessType: businessType?.rawValue, objectType: objectType?.rawValue, pageSource: (videoData?.pageSource ?? .sp_category).rawValue, extParams: tempExtParams, commonParams: commonParams)
  107. }
  108. }
  109. }
  110. }
  111. // 分享上报
  112. // - Parameters:
  113. // - isShareVideo: 是否是分享视频
  114. // - screenType: 分享场景 1-分享视频/用户 2-分享视频到朋友圈 3-分享视频到好友
  115. // - videoId: 视频Id
  116. // - pageSource: 页面枚举
  117. // - recommendId: <#recommendId description#>
  118. // - recommendLogVO: <#recommendLogVO description#>
  119. // - abInfoData: <#abInfoData description#>
  120. // - measureType: <#measureType description#>
  121. // - measureId: <#measureId description#>
  122. // - businessType: <#businessType description#>
  123. // - targetUid: <#targetUid description#>
  124. // - shareId: <#shareId description#>
  125. public class func shareReportUpload(isShareVideo: Bool = true, screenType: Int = 1, videoId: String, pageSource: PAGESOURCE, recommendId: String?, recommendLogVO: String?, flowPool: String?, abInfoData: String?, measureType: Int?, measureId: Int?, businessType: businessType?, targetUid: Int?, shareId: String = "", playId: String?, wxOpenId: String?,rootPageTimestamp:Int64, extParams: [String: Any]? = nil, commonParams: [String: Any]?) {
  126. DispatchQueue.global().async {
  127. var url: String = PQENVUtil.shared.longvideoapi
  128. switch screenType {
  129. case 1:
  130. url = url + userShareReportUrl
  131. case 2:
  132. url = url + userShareH5ReportUrl
  133. case 3:
  134. url = url + userShareFriendReportUrl
  135. default:
  136. break
  137. }
  138. BFBaseEventTrack.bf_shareReportUpload(url: url, isShareVideo: isShareVideo, screenType: screenType, videoId: videoId, recommendId: recommendId, recommendLogVO: recommendLogVO, flowPool: flowPool, abInfoData: abInfoData, measureType: measureType, measureId: measureId, targetUid: targetUid, shareId: shareId, playId: playId, wxOpenId: wxOpenId,rootPageTimestamp:rootPageTimestamp, businessType: businessType?.rawValue, pageSource: pageSource.rawValue, extParams: extParams, commonParams: commonParams)
  139. }
  140. }
  141. /// DNS上报
  142. /// - Returns: <#description#>
  143. public class func dnsReportUpload(commonParams: [String: Any]?) {
  144. DispatchQueue.global().async {
  145. let speedExtParams = bf_parseDNS(hostUrl: "speed.piaoquantv.com")
  146. let rescdnExtParams = bf_parseDNS(hostUrl: "rescdn.yishihui.com")
  147. if speedExtParams != nil {
  148. baseReportUpload(businessType: .bt_dnsParseCostTime, objectType: nil, pageSource: nil, eventData: nil, extParams: speedExtParams, commonParams: commonParams)
  149. }
  150. if rescdnExtParams != nil {
  151. baseReportUpload(businessType: .bt_dnsParseCostTime, objectType: nil, pageSource: nil, eventData: nil, extParams: rescdnExtParams, commonParams: commonParams)
  152. }
  153. }
  154. }
  155. /// app冷热启动上报
  156. /// - Parameters:
  157. /// - isFirstLaunch: <#isFirstLaunch description#>
  158. /// - firstParams: <#firstParams description#>
  159. /// - isHotLaunch: <#isHotLaunch description#>
  160. /// - launchType: <#launchType description#>
  161. /// - commonParams: <#commonParams description#>
  162. class public func appLaunchReportUpload(isFirstLaunch: Int = 1, firstParams: [String: Any]? = nil, isHotLaunch: Bool = false, launchType: String = "userActiveOpen", commonParams: [String: Any]?) {
  163. BFBaseEventTrack.appLaunchReportUpload(url: PQENVUtil.shared.commonapi + staticsFrontendReportUrl, isFirstLaunch: isFirstLaunch, firstParams: firstParams, isHotLaunch: isHotLaunch, launchType: launchType, commonParams: commonParams)
  164. }
  165. /// 推送点击数据上报
  166. /// - Parameters:
  167. /// - pushId: 推送Id
  168. /// - pushTargetType: 1-推送单个视频 2-整体关注有更新 3-关注单个up主有更新(暂废弃) 4-订阅某人有更新
  169. /// - pushBrand: 推送平台 APPLE_TYPE
  170. /// - pushTargetId: pushTargetType == 1 视频ID,pushTargetType == 4 用户ID
  171. /// - bizParam 扩展参数
  172. /// - Returns: <#description#>
  173. public class func reportPushActionUpload(pushId: String, pushTargetType: Int, pushBrand: String, pushTargetId: String?, bizParam: [String: Any]? = nil, commonParams: [String: Any]?) {
  174. BFBaseEventTrack.bf_pushActionReportUpload(url: PQENVUtil.shared.longvideoapi + pushActionReportUrl, pushId: pushId, pushTargetType: pushTargetType, pushBrand: pushBrand, pushTargetId: pushTargetId, bizParam: bizParam, commonParams: commonParams)
  175. }
  176. /// 上报deviceToken
  177. /// - Parameter registerId: 设备id
  178. /// - Parameter deviceToken: <#deviceToken description#>
  179. /// - Returns: <#description#>
  180. public class func reportPushDeviceTokenUpload(registerId: String, deviceToken: String, brand: String, commonParams: [String: Any]?, completeHander: @escaping (_ isSuccess: Bool) -> Void) {
  181. BFBaseEventTrack.bf_deviceTokenReportUpload(url: PQENVUtil.shared.longvideoapi + pushDeviceTokenReportUrl, registerId: registerId, deviceToken: deviceToken, brand: brand, commonParams: commonParams, completeHander: completeHander)
  182. }
  183. /// 搜索上报
  184. /// - Parameters:
  185. /// - keyWord: 搜索词
  186. /// - searchType: 1 热搜词搜索 2 历史记录 3 普通搜索
  187. /// - searchNumber: 数量
  188. /// - reportType: 1 into 2 click 3 show
  189. /// - Returns: <#description#>
  190. public class func searchReportUpload(keyWord: String, searchType: Int, searchNumber: Int = 10, reportType: Int = 2, commonParams: [String: Any]?) {
  191. BFBaseEventTrack.bf_searchReportUpload(url: PQENVUtil.shared.longvideoapi + searchReportUrl, keyWord: keyWord, searchType: searchType, searchNumber: searchNumber, reportType: reportType, commonParams: commonParams)
  192. }
  193. /// 发布视频的上报
  194. /// - Parameters:
  195. /// - projectId:项目ID-发布创作的视频时必传,会在进入创作工具页时生成,以app_no_projectdata为前缀
  196. /// - businessType: <#businessType description#>
  197. /// - ossInfo: <#ossInfo description#>
  198. /// - params: <#params description#>
  199. /// - Returns: <#description#>
  200. public class func publishReportUpload(projectId: String?, businessType: businessType, ossInfo: [String: Any], params: [String: Any], commonParams: [String: Any]?) {
  201. var extParams: [String: Any] = ["ossInfo": bf_dictionaryToJsonString(ossInfo) ?? "", "params": bf_dictionaryToJsonString(params) ?? ""]
  202. if projectId != nil {
  203. extParams["projectId"] = projectId
  204. }
  205. if !extParams.keys.contains("source") {
  206. extParams["source"] = projectId != nil ? "videoCompose" : "videoUpload"
  207. }
  208. baseReportUpload(businessType: businessType, objectType: nil, pageSource: nil, extParams: extParams, commonParams: commonParams)
  209. }
  210. /// 站内消息埋点上报
  211. /// - Parameters:
  212. /// - messageIds: 消息Id,多个用逗号分隔
  213. /// - clickId: 子入口点击ID,标识一次子入口点击动作。子入口内消息列表中的消息点击行为都带有此字段,分享空间消息除外
  214. /// - messageType: 消息类型
  215. /// - messageSubType: 消息子类型
  216. /// - actionType: 动作类型(backendCreate:后端构建;backendReturn:后端返回;frontendPull:前端拉取;view:曝光;click:点击)
  217. /// - objectType: <#objectType description#>
  218. /// - pageSource: <#pageSource description#>
  219. /// - readStatus: 已读状态:1:页面上显示未读 2:页面上显示已读
  220. /// - eventData: 扩展数据,json格式,日志系统里会展开存储
  221. /// - extParams: 扩展字段 json格式
  222. /// - remindmsg: 打印提示信息
  223. /// - Returns: <#description#>
  224. public class func messageReportUpload(messageIds: String?, clickId: String?, messageType: messageType?, messageSubType: messageSubType?, actionType: actionType?, objectType: objectType?, pageSource: PAGESOURCE?, readStatus: Int = 1, eventData: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]?) {
  225. BFBaseEventTrack.bf_messageReportUpload(url: PQENVUtil.shared.longvideoapi + messagePeportUrl, messageIds: messageIds, clickId: clickId, messageType: messageType?.rawValue, messageSubType: messageSubType?.rawValue, actionType: actionType?.rawValue, readStatus: readStatus, objectType: objectType?.rawValue, pageSource: pageSource?.rawValue, eventData: eventData, extParams: extParams, commonParams: commonParams)
  226. }
  227. }