diff --git a/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs b/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs index c887112..308af49 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs @@ -53,7 +53,7 @@ namespace WZ network.RefreshAdsData(); } } - +#region 激励视频广告 public bool IsRewardAdReady() { return _adNetworks.Any(network => network.IsRewardedAvailable()); @@ -63,7 +63,7 @@ namespace WZ /// 展示激励广告 /// /// - public void ShowRewardAd(string _adPos, Action _rewardCallback = null, Action _showFailedCallback = null) + public void ShowRewardAd(string _adPos, Action _rewardCallback = null, Action _showFailedCallback = null) { AdsActionEvents.TrackAdPosition(AdsType.Rewarded, _adPos); if (!IsRewardAdReady()) @@ -100,7 +100,9 @@ namespace WZ AdPlayCountManager.IncrementAdPlayCount(AdsType.Rewarded); CheckAndRefreshExpiredBids(AdsType.Rewarded); } +#endregion +#region 插屏广告 public bool IsInterstitialReady() { return _adNetworks.Any(network => network.IsInterstitialAvailable()); @@ -151,6 +153,51 @@ namespace WZ // 刷新其他类型广告 CheckAndRefreshExpiredBids(AdsType.Interstitial); } + #endregion + + #region 横幅广告 + public bool IsBannerAdReady() + { + return AdmobAdsManager.Instance.IsBannerAvailable(); + } + + public void ShowBanner() + { + AdsActionEvents.TrackAdPosition(AdsType.Interstitial, ""); + if (IsBannerAdReady()) + { + AdmobAdsManager.Instance.DisplayBanner(); + AdPlayCountManager.IncrementAdPlayCount(AdsType.Banner); + } + } + + public void HideBanner() + { + AdmobAdsManager.Instance.HideBanner(); + } + #endregion + + + #region 原生广告 + public bool IsNativeAdReady() + { + return AdmobAdsManager.Instance.IsNativeAvailable(); + } + + public void ShowNativeAd(NativeAdPosition position) + { + if (IsNativeAdReady()) + { + AdmobAdsManager.Instance.DisplayNative(position); + AdPlayCountManager.IncrementAdPlayCount(AdsType.Native); + } + } + + public void RemoveNativeAd() + { + AdmobAdsManager.Instance.RemoveNative(); + } + #endregion #region 开屏广告 public bool IsSplashAvailable() @@ -197,7 +244,80 @@ namespace WZ } } - // 检查并刷新过期竞价 + /// + /// 广告看完回调 + /// + public void OnRewardAdCallback(double price) + { + AdRewardCallback?.Invoke(price); + AdRewardCallback = null; + } + + /// + /// 根据IvRules判断是否可以展示插屏 + /// + /// + public bool IvRulesShow(IvType ivadType) + { + //1.获取远程配置 + string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("IV_RULES"); + if (string.IsNullOrEmpty(json)) + { + return true; + } + //2.解析配置 + var dates = JsonConvert.DeserializeObject(json); + if (dates == null && dates.Length == 0) + { + return true; + } + //3.获取IVADType对应的配置 + IvRulesData ivRulesData = null; + foreach (var data in dates) + { + if (data.type == (int)ivadType) + { + ivRulesData = data; + } + } + if (ivRulesData == null) + { + return true; + } + //4.判断skip(次安装跳过几次触发不展示广告) + int skipLevel = ivRulesData.skipLevel; + int currentSkipLevel = PlayerPrefsUtils.GetPlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, 0); + if (currentSkipLevel < skipLevel) + { + LoggerUtils.Debug($"[SDK] skipLevel limit"); + PlayerPrefsUtils.SavePlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, currentSkipLevel + 1); + return false; + } + //5.判断overLevel(没跳过几次触发) + int overLevel = ivRulesData.overLevel; + int currentOverLevel = IvRulesConst.CurrentOverLevel; + if (currentOverLevel < overLevel) + { + LoggerUtils.Debug($"[SDK] overLevel limit"); + IvRulesConst.CurrentOverLevel++; + return false; + } + + //6.判断interval(广告时间间隔) + int interval = ivRulesData.interval; + long currentInterval = IvRulesConst.CurrentInterval; + long localTimestamp = TimeUtils.GetLocalTimestamp(); + + if (localTimestamp < currentInterval + (interval * 1000L)) + { + LoggerUtils.Debug($"[SDK] interval limit"); + return false; + } + + return true; + } + + #region 检查并刷新过期竞价 private void CheckAndRefreshExpiredBids(AdsType _adsType) { Dictionary> expiredBids = BidPlatformManager.Instance.GetExpiredBids(); @@ -327,78 +447,6 @@ namespace WZ break; } } - - /// - /// 广告看完回调 - /// - public void OnRewardAdCallback(double price) - { - AdRewardCallback?.Invoke(price); - AdRewardCallback = null; - } - - /// - /// 根据IvRules判断是否可以展示插屏 - /// - /// - public bool IvRulesShow(IvType ivadType) - { - //1.获取远程配置 - string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("IV_RULES"); - if (string.IsNullOrEmpty(json)) - { - return true; - } - //2.解析配置 - var dates = JsonConvert.DeserializeObject(json); - if (dates == null && dates.Length == 0) - { - return true; - } - //3.获取IVADType对应的配置 - IvRulesData ivRulesData = null; - foreach (var data in dates) - { - if (data.type == (int)ivadType) - { - ivRulesData = data; - } - } - if (ivRulesData == null) - { - return true; - } - //4.判断skip(次安装跳过几次触发不展示广告) - int skipLevel = ivRulesData.skipLevel; - int currentSkipLevel = PlayerPrefsUtils.GetPlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, 0); - if (currentSkipLevel < skipLevel) - { - LoggerUtils.Debug($"[SDK] skipLevel limit"); - PlayerPrefsUtils.SavePlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, currentSkipLevel + 1); - return false; - } - //5.判断overLevel(没跳过几次触发) - int overLevel = ivRulesData.overLevel; - int currentOverLevel = IvRulesConst.CurrentOverLevel; - if (currentOverLevel < overLevel) - { - LoggerUtils.Debug($"[SDK] overLevel limit"); - IvRulesConst.CurrentOverLevel++; - return false; - } - - //6.判断interval(广告时间间隔) - int interval = ivRulesData.interval; - long currentInterval = IvRulesConst.CurrentInterval; - long localTimestamp = TimeUtils.GetLocalTimestamp(); - - if (localTimestamp < currentInterval + (interval * 1000L)) - { - LoggerUtils.Debug($"[SDK] interval limit"); - return false; - } - - return true; - } +#endregion } } \ No newline at end of file diff --git a/Assets/Script/SDKManager/AdsSDKManager/Events/AdsEvents/AdsActionEvents.cs b/Assets/Script/SDKManager/AdsSDKManager/Events/AdsEvents/AdsActionEvents.cs index c3e2abc..604e0f0 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/Events/AdsEvents/AdsActionEvents.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/Events/AdsEvents/AdsActionEvents.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using Firebase.Analytics; using UnityEngine; @@ -9,42 +10,124 @@ namespace WZ { public static void TrackAdClicked(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat, string posotion, double value) { - + var eventName = "ad_click"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_source", adSource}, + { "ad_unit_name", adUnitName}, + { "ad_format", adFormat.ToString()}, + { "position", posotion}, + { "value", value}, + { "currency","USD"}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdClosed(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat, string posotion, double value) { AdsSDKManager.Instance.otherAdsOnShow = false; + var eventName = "ad_close"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_source", adSource}, + { "ad_unit_name", adUnitName}, + { "ad_format", adFormat.ToString()}, + { "position", posotion}, + { "value", value}, + { "currency","USD"}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdStartLoad(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat) { AdsSDKManager.Instance.otherAdsOnShow = true; + var eventName = "ad_start_load"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_format", adFormat.ToString()}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdLoaded(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat, double loadTime) { - + var eventName = "ad_loaded"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_source", adSource}, + { "ad_unit_name", adUnitName}, + { "ad_format", adFormat.ToString()}, + { "pass_time", loadTime}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdFailToLoad(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat, double loadTime, string reason) { - + var eventName = "ad_load_fail"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_source", adSource}, + { "ad_unit_name", adUnitName}, + { "ad_format", adFormat.ToString()}, + { "pass_time", loadTime}, + { "reason", reason}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdFailToShow(PlatformType adPlatform, AdsType adFormat, string reason, string pos) { AdsSDKManager.Instance.otherAdsOnShow = false; + var eventName = "ad_show_fail"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_format", adFormat.ToString()}, + { "reason", reason}, + { "position", pos}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdPosition(AdsType adFormat, string pos) { - + var eventName = "ad_position"; + var dic = new Dictionary { + { "ad_format", adFormat.ToString()}, + { "position", pos}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } public static void TrackAdImpression(PlatformType adPlatform, string adSource, string adUnitName, AdsType adFormat, string posotion, double value) { - + var eventName = "ad_impression"; + var dic = new Dictionary { + { "ad_platform", adPlatform.ToString()}, + { "ad_source", adSource}, + { "ad_unit_name", adUnitName}, + { "ad_format", adFormat.ToString()}, + { "position", posotion}, + { "value", value}, + { "currency","USD"}, + { "number",AdPlayCountManager.GetAdPlayCount(adFormat)} + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, dic); + ShuShuEvent.Instance.Track(eventName, dic); } - } } \ No newline at end of file diff --git a/Assets/Script/SDKManager/AppSDKManager.cs b/Assets/Script/SDKManager/AppSDKManager.cs index a26bf32..39bcc4c 100644 --- a/Assets/Script/SDKManager/AppSDKManager.cs +++ b/Assets/Script/SDKManager/AppSDKManager.cs @@ -36,6 +36,21 @@ public class AppSDKManager : D_MonoSingleton #region ad + public void ShowRewardAd(string position, Action callback = null) + { + bool isRewardAdReady = AdsSDKManager.Instance.IsRewardAdReady(); + if (isRewardAdReady) + { + AdsSDKManager.Instance.ShowRewardAd(position, (isReward, revenue) => + { + if (isReward) + { + //callback?.Invoke(); + callback?.Invoke(true, revenue); + } + }); + } + } public void ShowInterstitial(string position, IvType ivadType = IvType.IV1, Action callback = null) { //插屏展示逻辑 @@ -112,24 +127,7 @@ public class AppSDKManager : D_MonoSingleton } #endregion - - - public void ShowRewardAd(string position, Action callback = null) - { - bool isRewardAdReady = AdsSDKManager.Instance.IsRewardAdReady(); - if (isRewardAdReady) - { - AdsSDKManager.Instance.ShowRewardAd(position, (isReward, revenue) => - { - if (isReward) - { - //callback?.Invoke(); - callback?.Invoke(true, revenue); - } - }); - } - } #region 在线参数 @@ -151,7 +149,7 @@ public class AppSDKManager : D_MonoSingleton return FireBaseRemoteConfigManager.Instance.GetRemoteConfigInt(key, defaultValue); } - public string GetRemoteConfigString(string key, string defaultValue = "") + public string GetRemoteConfigStr(string key, string defaultValue = "") { if (Application.isEditor) { diff --git a/Assets/Script/SDKManager/EFSdkManager/EFSdkManager.cs b/Assets/Script/SDKManager/EFSdkManager/EFSdkManager.cs index 03bcf93..d88ff2d 100644 --- a/Assets/Script/SDKManager/EFSdkManager/EFSdkManager.cs +++ b/Assets/Script/SDKManager/EFSdkManager/EFSdkManager.cs @@ -34,6 +34,7 @@ namespace WZ }); SetSDKEventCallback(); + SetHdH5ImpressionCallback(); } private void SetSDKEventCallback() @@ -44,5 +45,26 @@ namespace WZ ShuShuEvent.Instance.Track(eventName, dict); }); } + + // + /// 互动广告展示回调,此时可以计算上报互动广告展示次数和收益 + /// + /// string 是互动广告的url + public void SetHdH5ImpressionCallback() + { + EFSdk.get().SetHdH5ImpressionCallback((url) => + { + //TODO 判断是okspin还是appluck + string h5ad_okspinrev = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("H5ad_okspinrev", "0"); + string h5ad_appluckrev= FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("H5ad_appluckrev", "0"); + //TODO 上报 + //adjust + //AdjustTrackEvent.Instance.TrackAdEvent(); + //firebase + //FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(); + //数数 + //ShuShuEvent.Instance.OnAdRevenueEvent(); + }); + } } } \ No newline at end of file