广告聚合

Integrate Network SDKs

Dependency Resolution & Google External Dependency Manager (EDM) 🔗

The Chartboost Mediation Unity SDK does not embed Google’s EDM plugin.

If you want to integrate ad networks with other supported SDKs as well, you will need Google’s External Dependency Manager. For more information see our recommended setup in Google External Dependency Manager (EDM).

Chartboost Mediation Adapters Window 🔗

Since Chartboost Mediation 4.X Adapters are no longer released at the cadence as the Chartboost Mediation SDK, it is now possible to receive adapter updates in between SDK releases.

Until Chartboost Mediation Unity SDK 4.1.0, adapters were added through the UPM Samples capability; however, this limited the ability to provide adapter updates in between SDK releases. As such, from Chartboost Mediation Unity SDK 4.2.0, we have created a brand new Editor Window. This will allow users to fetch Ad Adapter updates on demand. see screenshot below

Adapters Window Default State 🔗

The Adapters window can be accessed through the following unity menu: Chartboost Mediation/Configure

Chartboost Mediation Settings

As seen, in the screenshot above, in its default state, the Adapters Window does not select any adapters, and there are multiple elements grabbing your attention. For a detailed step-by-step instruction on how to use the window see below:

ChartboostMediationDependencies.xml 🔗

Although Chartboost Mediation Unity SDK can be initialized without adapters. You still need to have a reference to the Chartboost Mediation Native libraries. Whenever such dependencies are missing or miss-matching with your currently implemented version, the following warning button will show up.

Chartboost Mediation Settings

If you wish to know more details, you can always hover over the warning to see more details. In order to resolve the warnings, you just need to press the warning button itself. In most scenarios, this will add or update your ChartboostMediationDependencies.xml dependency file.

After resolving the warnings, the ChartboostMediationDependencies.xml dependency file can be found in the following path Assets/com.chartboost.mediation/Editor/ChartboostMediationDependencies.xml

Adding Ad Adapters 🔗

In order to add adapters, you only need to select a version from the platform specific dropdowns.

Chartboost Mediation Settings

As seen in the screenshot above, whenever changes are pending to be saved, the save button will be displayed. In order to save your adapter selections you must click on the save button. After saving, the corresponding dependencies for the Ad Adapter selections will be saved in the following path Assets/com.chartboost.mediation/Editor/Adapters.

Window Utilities 🔗

Upgrade All Selections 🔗

Once you have all of your selections, you can always manually check for updates by pressing the upgrades button. Found in the top right corner. Using the upgrade button will compare your current selections with the most up to date adapter releases. If any changes are found, you will be notified and asked to save such changes.

Chartboost Mediation Settings

Refresh 🔗

Adapter information is fetched automatically on Unity Editor’s startup. If you wish you check for updates on demand, you can use the refresh button.

Chartboost Mediation Settings

Using the refresh button will check for new adapter releases, update your cached adapter info, and repaint the Adapters Window if necessary.

Adapters Window Unity Editor C# API 🔗

Along with the Editor Window, we have exposed a few C# methods that can be utilized in a CI/CD environment to keep your adapters up to date.

Below is a demonstration on how to use such API:


// AdapterDataSource is in charge of fetching adapter updates, runs once on Editor startup, but you will need to call it manually if running in batchmode
AdapterDataSource.Update();

// Loads current project adapter selections
AdaptersWindow.LoadSelections();

// Perform Ad Adapter upgrades, platform flags available for customization
var upgrades = AdaptersWindow.UpgradePlatformToLatest(Platform.Android | Platform.IOS);

// Depending on upgrade results, information can be logged.
Console.WriteLine(upgrades.Count > 0 ? $"[Adapters] Upgraded: \n {JsonConvert.SerializeObject(upgrades, Formatting.Indented)}" : "[Adapters] No Upgrades.");

// Ad newly found Ad Adapter networks, by default any partially implemented or newly found networks will be added, but such behavior can be customized.
var newNetworks = AdaptersWindow.AddNewNetworks(Platform.Android | Platform.IOS);

// Manually save selections
AdaptersWindow.SaveSelections();

// Depending on new networks result, information can be logged.
Console.WriteLine(newNetworks.Count > 0 ? $"[Adapters] New Networks: \n {JsonConvert.SerializeObject(newNetworks, Formatting.Indented)}" :  "[Adapters] No New Networks");

// This will resolve any issues with your Chartboost Mediation dependency, e.g if your package does not match your current dependency file, this method makes sure to update the file as needed.
var changed = AdaptersWindow.CheckChartboostMediationVersion();
Console.WriteLine(changed ? "[Adapters] Chartboost Mediation Version Has Been Updated" :  "[Adapters] Chartboost Mediation Version is Up to Date");

Adding Networks through the C# API 🔗

As mentioned in the previous section, networks can be added based on specific conditions.

Default Network Addition Condition 🔗

/// <summary>
/// Default network add condition. This will add any entirely missing or partially implemented networks
/// </summary>
/// <param name="id">network id</param>
/// <param name="currentSelections">current selections</param>
/// <returns></returns>
private static bool DefaultAddCondition(string id, Dictionary<string, AdapterSelection> currentSelections) => !selections.ContainsKey(id) || selections[id].android == Constants.Unselected || selections[id].ios == Constants.Unselected;

