All requests to retrieve and show ads are done through NimbusAdsManager's Singleton Access Pattern. This Singleton can be accessed through any MonoBehavior.
Banner Ads
Banner Ads
Showing a single Ad can done through the NimbusAdsManager's Singleton Access Pattern via RequestBannerAdAndLoad
usingNimbus.Internal;usingNimbus.Runtime.Scripts;usingUnityEngine;publicclassBannerRequest:MonoBehaviour { // The position field is required and used explicitly within the Ads By Nimbus reporting UI. The data in this field
// should remain fairly constant and allows you to distinguish ads units within the Nimbus reporting dashboard. privateconststring NimbusReportingPosition ="banner_ad_unit"; [Tooltip("Floors can be dynamically set through the Nimbus Dashboard")] [SerializeField] privatefloat _bannerAdFloor =0.00f;privateNimbusAdUnit _bannerAd;privatevoidStart() { // This method will call to the Nimbus Exchange and // if an ad was successfully returned it will immediately display it. // Storing the ad unit as a class variable allows you to remove the ad by // calling it's Destroy Method _bannerAd =NimbusManager.Instance.RequestBannerAdAndLoad(NimbusReportingPosition, _bannerAdFloor); }privatevoidOnDisable() {_bannerAd?.Destroy(); }}
To continuously refresh and display Banner Ads call RequestRefreshingBannerAdAndLoad
usingSystem.Threading;usingNimbus.Runtime.Scripts;usingUnityEngine;publicclassRefreshingBannerRequest:MonoBehaviour { // The position field is required and used explicitly within the Ads By Nimbus reporting UI. The data in this field
// should remain fairly constant and allows you to distinguish ads units within the Nimbus reporting dashboard. privateconststring NimbusReportingPosition ="banner_ad_unit"; [Tooltip("Floors can be dynamically set through the Nimbus Dashboard")] [SerializeField] privatefloat _bannerAdFloor =0.00f; // To stop refreshing banner ads or remove them from the screen the source must be cancelledprivateCancellationTokenSource _ctx;privatevoidAwake() { _ctx =newCancellationTokenSource(); // This method will call to the Nimbus Exchange and // if an ad was successfully returned it will immediately display it. // Banner ads will continuously be refreshed every 30 seconds. If no ad was returned from // the Nimbus exchange any currently displayed ads will remain and an attempt to display another // ad will be made at the next interval.NimbusManager.Instance.RequestRefreshingBannerAdAndLoad(_ctx, NimbusReportingPosition, _bannerAdFloor); }privatevoidOnDisable() {_ctx.Cancel(); }}
RequestRefreshingBannerAdAndLoad should only ever be called once.
Interstitial Ads
Showing an Interstitial Ad can done through the NimbusAdsManager's Singleton Access Pattern via RequestHybridFullScreenAd. Interstitial ads make use of the Nimbus Hybrid auction. In a Hybrid Auction, static display and video ads compete against each other to fill your placement. This maximizes CPMs and ensures you get the highest fill rates possible. Ads will remain on screen for 5 seconds because a user is allowed to hit the X button and close the ad.
usingNimbus.Internal;usingNimbus.Runtime.Scripts;usingUnityEngine;publicclassFullScreenRequest:MonoBehaviour { // The position field is required and used explicitly within the Ads By Nimbus reporting UI. The data in this field
// should remain fairly constant and allows you to distinguish ads units within the Nimbus reporting dashboard. privateconststring NimbusReportingPosition ="interstitial_ad_unit"; [Tooltip("Floors can be dynamically set through the Nimbus Dashboard")] [SerializeField] privatefloat _fullScreenAdFloor =0.00f;privateNimbusAdUnit _fullscreenAd;privatevoidStart() { // This will method will the Nimbus server to return an ad // if an ad was successfully returned it will immediately display it _fullscreenAd =NimbusManager.Instance.RequestHybridFullScreenAd(NimbusReportingPosition, _fullScreenAdFloor); }privatevoidOnDisable() {_fullscreenAd?.Destroy(); }}
Requesting For Reward Video Ads
Showing an Interstitial Ad can done through the NimbusAdsManager's Singleton Access Pattern via RequestHybridFullScreenAd. Interstitial ads make use of the Nimbus Hybrid auction. In a Hybrid Auction, static display and video ads compete against each other to fill your placement. This maximizes CPMs and ensures you get the highest fill rates possible. Ads will remain on screen for 5 seconds because a user is allowed to hit the X button and close the ad.
usingNimbus.Internal;usingNimbus.Runtime.Scripts;usingUnityEngine;publicclassRewardedRequest:MonoBehaviour { // The position field is required and used explicitly within the Ads By Nimbus reporting UI. The data in this field
// should remain fairly constant and allows you to distinguish ads units within the Nimbus reporting dashboard. privateconststring NimbusReportingPosition ="rewarded_ad_unit"; [Tooltip("Floors can be dynamically set through the Nimbus Dashboard")] [SerializeField] privatefloat _rewardedAdFloor =0.00f;privateNimbusAdUnit _rewardedAd;privatevoidStart() { // This will method will the Nimbus server to return an ad // if an ad was successfully returned it will immediately display it _rewardedAd =NimbusManager.Instance.RequestRewardVideoAdAndLoad(NimbusReportingPosition, _rewardedAdFloor); }privatevoidOnDisable() {_rewardedAd?.Destroy(); }}
Decoupled Request and Load
It is possible to call for an Ad from the Nimbus server and display it later (ad caching). It is not recommended. The Nimbus Exchange operates at low latency that can be discussed during the onboarding phase. The reason it is recommended to cache these ads is because Nimbus does not control or own returned ads. As such impression trackers embedded by connected demand partners may expire before an ad can be displayed to a user. It is suggested that if you wish to cache ads to talk to your connected demand partners directly to determine and negotiate expiration times on tracking pixels. So that your system can implement a smart caching system to avoid any revenue loss due to ads being expired.
usingNimbus.Internal;usingNimbus.Runtime.Scripts;usingUnityEngine;publicclassDecoupledRequest:MonoBehaviour {privateconststring NimbusReportingPositionBanner ="banner_ad_unit";privateconststring NimbusReportingPositionInterstitial ="intersitial_ad_unit";privateconststring NimbusReportingPositionReward ="rewarded_ad_unit";privateNimbusAdUnit _bannerAd;privateNimbusAdUnit _interstitialAd;privateNimbusAdUnit _rewardedAd;privatevoidStart() { // ads are requested from the Nimbus Exchange but they are not shown to the user _bannerAd =NimbusManager.Instance.RequestBannerAd(NimbusReportingPositionBanner); _interstitialAd =NimbusManager.Instance.RequestHybridFullScreenAd(NimbusReportingPositionInterstitial); _rewardedAd =NimbusManager.Instance.RequestRewardVideoAd(NimbusReportingPositionReward); }privatevoidOnEnable() { // to show an ad that has been successfully returned from the server call ShowLoadedAd and pass in the // NimbusAdUnit objectNimbusManager.Instance.ShowLoadedAd(_bannerAd); // NimbusManager.Instance.ShowLoadedAd(_interstitialAd); // NimbusManager.Instance.ShowLoadedAd(_rewardedAd); }}Decoupled Request and Load
Advanced Requesting
Nimbus is an RTB exchange and as such all communication to Nimbus is done via the Nimbus Open RTB Spec. As such, for those confident in their RTB knowledge we expose two additional methods on the NimbusManager.Instance
Noting that each of the above methods takes in a BidRequest object. All accessible data models and fields can be found in the open source nimbus-openrtb repository.
Constructing a 100% valid Nimbus RTB bid request requires understanding of the RTB Nimbus Open RTB Spec and the data models nimbus-openrtb repository. There are a few static helpers to jump start BidRequest objects based on Nimbus ad type.
Below are examples of the 4 main static constructor types. For an overview of all the static extensions please examine the RequestBuilder package within the Ads By Nimbus Package in Unity. /Package/Ads By Nimbus/Runtime/Scripts/Nimbus.Internal/RequestBuilder
Here is an example of what the ForVideoInterstitialAd expands into, again noting that it's setting many of the required Nimbus RTB fields..
publicstaticBidRequestForVideoInterstitialAd(string position) {var impression =new[] {newImp { Video =newVideo().Interstitial(), Instl =1, Secure =1, Ext =newImpExt { Position = position } } };returnnewBidRequest { Imp = impression, Format =newFormat { W =Screen.width, H =Screen.height } };}
Here is a fuller example using a custom request
usingSystem;usingNimbus.Internal;usingNimbus.Internal.RequestBuilder;usingNimbus.Runtime.Scripts;usingOpenRTB.Request;usingUnityEngine;publicclassAdvancedRequest:MonoBehaviour {privateconststring NimbusReportingPosition ="video_interstitial_checkpoint"; // subscribe to events of interestprivatevoidOnEnable() {NimbusManager.Instance.NimbusEvents.OnAdImpression+= OnAdImpression;NimbusManager.Instance.NimbusEvents.OnAdCompleted+= OnAdCompleted;NimbusManager.Instance.NimbusEvents.OnAdError+= OnAdError; } // unsubscribe to events as clean upprivatevoidOnDisable() {NimbusManager.Instance.NimbusEvents.OnAdImpression-= OnAdImpression;NimbusManager.Instance.NimbusEvents.OnAdCompleted-= OnAdCompleted;NimbusManager.Instance.NimbusEvents.OnAdError-= OnAdError; } // check if the player crossed a trigger zone 3DprivatevoidOnTriggerEnter(Collider other) {Trigger(other.gameObject); } // check if the player crossed a trigger zone 2DprivatevoidOnTriggerEnter2D(Collider2D col) {Trigger(col.gameObject); } // Trigger allows for 2d/3d abstractionprivatestaticvoidTrigger(GameObject go) {if (!go.CompareTag("Player")) return;ShowAdToPlayerAtTriggerCheckPointImmediately(); } /// <summary> /// Constructs a custom video Interstitial. This differs from calling RequestHybridFullScreenAd as this limits /// Nimbus's auction to returning video assets, rather than hybridizing and also returning any winning "static" ads. /// Likewise, I'm customizing the request by adding additional RTB data. Also, recall that this differs from calling RequestRewardVideoAdAndLoad.
/// Returned Video Rewarded ads require that the user watch the video ad to completion, whereas an video interstitial, will allow
/// a user to skip after 5 seconds. /// </summary> /// <returns></returns>privatestaticBidRequestVideoOnlyInterstitialRequest() { // using the NimbusRtbBidRequestHelper package provides extensions on top off the BidRequest objectvar bidRequest =NimbusRtbBidRequestHelper.ForVideoInterstitialAd(NimbusReportingPosition); // pass in user data, this is hardcoded as an examplebidRequest.User=newUser { Age =32, Gender ="male", Yob =1991 };return bidRequest; } /// <summary> /// Calling RequestAdAndLoad sends the RTB data object to Nimbus Servers immediately and if the server /// responds with an ad attempts to display it to the user /// </summary>privatestaticvoidShowAdToPlayerAtTriggerCheckPointImmediately() {var bidRequest =VideoOnlyInterstitialRequest();NimbusManager.Instance.RequestAdAndLoad(NimbusReportingPosition, bidRequest); } /// <summary> /// OnAdError will be invoked anytime the Nimbus Server cannot return an ad /// This includes anytime Nimbus returns a No Fill, which means integrated partners /// Do not have an ad return at this time /// </summary> /// <paramname="adUnit"></param>privatevoidOnAdError(NimbusAdUnit adUnit) {Debug.Log($"The Nimbus Auction ID {adUnit.ErrResponse.Id}");Debug.Log($"The Nimbus Error Message {adUnit.ErrResponse.Message}");Debug.Log($"The Nimbus Nimbus Status Code {adUnit.ErrResponse.StatusCode}");if (adUnit.ErrResponse.StatusCode==400) {Debug.Log($"There was a problem with the RTB request data, check the message"); } elseif (adUnit.ErrResponse.StatusCode==404) {Debug.Log($"Integrated partners did not have an ad to return, try again later"); } elseif (adUnit.ErrResponse.StatusCode==429) {Debug.Log($"The request to Nimbus was rate limited"); } elseif (adUnit.ErrResponse.StatusCode==500) {Debug.Log($"There was likely a transient server issue, try again later"); } } /// <summary> /// OnAdImpression is invoked anytime an ad is successfully rendered on screen /// </summary> /// <paramname="adUnit"></param>privatevoidOnAdImpression(NimbusAdUnit adUnit) {Debug.Log($"The Ad was successfully rendered"); } /// <summary> /// OnAdCompleted is invoked when the Interstitial ad is closed. Because Video Interstitial ads can closed /// after 5 seconds, we can check the adWasViewedToCompletion to determine if the user watched the entire ad /// of closed the ad early. Both states are valid, however perhaps the reward given to the user changes. /// </summary> /// <paramname="adUnit"></param> /// /// <paramname="adWasViewedToCompletion"></param>privatevoidOnAdCompleted(NimbusAdUnit adUnit,bool adWasViewedToCompletion) {if (adWasViewedToCompletion) {Debug.Log($"The user watched the entire video ad, 10 points given"); } else {Debug.Log($"The user watched the at least 5 seconds of the video ad, 5 points given"); } }}