Mediation

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";

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();