123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- //
- // BFBaseEventTrack.swift
- // PQSpeed
- //
- // Created by SanW on 2020/11/3.
- // Copyright © 2020 BytesFlow. All rights reserved.
- //
- import BFCommonKit
- import BFNetRequestKit
- import UIKit
- // MARK: - 埋点数据上报
- /// 埋点数据上报
- public class BFBaseEventTrack: NSObject {
- /// 基础数据上报 - frontend库上报
- /// - Parameters:
- /// - logType: 数据库类型
- /// - businessType: businessType
- /// - objectType: objectType
- /// - eventData: eventData
- /// - pageSource: pageSource页面场景
- /// - extParams: extParams 扩展字段,为json对象
- /// - remindmsg: remindmsg 打印提示信息
- /// - Returns: <#description#>
- public class func bf_frontendReportUpload(url: String, logType: Int = 30, businessType: String?, objectType: String?, pageSource: String?, params: [String: Any]? = nil, eventData: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- // LogType
- var tempParams: [String: Any] = params ?? [:]
- tempParams["LogType"] = logType
- // pageSource
- if pageSource != nil {
- tempParams["pageSource"] = pageSource ?? ""
- }
- // eventData
- var tempEventData: [String: Any] = eventData ?? [:]
- if objectType != nil {
- tempEventData["objectType"] = objectType ?? ""
- }
- if businessType != nil {
- tempEventData["businessType"] = businessType ?? ""
- }
- if tempEventData.keys.count > 0 {
- tempParams["eventData"] = bf_dictionaryToJsonString(tempEventData)
- }
- // extParams
- if extParams != nil, (extParams?.keys.count ?? 0) > 0 {
- tempParams["extParams"] = bf_dictionaryToJsonString(extParams!)
- }
- BFNetRequestAdaptor.postRequestData(url: url, parames: tempParams, commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- /// 消息数据上报
- /// - Parameters:
- /// - messageIds: 消息Id,多个用逗号分隔
- /// - clickId: 子入口点击ID,标识一次子入口点击动作。子入口内消息列表中的消息点击行为都带有此字段,分享空间消息除外
- /// - messageType: 消息类型
- /// - messageSubType: 消息子类型
- /// - actionType: 动作类型(backendCreate:后端构建;backendReturn:后端返回;frontendPull:前端拉取;view:曝光;click:点击)
- /// - objectType: <#objectType description#>
- /// - pageSource: <#pageSource description#>
- /// - readStatus: 已读状态:1:页面上显示未读 2:页面上显示已读
- /// - eventData: 扩展数据,json格式,日志系统里会展开存储
- /// - extParams: 扩展字段 json格式
- /// - remindmsg: 打印提示信息
- /// - Returns: <#description#>
- public class func bf_messageReportUpload(url: String, messageIds: String?, clickId: String?, messageType: Int?, messageSubType: Int?, actionType: String?, readStatus: Int = 1, objectType: String?, pageSource: String?, eventData: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- var tempParams: [String: Any] = extParams ?? [:]
- if messageIds != nil {
- tempParams["messageIds"] = messageIds
- }
- if messageType != nil {
- tempParams["messageType"] = messageType ?? ""
- }
- if messageSubType != nil {
- tempParams["messageSubType"] = messageSubType ?? ""
- }
- if actionType != nil {
- tempParams["actionType"] = actionType ?? ""
- }
- tempParams["readStatus"] = readStatus + 1
- if pageSource != nil {
- tempParams["pageSource"] = pageSource ?? ""
- }
- // eventData
- var tempEventData: [String: Any] = eventData ?? [:]
- if objectType != nil {
- tempEventData["objectType"] = objectType ?? ""
- }
- if tempEventData.keys.count > 0 {
- tempParams["eventData"] = bf_dictionaryToJsonString(tempEventData)
- }
- // extParams
- var tempExtParams: [String: Any] = extParams ?? [:]
- if clickId != nil {
- tempExtParams["clickId"] = clickId
- }
- if tempExtParams.keys.count > 0 {
- tempParams["extParams"] = bf_dictionaryToJsonString(tempExtParams)
- }
- BFNetRequestAdaptor.postRequestData(url: url, parames: tempParams, commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- /// 视频相关数据上报
- /// - Parameters:
- /// - reportLogType: 日志类型
- /// - videoId: 视频Id
- /// - headVideoId: 当前的相关推荐视频是属于哪个视频的相关推荐,值为那个头部视频的videoId
- /// - videoIds: reportLogType_view时传
- /// - pageSource: 页面
- /// - playId: 播放ID 对于每一次播放操作,生成唯一playid,标示唯一一次播放操作,视频播放中暂停,再继续播放时,不算一次新的播放,不需要生成新的playid。重播视频算一次新的播放,即需要生成新的playid。
- /// - recommendId: 推荐链路ID 列表返回
- /// - recommendLogVO: 推荐日志对象 列表返回
- /// - abInfoData: AB信息 列表返回
- /// - measureType:
- /// - measureId:
- /// - businessType: 操作类型
- /// - targetUid: 视频用户ID
- /// - Returns: <#description#>
- public class func bf_videoReportUpload(url: String, videoId: String?, headVideoId: String?, playId: String?, recommendId: String?, recommendLogVO: String?, flowPool: String?, abInfoData: String?, measureType: Int?, measureId: Int?, targetUid: Int = 0, businessType: String?, objectType: String?, pageSource: String?, params: [String: Any]? = nil, eventData: [String: Any]? = nil, extParams: [String: Any]? = nil, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- var tempParams: [String: Any] = params ?? [:]
- if !tempParams.keys.contains("videoId") {
- tempParams["videoId"] = Int64(videoId ?? "") ?? 0
- }
- if !tempParams.keys.contains("pageSource") {
- tempParams["pageSource"] = pageSource ?? ""
- }
- if !tempParams.keys.contains("playId") {
- tempParams["playId"] = playId ?? ""
- }
- if !tempParams.keys.contains("targetUid") {
- tempParams["targetUid"] = targetUid
- }
- if measureType != nil {
- tempParams["measureType"] = measureType
- }
- if measureId != nil {
- tempParams["measureId"] = measureId
- }
- if recommendId != nil, !(recommendId?.isEmpty ?? true) {
- tempParams["recommendId"] = recommendId
- }
- if recommendLogVO != nil, !(recommendLogVO?.isEmpty ?? true) {
- tempParams["recommendLogVO"] = recommendLogVO
- }
- if flowPool != nil, (flowPool?.count ?? 0) > 0 {
- tempParams["flowPool"] = flowPool
- }
- if abInfoData != nil, !(abInfoData?.isEmpty ?? true) {
- tempParams["abInfoData"] = abInfoData
- }
- if pageSource?.contains("speedApp-category") ?? false {
- tempParams["pageCategoryId"] = 55
- }
- // eventData
- var tempEventData: [String: Any] = eventData ?? [:]
- if objectType != nil {
- tempEventData["objectType"] = objectType ?? ""
- }
- if businessType != nil {
- tempEventData["businessType"] = businessType ?? ""
- tempParams["businessType"] = businessType ?? ""
- }
- tempEventData["pageSource"] = pageSource ?? ""
- // extParams
- var tempExtParams: [String: Any] = extParams ?? [:]
- if headVideoId != nil, (headVideoId?.count ?? 0) > 0 {
- tempExtParams["headVideoId"] = Int64(headVideoId ?? "0") ?? 0
- }
- if videoId != nil, (videoId?.count ?? 0) > 0 {
- tempExtParams["videoId"] = Int64(videoId ?? "") ?? 0
- }
- if tempEventData.keys.count > 0 {
- tempParams["eventData"] = bf_dictionaryToJsonString(tempEventData)
- }
- if tempExtParams.keys.count > 0 {
- tempParams["extParams"] = bf_dictionaryToJsonString(tempExtParams)
- }
- BFNetRequestAdaptor.postRequestData(url: url, parames: tempParams, commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- // 分享数据上报
- // - Parameters:
- // - isShareVideo: 是否是分享视频
- // - screenType: 分享场景 1-分享视频/用户 2-分享视频到朋友圈 3-分享视频到好友
- // - videoId: 视频Id
- // - pageSource: 页面枚举
- // - recommendId: <#recommendId description#>
- // - recommendLogVO: <#recommendLogVO description#>
- // - abInfoData: <#abInfoData description#>
- // - measureType: <#measureType description#>
- // - measureId: <#measureId description#>
- // - businessType: <#businessType description#>
- // - targetUid: <#targetUid description#>
- // - shareId: <#shareId description#>
- public class func bf_shareReportUpload(url: String, isShareVideo: Bool = true, screenType _: Int = 1, videoId: String?, recommendId: String?, recommendLogVO: String?, flowPool: String?, abInfoData: String?, measureType: Int?, measureId: Int?, targetUid: Int?, shareId: String = "", playId: String?, wxOpenId: String?, rootPageTimestamp: Int64, businessType: String?, pageSource: String?, extParams: [String: Any]? = nil, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- var params: [String: Any] = ["type": isShareVideo ? "1" : "2", "videoId": videoId ?? "", "pageSource": pageSource ?? "", "playId": playId ?? "", "targetUid": targetUid ?? 0, "shareDepth": "0", "rootPageTimestamp": rootPageTimestamp]
- if extParams != nil {
- params["extParams"] = bf_dictionaryToJsonString(extParams!)
- }
- params["eventData"] = bf_dictionaryToJsonString(["rootPageTimestamp": rootPageTimestamp])
- if measureType != nil {
- params["measureType"] = measureType
- }
- if measureId != nil {
- params["measureId"] = measureId
- }
- params["shareId"] = shareId
- params["rootLaunchShareId"] = shareId
- params["parentShareId"] = shareId
- params["rootShareId"] = shareId
- if wxOpenId != nil {
- params["shareUi"] = wxOpenId ?? ""
- }
- if pageSource?.contains("speedApp-category") ?? false {
- params["pageCategoryId"] = 55
- }
- if isShareVideo {
- params["shareObjectId"] = videoId
- } else {
- params["shareObjectId"] = targetUid
- }
- if businessType != nil {
- params["businessType"] = businessType ?? ""
- }
- if recommendId != nil, !(recommendId?.isEmpty ?? true) {
- params["recommendId"] = recommendId
- }
- if recommendLogVO != nil, !(recommendLogVO?.isEmpty ?? true) {
- params["recommendLogVO"] = recommendLogVO
- }
- if flowPool != nil, (flowPool?.count ?? 0) > 0 {
- params["flowPool"] = flowPool
- }
- if abInfoData != nil, !(abInfoData?.isEmpty ?? true) {
- params["abInfoData"] = abInfoData
- }
- BFNetRequestAdaptor.postRequestData(url: url, parames: params, commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- /// 推送点击数据上报
- /// - Parameters:
- /// - pushId: 推送Id
- /// - pushTargetType: 1-推送单个视频 2-整体关注有更新 3-关注单个up主有更新(暂废弃) 4-订阅某人有更新
- /// - pushBrand: 推送平台 APPLE_TYPE
- /// - pushTargetId: pushTargetType == 1 视频ID,pushTargetType == 4 用户ID
- /// - bizParam 扩展参数
- /// - Returns: <#description#>
- public class func bf_pushActionReportUpload(url: String, pushId: String, pushTargetType: Int, pushBrand: String?, pushTargetId: String?, bizParam: [String: Any]? = nil, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- var params: [String: Any] = bizParam ?? Dictionary<String, Any>.init()
- if pushTargetId != nil {
- params["pushTargetId"] = pushTargetId
- }
- if pushId.count > 0 {
- params["pushId"] = pushId
- }
- params["pushTargetType"] = pushTargetType
- params["pushBrand"] = pushBrand
- params["pushReportType"] = "click"
- if params.keys.contains("aps") {
- params.removeValue(forKey: "aps")
- }
- BFNetRequestAdaptor.postRequestData(url: url, parames: params, commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- /// deviceToken数据上报
- /// - Parameter registerId: 设备id
- /// - Parameter deviceToken: <#deviceToken description#>
- /// - Returns: <#description#>
- public class func bf_deviceTokenReportUpload(url: String, registerId: String, deviceToken: String, brand: String, commonParams: [String: Any]? = nil, completeHander: @escaping (_ isSuccess: Bool) -> Void) {
- DispatchQueue.global().async {
- BFNetRequestAdaptor.postRequestData(url: url, parames: ["registerId": registerId, "deviceToken": deviceToken, "brand": brand], commonParams: commonParams) { _, _, error, _ in
- completeHander(error == nil ? true : false)
- }
- }
- }
- /// 搜索数据上报
- /// - Parameters:
- /// - keyWord: 搜索词
- /// - searchType: 1 热搜词搜索 2 历史记录 3 普通搜索
- /// - searchNumber: 数量
- /// - reportType: 1 into 2 click 3 show
- /// - Returns: <#description#>
- public class func bf_searchReportUpload(url: String, keyWord: String, searchType: Int, searchNumber: Int = 10, reportType: Int = 2, commonParams: [String: Any]? = nil) {
- DispatchQueue.global().async {
- BFNetRequestAdaptor.postRequestData(url: url, parames: ["keyWord": keyWord, "searchType": searchType, "searchNumber": searchNumber, "reportType": reportType], commonParams: commonParams) { _, _, _, _ in
- }
- }
- }
- /// 冷热启动数据上报
- /// - 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)")
- }
- }
- }
- }
|