Such condition is checked automatically when running AdaptersWindow.AddNewNetworks. However, it can be customized to fit your own needs.


// The method below will only add brand new networks and implemented them as needed.
private bool CustomCondition(string id, Dictionary<string, AdapterSelection> currentSelections) => !selections.ContainsKey(id);

// Addding networks only if they are entirely new
AdaptersWindow.AddNewNetworks(Platform.Android | Platform.IOS, CustomCondition);

// Another example, adding only brand new networks for Android
AdaptersWindow.AddNewNetworks(Platform.Android, CustomCondition);

Starting Chartboost Mediation 4.7.0, we have included APIs pertinent to ad adapter partner consents.

Consent can now be set on a case by case basis. The Partners.cs data class contains all of the supported Partner IDs. If you do not see your Partner there contact support for details.

Setting Partner Consents 🔗

Partner consent can be set on an individual basis using the following API:

// In this example we set AdMob's Consent to True. Granted!
ChartboostMediation.PartnerConsents.SetPartnerConsent(Partners.AdMob, true);

// Set Mintegral's Consent to False. Denied!
ChartboostMediation.PartnerConsents.SetPartnerConsent(Partners.Mintegral, false);

Partner consent can also be set as a predefined collection using the following API:

var consents = new Dictionary<string, bool>
{
    { Partners.AdMob, true },
    { Partners.Mintegral, false }
};
ChartboostMediation.PartnerConsents.AddPartnerConsents(consents);

Getting Current Partner Consents 🔗

Consents can be fetched utilzing the following API:

var consents = ChartboostMediation.PartnerConsents.GetPartnerIdToConsentGivenDictionaryCopy();
// Base on the examples provided before, this would outout "Current Consent: { "admob" : "true", "mintegral" : "false" }".
Debug.Log($"Current Consent: {JsonConvert.SerializeObject(consents)}");

Removing Partner Consents 🔗

Consent can be removed on a case by case basis with the following API:

// Remove AdMob Consent, RemovePartnerConsent returns the value attached to the Partner. Base on the previous examples this would be `true`.
var adMobConsent = ChartboostMediation.PartnerConsents.RemovePartnerConsent(Partners.AdMob);

// Remove Mintegral Consent, RemovePartnerConsent returns the value attached to the Partner. Base on the previous examples this would be `false`.
var mintegralConsent = ChartboostMediation.PartnerConsents.RemovePartnerConsent(Partners.Mintegral);

// Removing consent for a network without consent set returns `null`.
var vungleConsent = ChartboostMediation.PartnerConsents.RemovePartnerConsent(Partners.Vungle);

To remove consent for all partners:

ChartboostMediation.PartnerConsents.ClearConsents();

To replace consent with an entirely new set of values:

var consents = new Dictionary<string, bool>
{
    { Partners.Vungle, true },
    { Partners.Mintegral, true }
};

ChartboostMediation.PartnerConsents.ReplacePartnerConsents(consents);

var consents = ChartboostMediation.PartnerConsents.GetPartnerIdToConsentGivenDictionaryCopy();
// Base on the examples provided before, the new output would be "Current Consent: { "vungle" : "true", "mintegra" : "true" }".
Debug.Log($"Current Consent: {JsonConvert.SerializeObject(consents)}");

Adapters Information 🔗

Partner ad adapter information can now be fetched utilizing the following API:


// Adapter information is conformed to the `AdapterInfo.cs` data class.
Debug.Log($"Current Adapters: {JsonConvert.SerializeObject(ChartboostMediation.AdaptersInfo)}");

// Logging each adapter information.
foreach (var adapter in ChartboostMediation.AdaptersInfo)
{
    Debug.Log($"Logging Adapter v-{adapter.AdapterVersion}, partner v-{adapter.PartnerVersion}, partner id:{adapter.PartnerIdentifier}, partner display:{adapter.PartnerDisplayName}");
}

The above APIs allows you to manage consent details more effectively. The following example shows another variation of using the APIs. Please note that user consent should be managed with care.


// Get your current user consent status.
var myUserConsentStatus = FetchUserConsent();

foreach (var adapter in ChartboostMediation.AdaptersInfo)
    ChartboostMediation.PartnerConsents.SetPartnerConsent(adapter.PartnerIdentifier, myUserConsentStatus);

Disabling Adapters Window 🔗

If you are utilizing Chartboost Mediation SDK to create your own ad mediation solution and want to disable the adapters window to users, use the following APIs:

// Disables adapters window for all available platforms.
ChartboostEditorConfiguration.DisableAdaptersWindow();

// Enables adapters window for all available platforms.
ChartboostEditorConfiguration.EnableAdaptersWindow();

// Disables MenuItems to configure Chartboost Mediation Unity SDK, while keeping the APIs compiled. This will be called automatically if all configuration windows are disabled.
ChartboostEditorConfiguration.DisableConfigurability();