diff --git a/package/Runtime/Plugins/Android/UnityHelper.java b/package/Runtime/Plugins/Android/UnityHelper.java index 50227692..0d7e3eab 100644 --- a/package/Runtime/Plugins/Android/UnityHelper.java +++ b/package/Runtime/Plugins/Android/UnityHelper.java @@ -13,6 +13,7 @@ import com.adsbynimbus.openrtb.request.App; import com.adsbynimbus.openrtb.request.Format; import com.adsbynimbus.openrtb.request.Position; +import com.adsbynimbus.openrtb.request.User; import com.adsbynimbus.render.AdController; import com.adsbynimbus.render.AdEvent; import com.adsbynimbus.render.BlockingAdRenderer; @@ -27,15 +28,22 @@ public final class UnityHelper { BlockingAdRenderer.setDismissOnComplete(true); } - public static void setApp(Object bundleId, String appName, String domain, String storeUrl) { + public static void setApp(String bundleId, String appName, String domain, String storeUrl) { final App app = new App(); - app.bundle = bundleId.toString(); - app.name = appName.toString(); - app.domain = domain.toString(); - app.storeurl = storeUrl.toString(); + app.bundle = bundleId; + app.name = appName; + app.domain = domain; + app.storeurl = storeUrl; RequestManager.setApp(app); } + public static void setUser(String gdprConsent) { + final User user = new User(); + user.ext = new User.Extension(); + user.ext.consent = gdprConsent; + RequestManager.setUser(user); + } + public static void showInterstitialAd(Object obj, String position, float bannerFloor, float videoFloor, int closeButtonDelay, Object listener) { if (obj instanceof Activity) { diff --git a/package/Runtime/Scripts/Internal/Android.cs b/package/Runtime/Scripts/Internal/Android.cs index 7407d774..56001ede 100644 --- a/package/Runtime/Scripts/Internal/Android.cs +++ b/package/Runtime/Scripts/Internal/Android.cs @@ -55,5 +55,9 @@ internal override NimbusAdUnit LoadAndShowAd(ILogger logger, ref NimbusAdUnit ni listener); return nimbusAdUnit; } + + internal override void SetGDPRConsentString(string consent) { + _helper.CallStatic("setUser", consent); + } } } \ No newline at end of file diff --git a/package/Runtime/Scripts/Internal/Editor.cs b/package/Runtime/Scripts/Internal/Editor.cs index 75fe6a8c..39401ecf 100644 --- a/package/Runtime/Scripts/Internal/Editor.cs +++ b/package/Runtime/Scripts/Internal/Editor.cs @@ -30,5 +30,9 @@ internal override NimbusAdUnit LoadAndShowAd(ILogger logger, ref NimbusAdUnit ni logger.Log($"In Editor mode, {functionCall} was called, however ads cannot be shown in the editor"); return nimbusAdUnit; } + + internal override void SetGDPRConsentString(string consent) { + Debug.unityLogger.Log("Mock SDK consent string cannot be added"); + } } } \ No newline at end of file diff --git a/package/Runtime/Scripts/Internal/NimbusAPI.cs b/package/Runtime/Scripts/Internal/NimbusAPI.cs index 94473f64..aaec4a8e 100644 --- a/package/Runtime/Scripts/Internal/NimbusAPI.cs +++ b/package/Runtime/Scripts/Internal/NimbusAPI.cs @@ -5,5 +5,7 @@ namespace Nimbus.Runtime.Scripts.Internal { public abstract class NimbusAPI { internal abstract void InitializeSDK(ILogger logger, NimbusSDKConfiguration configuration); internal abstract NimbusAdUnit LoadAndShowAd(ILogger logger, ref NimbusAdUnit nimbusAdUnit); + // ReSharper disable once InconsistentNaming + internal abstract void SetGDPRConsentString(string consent); } } \ No newline at end of file diff --git a/package/Runtime/Scripts/NimbusManager.cs b/package/Runtime/Scripts/NimbusManager.cs index f523ad38..0d334329 100644 --- a/package/Runtime/Scripts/NimbusManager.cs +++ b/package/Runtime/Scripts/NimbusManager.cs @@ -11,10 +11,10 @@ public class NimbusManager : MonoBehaviour { public delegate void SetAdUnitFromCoroutine(NimbusAdUnit adUnit); public static NimbusManager Instance; - - private AdEvents _nimbusEvents; private NimbusAPI _nimbusPlatformAPI; + public AdEvents NimbusEvents; + private void Awake() { if (configuration == null) throw new Exception("The configuration object cannot be null"); configuration.ValidateMobileData(); @@ -30,7 +30,7 @@ private void Awake() { Android #endif (); - _nimbusEvents = new AdEvents(); + NimbusEvents = new AdEvents(); Debug.unityLogger.logEnabled = configuration.enableUnityLogs; _nimbusPlatformAPI.InitializeSDK(Debug.unityLogger, configuration); Instance = this; @@ -47,15 +47,15 @@ private IEnumerator Start() { var eventsFound = false; var iAdEvents = FindObjectsOfType().OfType(); foreach (var iAdEvent in iAdEvents) { - Instance._nimbusEvents.OnAdRendered += iAdEvent.OnAdWasRendered; - Instance._nimbusEvents.OnAdError += iAdEvent.OnAdError; - Instance._nimbusEvents.OnAdLoaded += iAdEvent.OnAdLoaded; - Instance._nimbusEvents.OnAdImpression += iAdEvent.OnAdImpression; - Instance._nimbusEvents.OnAdClicked += iAdEvent.OnAdClicked; - Instance._nimbusEvents.OnAdDestroyed += iAdEvent.OnAdDestroyed; - Instance._nimbusEvents.OnVideoAdPaused += iAdEvent.OnVideoAdPaused; - Instance._nimbusEvents.OnVideoAdResume += iAdEvent.OnVideoAdResume; - Instance._nimbusEvents.OnVideoAdCompleted += iAdEvent.OnVideoAdCompleted; + Instance.NimbusEvents.OnAdRendered += iAdEvent.OnAdWasRendered; + Instance.NimbusEvents.OnAdError += iAdEvent.OnAdError; + Instance.NimbusEvents.OnAdLoaded += iAdEvent.OnAdLoaded; + Instance.NimbusEvents.OnAdImpression += iAdEvent.OnAdImpression; + Instance.NimbusEvents.OnAdClicked += iAdEvent.OnAdClicked; + Instance.NimbusEvents.OnAdDestroyed += iAdEvent.OnAdDestroyed; + Instance.NimbusEvents.OnVideoAdPaused += iAdEvent.OnVideoAdPaused; + Instance.NimbusEvents.OnVideoAdResume += iAdEvent.OnVideoAdResume; + Instance.NimbusEvents.OnVideoAdCompleted += iAdEvent.OnVideoAdCompleted; eventsFound = true; } @@ -71,15 +71,15 @@ private void OnDestroy() { if (!shouldSubscribeToIAdEvents) return; var iAdEvents = FindObjectsOfType().OfType(); foreach (var iAdEvent in iAdEvents) { - Instance._nimbusEvents.OnAdRendered -= iAdEvent.OnAdWasRendered; - Instance._nimbusEvents.OnAdError -= iAdEvent.OnAdError; - Instance._nimbusEvents.OnAdLoaded += iAdEvent.OnAdLoaded; - Instance._nimbusEvents.OnAdImpression += iAdEvent.OnAdImpression; - Instance._nimbusEvents.OnAdClicked += iAdEvent.OnAdClicked; - Instance._nimbusEvents.OnAdDestroyed += iAdEvent.OnAdDestroyed; - Instance._nimbusEvents.OnVideoAdPaused += iAdEvent.OnVideoAdPaused; - Instance._nimbusEvents.OnVideoAdResume += iAdEvent.OnVideoAdResume; - Instance._nimbusEvents.OnVideoAdCompleted += iAdEvent.OnVideoAdCompleted; + Instance.NimbusEvents.OnAdRendered -= iAdEvent.OnAdWasRendered; + Instance.NimbusEvents.OnAdError -= iAdEvent.OnAdError; + Instance.NimbusEvents.OnAdLoaded += iAdEvent.OnAdLoaded; + Instance.NimbusEvents.OnAdImpression += iAdEvent.OnAdImpression; + Instance.NimbusEvents.OnAdClicked += iAdEvent.OnAdClicked; + Instance.NimbusEvents.OnAdDestroyed += iAdEvent.OnAdDestroyed; + Instance.NimbusEvents.OnVideoAdPaused += iAdEvent.OnVideoAdPaused; + Instance.NimbusEvents.OnVideoAdResume += iAdEvent.OnVideoAdResume; + Instance.NimbusEvents.OnVideoAdCompleted += iAdEvent.OnVideoAdCompleted; } } @@ -95,7 +95,7 @@ private void OnDestroy() { /// Represents your asking price for banner ads during the auction /// public NimbusAdUnit LoadAndShowBannerAd(string position, float bannerBidFloor) { - var adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0f, in _nimbusEvents); + var adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0f, in NimbusEvents); return _nimbusPlatformAPI.LoadAndShowAd(Debug.unityLogger, ref adUnit); } @@ -115,7 +115,7 @@ public NimbusAdUnit LoadAndShowBannerAd(string position, float bannerBidFloor) { /// public NimbusAdUnit LoadAndShowFullScreenAd(string position, float bannerBidFloor, float videoBidFloor) { var adUnit = new NimbusAdUnit(AdUnityType.Interstitial, position, bannerBidFloor, videoBidFloor, - in _nimbusEvents); + in NimbusEvents); return _nimbusPlatformAPI.LoadAndShowAd(Debug.unityLogger, ref adUnit); } @@ -130,7 +130,7 @@ public NimbusAdUnit LoadAndShowFullScreenAd(string position, float bannerBidFloo /// Represents your asking price for video ads during the auction /// public NimbusAdUnit LoadAndShowRewardedVideoAd(string position, float videoBidFloor) { - var adUnit = new NimbusAdUnit(AdUnityType.Rewarded, position, 0, videoBidFloor, in _nimbusEvents); + var adUnit = new NimbusAdUnit(AdUnityType.Rewarded, position, 0, videoBidFloor, in NimbusEvents); return _nimbusPlatformAPI.LoadAndShowAd(Debug.unityLogger, ref adUnit); } @@ -152,18 +152,30 @@ public NimbusAdUnit LoadAndShowRewardedVideoAd(string position, float videoBidFl public IEnumerator LoadAndShowBannerAdWithRefresh(string position, float bannerBidFloor, SetAdUnitFromCoroutine currentAdUnit, float refreshIntervalInSeconds = 30f) { - var adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0, in _nimbusEvents); + var adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0, in NimbusEvents); currentAdUnit(adUnit); _nimbusPlatformAPI.LoadAndShowAd(Debug.unityLogger, ref adUnit); while (true) { yield return new WaitForSeconds(refreshIntervalInSeconds); adUnit?.Destroy(); - adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0, in _nimbusEvents); + adUnit = new NimbusAdUnit(AdUnityType.Banner, position, bannerBidFloor, 0, in NimbusEvents); currentAdUnit(adUnit); _nimbusPlatformAPI.LoadAndShowAd(Debug.unityLogger, ref adUnit); } } + // ReSharper disable once InconsistentNaming + /// + /// Allows the TCF GDPR consent string to be set globally on all request to Nimbus + /// + /// + /// This is the TCF GDRP consent string + /// + public void SetGDPRConsentString(string consent) { + _nimbusPlatformAPI.SetGDPRConsentString(consent); + } + + #region Editor Values public NimbusSDKConfiguration configuration;