本地统计load
This commit is contained in:
parent
0d4ebde870
commit
e2df65105c
@ -961,6 +961,7 @@ class YL_NetWorkManager{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("Result: \(result ?? [:])")
|
print("Result: \(result ?? [:])")
|
||||||
|
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "upload ad load 成功"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@ -1098,6 +1099,7 @@ class YL_NetWorkManager{
|
|||||||
NSLog("load end c")
|
NSLog("load end c")
|
||||||
client.hintBlock = { (t:String?) in
|
client.hintBlock = { (t:String?) in
|
||||||
guard let jsonStr = t else {
|
guard let jsonStr = t else {
|
||||||
|
// exit(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let result = convertStringToDictionary(text: jsonStr)
|
let result = convertStringToDictionary(text: jsonStr)
|
||||||
@ -1136,6 +1138,7 @@ class YL_NetWorkManager{
|
|||||||
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "返回数据格式错误"])
|
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "返回数据格式错误"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//exit(0)
|
||||||
}
|
}
|
||||||
NSLog("load end1")
|
NSLog("load end1")
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||||
|
|||||||
@ -135,30 +135,56 @@ class AdItem :NSObject,MAAdDelegate{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func didLoad(_ ad: MAAd) {
|
func didLoad(_ ad: MAAd) {
|
||||||
NSLog("XS didLoad\(self.interstitialAdID)")
|
NSLog("XS didLoad\(self.interstitialAdID)")
|
||||||
BbbAdManager.config.loadcount += 1
|
BbbAdManager.config.loadcount += 1
|
||||||
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "加载广告: \(ad.adUnitIdentifier) 成功"])
|
NotificationCenter.default.post(
|
||||||
retryAttempt = 0 // 重置重试次数
|
name: NSNotification.Name("adinfo"),
|
||||||
NSLog("成功加载广告\(ad.adUnitIdentifier)")
|
object: nil,
|
||||||
self.ecpm = ad.revenue
|
userInfo: ["text": "加载广告: \(ad.adUnitIdentifier) 成功"]
|
||||||
|
)
|
||||||
|
retryAttempt = 0 // 重置重试次数
|
||||||
|
NSLog("成功加载广告\(ad.adUnitIdentifier)")
|
||||||
|
self.ecpm = ad.revenue
|
||||||
|
|
||||||
// 计算并打印加载时间
|
// 计算并打印加载时间
|
||||||
var time = 0
|
var time = 0
|
||||||
if let startTime: DispatchTime = startLoadTime {
|
if let startTime = startLoadTime {
|
||||||
let loadDuration = calculateElapsedTime(since: startTime)
|
let loadDuration = calculateElapsedTime(since: startTime)
|
||||||
NSLog("广告 \(ad.adUnitIdentifier) 加载时间: \(loadDuration) ms")
|
NSLog("广告 \(ad.adUnitIdentifier) 加载时间: \(loadDuration) ms")
|
||||||
time = loadDuration
|
time = loadDuration
|
||||||
}
|
} else {
|
||||||
|
NSLog("startLoadTime 为 nil,无法计算加载时间")
|
||||||
DispatchQueue.global(qos: .utility).async { [weak self] in
|
|
||||||
guard self != nil else { return }
|
|
||||||
YL_NetWorkManager.uploadAD_Load(adid: ad.adUnitIdentifier, ecpm: ad.revenue, network: ad.networkName, countryCode: ALSdk.shared().configuration.countryCode, platformResponseTime:ad.requestLatency , dsp: ad.dspName ?? "", loadTime: time)
|
|
||||||
}
|
|
||||||
// 发布广告加载成功通知
|
|
||||||
// NotificationCenter.default.post(name: .adDidLoad, object: nil, userInfo: ["adId": ad.adUnitIdentifier])
|
|
||||||
changeStatus(st: 2)
|
|
||||||
YL_NetWorkManager.onLoad()
|
|
||||||
}
|
}
|
||||||
|
NotificationCenter.default.post(
|
||||||
|
name: NSNotification.Name("adinfo"),
|
||||||
|
object: nil,
|
||||||
|
userInfo: ["text": "加载广告: \(ad.adUnitIdentifier) 成功 1"]
|
||||||
|
)
|
||||||
|
DispatchQueue.global(qos: .utility).async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
YL_NetWorkManager.uploadAD_Load(
|
||||||
|
adid: ad.adUnitIdentifier,
|
||||||
|
ecpm: self.ecpm,
|
||||||
|
network: ad.networkName ?? "Unknown",
|
||||||
|
countryCode: ALSdk.shared().configuration.countryCode ?? "Unknown",
|
||||||
|
platformResponseTime: ad.requestLatency,
|
||||||
|
dsp: ad.dspName ?? "Unknown",
|
||||||
|
loadTime: time
|
||||||
|
)
|
||||||
|
}
|
||||||
|
NotificationCenter.default.post(
|
||||||
|
name: NSNotification.Name("adinfo"),
|
||||||
|
object: nil,
|
||||||
|
userInfo: ["text": "加载广告: \(ad.adUnitIdentifier) 成功 2"]
|
||||||
|
)
|
||||||
|
changeStatus(st: 2)
|
||||||
|
// YL_NetWorkManager.onLoad()
|
||||||
|
NotificationCenter.default.post(
|
||||||
|
name: NSNotification.Name("adinfo"),
|
||||||
|
object: nil,
|
||||||
|
userInfo: ["text": "加载广告: \(ad.adUnitIdentifier) 成功 3"]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {
|
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {
|
||||||
failLoad(forAdUnitIdentifier: adUnitIdentifier, withError: error.message)
|
failLoad(forAdUnitIdentifier: adUnitIdentifier, withError: error.message)
|
||||||
@ -170,8 +196,12 @@ class AdItem :NSObject,MAAdDelegate{
|
|||||||
NSLog("XS didFailToLoadAd 2 \(self.interstitialAdID) \(error)")
|
NSLog("XS didFailToLoadAd 2 \(self.interstitialAdID) \(error)")
|
||||||
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "加载:\(adUnitIdentifier ) 失败"])
|
NotificationCenter.default.post(name: NSNotification.Name("adinfo"), object: nil, userInfo: ["text": "加载:\(adUnitIdentifier ) 失败"])
|
||||||
var time = 0
|
var time = 0
|
||||||
if let startTime = startLoadTime {
|
var startTime = startLoadTime
|
||||||
let loadDuration = calculateElapsedTime(since: startTime)
|
if BbbAdManager.config.washParam == true {
|
||||||
|
startTime = BbbAdManager.startInitTime
|
||||||
|
}
|
||||||
|
if let ttItme = startTime {
|
||||||
|
let loadDuration = calculateElapsedTime(since: ttItme)
|
||||||
NSLog("广告 \(adUnitIdentifier) 加载时间: \(loadDuration) ms")
|
NSLog("广告 \(adUnitIdentifier) 加载时间: \(loadDuration) ms")
|
||||||
time = loadDuration
|
time = loadDuration
|
||||||
}
|
}
|
||||||
@ -213,7 +243,6 @@ class AdItem :NSObject,MAAdDelegate{
|
|||||||
func didHide(_ ad: MAAd) {
|
func didHide(_ ad: MAAd) {
|
||||||
changeStatus(st: 4)
|
changeStatus(st: 4)
|
||||||
NSLog("成功关闭广告\(ad.adUnitIdentifier)")
|
NSLog("成功关闭广告\(ad.adUnitIdentifier)")
|
||||||
onAdClosed?()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func didClick(_ ad: MAAd) {
|
func didClick(_ ad: MAAd) {
|
||||||
@ -251,7 +280,7 @@ class BbbAdManager: NSObject {
|
|||||||
let kOpenAdCTimeLength: CGFloat = 120 // 假设的超时时长
|
let kOpenAdCTimeLength: CGFloat = 120 // 假设的超时时长
|
||||||
|
|
||||||
static var totalTimeC: CGFloat = 0.0
|
static var totalTimeC: CGFloat = 0.0
|
||||||
|
static var startInitTime = DispatchTime.now()
|
||||||
|
|
||||||
// 添加广告位管理器
|
// 添加广告位管理器
|
||||||
func add(adId: String) {
|
func add(adId: String) {
|
||||||
@ -348,6 +377,7 @@ class BbbAdManager: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initAd() {
|
func initAd() {
|
||||||
|
BbbAdManager.startInitTime = DispatchTime.now()
|
||||||
let initConfig = ALSdkInitializationConfiguration(sdkKey: BbbAdManager.config.adKey) { builder in
|
let initConfig = ALSdkInitializationConfiguration(sdkKey: BbbAdManager.config.adKey) { builder in
|
||||||
|
|
||||||
builder.mediationProvider = ALMediationProviderMAX
|
builder.mediationProvider = ALMediationProviderMAX
|
||||||
@ -436,11 +466,22 @@ class BbbAdManager: NSObject {
|
|||||||
BbbAdManager.totalTimeC += kOpenADPerSec
|
BbbAdManager.totalTimeC += kOpenADPerSec
|
||||||
|
|
||||||
if BbbAdManager.shared.isEnd() || BbbAdManager.totalTimeC >= kOpenAdCTimeLength {
|
if BbbAdManager.shared.isEnd() || BbbAdManager.totalTimeC >= kOpenAdCTimeLength {
|
||||||
DispatchQueue.global(qos: .utility).async { [weak self] in
|
|
||||||
|
if BbbAdManager.totalTimeC >= kOpenAdCTimeLength {
|
||||||
|
DispatchQueue.global(qos: .utility).async { [weak self] in
|
||||||
guard self != nil else { return }
|
guard self != nil else { return }
|
||||||
let time:Int = Int(BbbAdManager.totalTimeC * 1000)
|
|
||||||
|
let startTime = BbbAdManager.startInitTime
|
||||||
|
|
||||||
|
let time:Int = {
|
||||||
|
let endTime = DispatchTime.now()
|
||||||
|
let nanoseconds = endTime.uptimeNanoseconds - startTime.uptimeNanoseconds
|
||||||
|
return Int(nanoseconds / 1_000_000) // 转换为毫秒
|
||||||
|
}()
|
||||||
YL_NetWorkManager.uploadAD_Load(adid: "", ecpm: 0.0, network: "", countryCode: "", platformResponseTime:0.0 , dsp: "", loadTime:time,succeed:false,errorMsg: "load timeout > 120s")
|
YL_NetWorkManager.uploadAD_Load(adid: "", ecpm: 0.0, network: "", countryCode: "", platformResponseTime:0.0 , dsp: "", loadTime:time,succeed:false,errorMsg: "load timeout > 120s")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog("xyz 1")
|
NSLog("xyz 1")
|
||||||
openADTimer?.invalidate()
|
openADTimer?.invalidate()
|
||||||
openADTimer = nil
|
openADTimer = nil
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user