Fullscreen Ad
Fullscreen ads typically take over the entire screen of the device.
FullscreenAdLoadRequest
π
FullscreenAdLoadRequest
objects contains publisher provided configurations for IFullscreenAds
. It is used when calling ChartboostMediation.LoadFullscreenAd
, as seen in the examples below:
// Create FullscreenAdLoadRequest with no keywords nor partner settings
FullscreenAdLoadRequest fullscreenAdRequest = new FullscreenAdLoadRequest("FULLSCREEN_PLACEMENT_ID");
Keywords π
Keywords are key-value pairs to enable real-time targeting on line items.
For IFullscreenAd
objects, keywords are passed in the FullscreenAdLoadRequest
object when calling ChartboostMediation.LoadFullscreenAd
, seen in the example below:
// Keywords to pass for fullscreen ad
var keywords = new Dictionary<string, string>
{
{ "key", "value" },
{ "key_2", "value_2" }
};
// Create FullscreenAdLoadRequest with keywords
FullscreenAdLoadRequest fullscreenAdRequest = new FullscreenAdLoadRequest("FULLSCREEN_PLACEMENT_ID", keywords);
Partner Settings π
An optional IDictionary<string, string>
setting to send to all partners.
// Partner settings
var partnerSettings = new Dictionary<string, string>
{
{ "setting_1", "value" },
{ "setting2", "value_2" }
};
// Create FullscreenAdLoadRequest with keywords previous example and a partnersettings.
FullscreenAdLoadRequest fullscreenAdRequest = new FullscreenAdLoadRequest("FULLSCREEN_PLACEMENT_ID", keywords, partnerSettings);
LoadFullscreenAd
π
In order to load IFullscreenAd
objects, you will need to call ChartboostMediation.LoadFullscreenAd
.
Load in async Context π
// Load `IFullscreenAd` using async approach and our previously built FullscreenAdLoadRequest
FullscreenAdLoadResult fullscreenAdLoadResult = await ChartboostMediation.LoadFullscreenAd(fullscreenAdRequest);
...
Load in sync Context π
A lot of APIs provided in the Chartboost Mediation Unity SDK utilize the async/await C# implementation. It is possible to call the following code from a sync context where async/await might not be supported:
ChartboostMediation.LoadFullscreenAd(fullscreenAdRequest).ContinueWithOnMainThread(continuation =>
{
FullscreenAdLoadResult fullscreenAdLoadResult = continuation.Result;
...
});
FullscreenAdLoadResult
π
The FullscreenAdLoadResult
object contains information for the requested IFullscreenAd
load request. The information inside can be used as follows:
// Check if an error occurred
ChartboostMediationError? error = fullscreenAdLoadResult.Error;
// Load failed
if (error.HasValue)
{
// Report load failure
Debug.LogError($"`IFullscreenAd` Load failed with error: {JsonTools.SerializeObject(error.Value, Formatting.Indented)}");
return;
}
// Load succeeded
// Parse load result data
var loadId = fullscreenAdLoadResult.LoadId;
var winningBidInfoJson = JsonTools.SerializeObject(fullscreenAdLoadResult.WinningBidInfo, Formatting.Indented);
var metricsJson = JsonTools.SerializeObject(fullscreenAdLoadResult.Metrics, Formatting.Indented);
// Report fullscreen ad load result information
Debug.Log($"`IFullscreenAd` load completed with: LoadId{loadId} WinningBidInfo: {winningBidInfoJson}, Metrics: {metricsJson}");
// Obtain IFullscreenAd
IFullscreenAd ad = fullscreenAdLoadResult.Ad;
// Subscribing IFullscreenAd Instance Delegates
ad.DidClick += fullscreenAd => Log($"DidClick Name: {fullscreenAd.Request.PlacementName}");
ad.DidClose += (fullscreenAd, error) => Debug.Log(!error.HasValue ? $"DidClose Name: {fullscreenAd.Request.PlacementName}" : $"DidClose with Error. Name: {fullscreenAd.Request.PlacementName}, Code: {error?.Code}, Message: {error?.Message}");
ad.DidReward += fullscreenAd => Log($"DidReward Name: {fullscreenAd.Request.PlacementName}");
ad.DidRecordImpression += fullscreenAd => Log($"DidImpressionRecorded Name: {fullscreenAd.Request.PlacementName}");
ad.DidExpire += fullscreenAd => Log($"DidExpire Name: {fullscreenAd.Request.PlacementName}");
Custom Data π
Custom data may be set at any time before calling Show()
.
...
IFullscreenAd ad = fullscreenAdLoadResult.Ad;
// Set custom data
ad.CustomData = "SOME_CUSTOM_DATA";
CustomData
property is found on the IFullsreenAd
instance, and has a maximum character limit of 1000
characters. In the event that the limit is exceeded, the CustomData
property will be set to null.
Show
π
Once the load process for the IFullscreenAd
object has been completed, you will need to call IFullscreenAd.Show
, as seen in the examples below:
Show in async Context π
...
// Show `IFullscreenAd` using async approach
AdShowResult adShowResult = await ad.Show();
...
Show in sync Context π
A lot of APIs provided in the Chartboost Mediation Unity SDK utilize the async/await C# implementation. It is possible to call the following code from a sync context where async/await might not be supported:
...
// Show `IFullscreenAd` using async approach
ad.Show().ContinueWithOnMainThread(continuation =>
{
AdShowResult adShowResult = continuation.Result;
...
});
AdShowResult
π
The AdShowResult
object contains information for the requested IFullscreenAd
show result. The information inside can be used as follows:
...
// Check if IFullscreenAd failed to show
var error = adShowResult.Error;
// Failed to show
if (error.HasValue)
{
// Report show failure
Debug.LogError($"`IFullscreenAd` Show failed with error: {JsonTools.SerializeObject(error.Value, Formatting.Indented)}");
return;
}
// Show succeeded
// Report metrics and show success
var metricsJson = JsonTools.SerializeObject(adShowResult.Metrics, Formatting.Indented);
Debug.Log($"`IFullscreenAd` show completed with: Metrics: {metricsJson}");
...
Dispose
π
IFullscreenAd
objects implement the IDisposable to properly dispose of managed and unmanaged resources.
You can free up resources directly by calling IFullscreenAd.Dispose
.
...
IFullscreenAd ad = fullscreenAdLoadResult.Ad;
// Do what we need to do with our IFullscreenAd
// Free up resources
ad.Dispose();
IFullscreenAd
objects will be disposed by the garbage collector once they are no longer referenced. It is still a good practice to disposed of unmanaged resources when no longer needed.