Compare commits

...

2 Commits

2 changed files with 30 additions and 9 deletions

View File

@ -54,8 +54,11 @@ namespace WZ
};
bannerAds.OnBannerAdLoadFailed += ((msg) =>
{
if (!_retryCounters.TryAdd(adUnitId, 0))
{
_retryCounters[adUnitId]++;
}
double retryDelay = Math.Pow(2, Math.Min(6, _retryCounters[adUnitId]));
LoggerUtils.Debug($"[Admob] banner -[Load]: {adUnitId} failed, error message = {msg}");

View File

@ -13,7 +13,7 @@ namespace WZ
private Dictionary<string, double> _adRevenueCache = new Dictionary<string, double>();
private Dictionary<string, int> _retryCounters = new Dictionary<string, int>();
private Dictionary<string,float> _adStartLoadTimes = new Dictionary<string, float>();
private Dictionary<string, float> _adStartLoadTimes = new Dictionary<string, float>();
public void InitializeAdUnits(List<string> adUnitIds)
{
@ -49,17 +49,32 @@ namespace WZ
{
_retryCounters[adUnitId]++;
}
var adSource = "";
if (ad != null)
{
adSource = ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName;
}
var reason = "";
if (error != null)
{
reason = error.GetMessage();
}
AdsActionEvents.TrackAdFailToLoad(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adSource,
adUnitId,
AdsType.Native,
Time.realtimeSinceStartup - _adStartLoadTimes[adUnitId],error.GetMessage());
Time.realtimeSinceStartup - _adStartLoadTimes[adUnitId], reason);
var retryDelay = Math.Pow(2, Math.Min(6, _retryCounters[adUnitId]));
TimerUtils.Instance.DelayExecute((float)retryDelay, () => { LoadAd(adUnitId); });
LoggerUtils.Debug("[Admob] Native ad failed to load an ad with error : " + error + " \n retryDelay :" + retryDelay);
return;
}
AdsActionEvents.TrackAdLoaded(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
@ -97,14 +112,16 @@ namespace WZ
ad.OnAdFullScreenContentOpened += () => { LoggerUtils.Debug("[Admob] Native ad full screen content opened."); };
ad.OnAdFullScreenContentClosed += () => {
ad.OnAdFullScreenContentClosed += () =>
{
AdsActionEvents.TrackAdClicked(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
AdsType.Native,
"",
AdmobUtils.GetNativeEcpm(ad));
LoggerUtils.Debug("[Admob] Native ad full screen content closed."); };
LoggerUtils.Debug("[Admob] Native ad full screen content closed.");
};
});
}
@ -154,8 +171,9 @@ namespace WZ
private float GetLoadedTime(string adUnitId)
{
return _adStartLoadTimes.TryGetValue(adUnitId, out var time)? time : 0;
return _adStartLoadTimes.TryGetValue(adUnitId, out var time) ? time : 0;
}
// 检查特定广告位是否可用
public bool IsAdAvailable(string adUnitId)
{