native 广告行为事件上报
This commit is contained in:
parent
a485b5eaa2
commit
251e0c7cce
|
@ -38,23 +38,19 @@ namespace WZ
|
|||
public void Initialize()
|
||||
{
|
||||
if (_initialized) return;
|
||||
_initialized = true;
|
||||
MobileAds.RaiseAdEventsOnUnityMainThread = true;
|
||||
//
|
||||
MobileAds.Initialize(initStatus =>
|
||||
{
|
||||
_initialized = true;
|
||||
if (_bannerAdUnits.Count > 0) LoadBanner();
|
||||
if (_interstitialAdUnits.Count > 0) LoadInterstitial();
|
||||
if (_rewardedAdUnits.Count > 0) LoadRewarded();
|
||||
if (_splashAdUnits.Count > 0) AdsSplashManager.Instance.InitSplash();
|
||||
if (_nativeAdUnits.Count > 0)LoadNative();
|
||||
LoggerUtils.Debug("[Admob] init success");
|
||||
});
|
||||
|
||||
if (_bannerAdUnits.Count > 0) LoadBanner();
|
||||
if (_interstitialAdUnits.Count > 0) LoadInterstitial();
|
||||
if (_rewardedAdUnits.Count > 0) LoadRewarded();
|
||||
if (_splashAdUnits.Count > 0) AdsSplashManager.Instance.InitSplash();
|
||||
|
||||
if (_nativeAdUnits.Count > 0)
|
||||
{
|
||||
LoadNative();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void RefreshAdsData()
|
||||
|
@ -177,7 +173,7 @@ namespace WZ
|
|||
}
|
||||
|
||||
public bool IsInterstitialAvailable()
|
||||
{;
|
||||
{
|
||||
return _admobInterstitialAdManager.GetAvailableAdUnits().Count > 0;
|
||||
}
|
||||
|
||||
|
@ -310,6 +306,7 @@ namespace WZ
|
|||
_admobNativeAdManager.InitializeAdUnits(
|
||||
_nativeAdUnits
|
||||
);
|
||||
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Native);
|
||||
}
|
||||
|
||||
public bool IsNativeAvailable(string adUnitId)
|
||||
|
@ -319,6 +316,7 @@ namespace WZ
|
|||
|
||||
public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position)
|
||||
{
|
||||
|
||||
_admobNativeAdManager.ShowAd(position, adUnitId);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ 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>();
|
||||
|
||||
public void InitializeAdUnits(List<string> adUnitIds)
|
||||
{
|
||||
foreach (var adUnitId in adUnitIds)
|
||||
|
@ -39,6 +41,7 @@ namespace WZ
|
|||
|
||||
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}");
|
||||
if (error != null || ad == null)
|
||||
{
|
||||
|
@ -46,13 +49,22 @@ namespace WZ
|
|||
{
|
||||
_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]));
|
||||
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,
|
||||
AdsType.Native,
|
||||
Time.realtimeSinceStartup - _adStartLoadTimes[adUnitId]);
|
||||
_retryCounters[adUnitId] = 0;
|
||||
|
||||
var nativeEcpm = AdmobUtils.GetNativeEcpm(ad);
|
||||
|
@ -72,11 +84,27 @@ namespace WZ
|
|||
|
||||
ad.OnAdImpressionRecorded += () => { LoggerUtils.Debug("[Admob] Native ad recorded an impression."); };
|
||||
|
||||
ad.OnAdClicked += () => { LoggerUtils.Debug("[Admob] Native ad was clicked."); };
|
||||
ad.OnAdClicked += () =>
|
||||
{
|
||||
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.OnAdFullScreenContentClosed += () => { LoggerUtils.Debug("[Admob] Native ad full screen content closed."); };
|
||||
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."); };
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -124,6 +152,10 @@ namespace WZ
|
|||
}
|
||||
|
||||
|
||||
private float GetLoadedTime(string adUnitId)
|
||||
{
|
||||
return _adStartLoadTimes.TryGetValue(adUnitId, out var time)? time : 0;
|
||||
}
|
||||
// 检查特定广告位是否可用
|
||||
public bool IsAdAvailable(string adUnitId)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue