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