Compare commits

..

No commits in common. "87a3a16376808406c3e8ad985d2d0098de8b82eb" and "1137f261cb98d062b93425a6bba14a4ffaa6c0c6" have entirely different histories.

2 changed files with 16 additions and 43 deletions

View File

@ -38,16 +38,23 @@ namespace WZ
public void Initialize() public void Initialize()
{ {
if (_initialized) return; if (_initialized) return;
_initialized = true;
MobileAds.RaiseAdEventsOnUnityMainThread = true; MobileAds.RaiseAdEventsOnUnityMainThread = true;
//
MobileAds.Initialize(initStatus => MobileAds.Initialize(initStatus =>
{ {
_initialized = true; LoggerUtils.Debug("[Admob] init success");
if (_bannerAdUnits.Count > 0) LoadBanner(); if (_bannerAdUnits.Count > 0) LoadBanner();
if (_interstitialAdUnits.Count > 0) LoadInterstitial(); if (_interstitialAdUnits.Count > 0) LoadInterstitial();
if (_rewardedAdUnits.Count > 0) LoadRewarded(); if (_rewardedAdUnits.Count > 0) LoadRewarded();
if (_splashAdUnits.Count > 0) AdsSplashManager.Instance.InitSplash(); if (_splashAdUnits.Count > 0) AdsSplashManager.Instance.InitSplash();
if (_nativeAdUnits.Count > 0)LoadNative();
LoggerUtils.Debug("[Admob] init success"); if (_nativeAdUnits.Count > 0)
{
LoadNative();
}
}); });
@ -173,7 +180,7 @@ namespace WZ
} }
public bool IsInterstitialAvailable() public bool IsInterstitialAvailable()
{ {;
return _admobInterstitialAdManager.GetAvailableAdUnits().Count > 0; return _admobInterstitialAdManager.GetAvailableAdUnits().Count > 0;
} }
@ -306,7 +313,6 @@ namespace WZ
_admobNativeAdManager.InitializeAdUnits( _admobNativeAdManager.InitializeAdUnits(
_nativeAdUnits _nativeAdUnits
); );
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Native);
} }
public bool IsNativeAvailable(string adUnitId) public bool IsNativeAvailable(string adUnitId)
@ -316,7 +322,6 @@ namespace WZ
public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position) public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position)
{ {
_admobNativeAdManager.ShowAd(position, adUnitId); _admobNativeAdManager.ShowAd(position, adUnitId);
} }

View File

@ -13,8 +13,6 @@ namespace WZ
private Dictionary<string, double> _adRevenueCache = new Dictionary<string, double>(); private Dictionary<string, double> _adRevenueCache = new Dictionary<string, double>();
private Dictionary<string, int> _retryCounters = new Dictionary<string, int>(); private Dictionary<string, int> _retryCounters = new Dictionary<string, int>();
private Dictionary<string,float> _adStartLoadTimes = new Dictionary<string, float>();
public void InitializeAdUnits(List<string> adUnitIds) public void InitializeAdUnits(List<string> adUnitIds)
{ {
foreach (var adUnitId in adUnitIds) foreach (var adUnitId in adUnitIds)
@ -41,7 +39,6 @@ namespace WZ
NativeOverlayAd.Load(adUnitId, new AdRequest(), new NativeAdOptions(), (NativeOverlayAd ad, LoadAdError error) => NativeOverlayAd.Load(adUnitId, new AdRequest(), new NativeAdOptions(), (NativeOverlayAd ad, LoadAdError error) =>
{ {
_adStartLoadTimes[adUnitId] = Time.realtimeSinceStartup;
LoggerUtils.Debug($"[Admob] Native Ad unit {adUnitId} load end. {ad} error {error}"); LoggerUtils.Debug($"[Admob] Native Ad unit {adUnitId} load end. {ad} error {error}");
if (error != null || ad == null) if (error != null || ad == null)
{ {
@ -49,22 +46,13 @@ namespace WZ
{ {
_retryCounters[adUnitId]++; _retryCounters[adUnitId]++;
} }
AdsActionEvents.TrackAdFailToLoad(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
AdsType.Native,
Time.realtimeSinceStartup - _adStartLoadTimes[adUnitId],error.GetMessage());
var retryDelay = Math.Pow(2, Math.Min(6, _retryCounters[adUnitId])); var retryDelay = Math.Pow(2, Math.Min(6, _retryCounters[adUnitId]));
TimerUtils.Instance.DelayExecute((float)retryDelay, () => { LoadAd(adUnitId); }); TimerUtils.Instance.DelayExecute((float)retryDelay, () => { LoadAd(adUnitId); });
LoggerUtils.Debug("[Admob] Native ad failed to load an ad with error : " + error + " \n retryDelay :" + retryDelay); LoggerUtils.Debug("[Admob] Native ad failed to load an ad with error : " + error + " \n retryDelay :" + retryDelay);
return; return;
} }
AdsActionEvents.TrackAdLoaded(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
AdsType.Native,
Time.realtimeSinceStartup - _adStartLoadTimes[adUnitId]);
_retryCounters[adUnitId] = 0; _retryCounters[adUnitId] = 0;
var nativeEcpm = AdmobUtils.GetNativeEcpm(ad); var nativeEcpm = AdmobUtils.GetNativeEcpm(ad);
@ -84,27 +72,11 @@ namespace WZ
ad.OnAdImpressionRecorded += () => { LoggerUtils.Debug("[Admob] Native ad recorded an impression."); }; ad.OnAdImpressionRecorded += () => { LoggerUtils.Debug("[Admob] Native ad recorded an impression."); };
ad.OnAdClicked += () => ad.OnAdClicked += () => { LoggerUtils.Debug("[Admob] Native ad was clicked."); };
{
AdsActionEvents.TrackAdClicked(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
AdsType.Native,
"",
AdmobUtils.GetNativeEcpm(ad));
LoggerUtils.Debug("[Admob] Native ad was clicked.");
};
ad.OnAdFullScreenContentOpened += () => { LoggerUtils.Debug("[Admob] Native ad full screen content opened."); }; ad.OnAdFullScreenContentOpened += () => { LoggerUtils.Debug("[Admob] Native ad full screen content opened."); };
ad.OnAdFullScreenContentClosed += () => { ad.OnAdFullScreenContentClosed += () => { LoggerUtils.Debug("[Admob] Native ad full screen content closed."); };
AdsActionEvents.TrackAdClicked(PlatformType.Admob,
ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
adUnitId,
AdsType.Native,
"",
AdmobUtils.GetNativeEcpm(ad));
LoggerUtils.Debug("[Admob] Native ad full screen content closed."); };
}); });
} }
@ -152,10 +124,6 @@ namespace WZ
} }
private float GetLoadedTime(string adUnitId)
{
return _adStartLoadTimes.TryGetValue(adUnitId, out var time)? time : 0;
}
// 检查特定广告位是否可用 // 检查特定广告位是否可用
public bool IsAdAvailable(string adUnitId) public bool IsAdAvailable(string adUnitId)
{ {