Integration
In this section,
- Integrate a consent management platform
- Initialize Core SDK with modules
- Set optional per publisher metadata
Consent Management Platform π
The Core SDK requires a Consent Management Platform (CMP) to manage the current consent state of the user and to provide consent change notifications.
Chartboost supports the following CMP providers with open source CMP adapters for the Core SDK.
Google User Messaging Platform π
Open source CMP adapter | https://github.com/ChartBoost/chartboost-core-unity-consent-adapter-google-user-messaging-platform |
To include the Google User Messaging Platform adapter into your Unity project via Unity Package Manager, add the following and refer to the CMPβs adapter repository for the latest compatible version.
"dependencies": {
"com.chartboost.core.consent.google-user-messaging-platform": "{{version}}",
...
},
"scopedRegistries": [
{
"name": "NpmJS",
"url": "https://registry.npmjs.org",
"scopes": [
"com.chartboost"
]
}
]
To include the Google User Messaging Platform adapter into your Unity project via NuGet, you will first need to add the NugetForUnity package into your Unity project as below:
"dependencies": {
"com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
...
}
Once NugetForUnity
is installed, search for the following in the search bar of the Nuget Explorer window (Nuget > Manage Nuget Packages). Choose the appropriate version and install.
Chartboost.CSharp.Core.GoogleUserMessagingPlatform.Unity
Usercentrics π
Open source CMP adapter | https://github.com/ChartBoost/chartboost-core-unity-consent-adapter-usercentrics |
When setting up your Usercentrics account, it is required to use a TCF2 configuration so Usercentrics provides consent info as a TCF string, which is used by most advertising partners. The CCPA configuration is also encouraged. You can achieve a hybrid setup with these and other configurations by using Usercentrics geolocation rulesets.
For more info refer to Usercentrics account setup and Usercentrics user guide to account interface docs.
To include the Usercentrics adapter into your unity project via Unity Package manager, add the following and refer to the CMPβs adapter repository for the latest compatible version.
"dependencies": {
"com.chartboost.core.consent.usercentrics": "{{version}}",
...
},
"scopedRegistries": [
{
"name": "NpmJS",
"url": "https://registry.npmjs.org",
"scopes": [
"com.chartboost"
]
}
]
To include the Usercentrics adapter into your Unity project via NuGet, you will first need to add the NugetForUnity package into your Unity project as below:
"dependencies": {
"com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
...
}
Once NugetForUnity
is installed, search for the following in the search bar of the Nuget Explorer window (Nuget > Manage Nuget Packages). Choose the appropriate version and install.
Chartboost.CSharp.Core.Consent.Usercentrics.Unity
Integrating Consent Management Platform π
The ConsentManagementPlatform
is the entry point for integrating your CMP via CMP mediation. There are two ways of integrating consent depending upon your appβs use case.
Note that some CMPs do not support the Publisher Handled Consent use case. The table below shows which CMPs are able to perform the following use cases.
Consent Management Platform | CMP Handled Dialog (Concise) | CMP Handled Dialog (Detailed) | Publisher Handled Dialog |
---|---|---|---|
Google User Messaging Platform | β | β | β |
Usercentrics | β | β | β |
CMP Handled Consent Dialog π
This is the most straightforward use case where you simply want to use the consent dialog that your CMP provides. In the event that your CMP provides no consent dialog, no consent dialog will be shown.
Concise dialogs are the standard user-facing consent dialogs that are typical of the web world. Detailed consent dialogs are much more verbose and typically allows users to pick and choose each individual item they are consenting to.
As a general rule of thumb, use the concise dialogs for the initial user presentation of the consent dialog, and use the detailed consent dialog for users wishing to make modifications to their consent.
if (ChartboostCore.Consent.ShouldCollectConsent)
{
var success = await ChartboostCore.Consent.ShowConsentDialog(ConsentDialogType.Concise);
Debug.Log(success ?
"Consent dialog presented." :
"Failed to present consent dialog");
}
else
{
Debug.Log("No need to show consent dialog");
}
Publisher Handled Consent Dialog π
For advanced Publishers who wish to manage the consent dialog themselves, the following examples demonstrate how to use ConsentManagementPlatform
to set the userβs consent programmatically.
if (ChartboostCore.Consent.ShouldCollectConsent)
{
var granted = await ChartboostCore.Consent.GrantConsent(ConsentSource.Developer);
Debug.Log(granted ? "consent granted." : "Failed to grant consent");
// OR
var denied = await ChartboostCore.Consent.DenyConsent(ConsentSource.Developer);
Debug.Log(denied ? "consent denied." : "Failed to deny consent");
}
else
{
Debug.Log("No need to grant or deny consent");
}
Unsupported CMPs π
If you are using a CPM that Chartboost Core doesnβt support, a custom CMP adapter module must be created. This has the benefits of being able to swap out CMPs easily and allows for a high degree of customization for your specific consent workflow. Additionally, a custom CMP adapter can be reused across multiple apps, cutting down on maintenance and improving quality.
See Creating a Module to set up a custom CMP adapter module.
Per-Partner Consent π
For advanced use cases, it may be desirable to specify consent on a per-Mediation partner basis. In lieu of specifying per-partner consent, the global consent of the CMP is used. Per-partner consent values take precedence over the global consent.
Not all CMPs support per-partner consent. The table below lists per-partner consent compatibility.
Per-partner consent is usually available via the detailed consent dialog. These consent signals will be sent to the Mediation partner adapters and applied in higher priority over the global consent settings.
Consent Management Platform | Per-Partner Consent Supported? |
---|---|
Google UMP | β |
Usercentrics | β |
Initializing Core with Modules π
The Core SDK and all specified modules will be initialized when ChartboostCore.initializeSDK()
is called.
By default, the following module initializations will automatically be attempted without the Publisher needing to explicitly specify the module name when calling ChartboostCore.initializeSDK()
.
Module |
---|
Chartboost Mediation |
Initialization Flow π
Once ChartboostCore.initializeSDK()
has been called, the Core SDK initialization flow is as follows:
Core SDK Initialization flow can be broken down into two concurrent processes: locally specified modules and remotely specified modules.
Locally specified modules are modules that are explicitly specified by the Publisher in the SDKConfiguration
object passed into the ChartboostCore.initializeSDK()
call. These modules will be initialized immediately and do not wait for the configuration endpoint response.
Remotely specified modules are modules that are specified by the configuration endpoint. On a fresh install, these modules wonβt be initialized until the configuration endpoint has given back a response. For subsequent launches when a cached configuration is available, the cached configuration will be used to initialize the modules it knows about to speed up initialization as much as possible.
Advanced Features π
Skipping Specific Modules π
Sometimes it is desirable to skip the initialization of certain modules. This may be due to employing multipart module initialization, or disabling a module due to performance issues or crashing.
To skip specific modules, populate the skippedModuleIDs
property of the SDKConfiguration
object that is passed into the ChartboostCore.initializeSDK()
call.
See Initialization Examples for more information.
Multipart Module Initialization π
The Core SDK supports multipart module initialization. This is an advanced use case where a Publisher wants to fully control what modules are initialized at various points in their appβs launch lifecycle. This allows for modules critical to app functionality to initialize first, and then some time later, initialize the non-essential or nice to have modules in a subsequent ChartboostCore.initializeSDK()
call.
For example, a Publisher may wish to initialize an analytics module only at app launch, and then initialize the mediation module after a gameβs assets have finished loading.
See Initialization Examples for more information.
Handling Module Initialization Callbacks π
When initializing modules, you have the option of getting notified when a module completes its initialization. To do so, pass in an instance conforming to ModuleObserver
into the ChartboostCore.initializeSDK()
call.
Note that initializing an already-initialized module may trigger duplicate notifications to this observer, and initializing an initializing module will be a no-op.
A ModuleInitializationResult
is given back once the moduleβs initialization is complete. The result contains various metrics pertaining to that particular module initialization attempt as well as the instance of the module itself.
CMP Adapter Initialization π
CMP adapters are considered to be modules by the Core SDK. While it is not explicitly necessary to initialize the Core SDK with a CMP module, failure to do so will have the following effects:
- Downstream modules reliant upon consent information will not have any available and will assume that they are operating in an unconsented environment.
- Calls made to
ConsentManagementPlatform
will be no-op as there is no CMP to forward the calls to.
In the event that more than one CMP adapter is specified for initialization, the first one will be used.
The Core SDK currently does not support multiple initialized instances of CMPs. If your consent use case requires the usage of multiple CMPs at the same time, it is recommended that you create a custom CMP adapter to achieve your use case.
See Creating a Module for more information.
Module Initialization Errors and Exceptions π
While the ChartboostCore.initializeSDK()
call can accept a nil value for the moduleObserver
parameter, it is highly recommended to provide an observer to receive module initialization callbacks. This will allow you to handle any errors or exceptions that may occur during a moduleβs initialization, and be notified when a module is ready for use.
Initialization Examples π
Normal π
Normal initialization workflow examples prioritizing simplicity of integration.
The following code snippets demonstrate:
- Creating a CMP module that will be used as the source of truth for consent changes and values.
- Initializing Chartboost Core and the CMP module
- Subscribing to the initialization completion callback
// Create a CMP module such as the UsercentricsAdapter
var cmpModule = new UsercentricsAdapter(
new UsercentricsOptions(settingsId: "PUBLISHER_USERCENTRICS_SETTINGS_ID"),
// map of usercentrics template IDs to chartboost partner IDs. This is used for per-partner consent. There are defaults so this is used for only custom partners.
templateIdToPartnerId: templateIdToPartnerId
);
// Initialize Core with this CMP module
ChartboostCore.ModuleInitializationCompleted += OnInitializationComplete;
ChartboostCore.Initialize(new SDKConfiguration(
chartboostApplicationIdentifier: "PUBLISHER_CHARTBOOST_APP_ID",
modules: new List<Module> {cmpModule})
);
void OnInitializationComplete(ModuleInitializationResult result)
{
Debug.Log(result.Error.HasValue
? $"Module {result.ModuleId} initialized with error: {result.Error?.Message}"
: $"Module {result.ModuleId} initialized with success"
);
}
Advanced π
Advanced initialization workflow examples for the advanced features.
The following code snippets demonstrate:
- Creating a CMP module that will be used as the source of truth for consent changes and values.
- Creating a custom module to be initialized first.
- Initializing Chartboost Core, the CMP module, and the custom module, but skipping the automatic initialization of the Chartboost Mediation module.
- Subscribing to the initialization completion callback.
- Waiting a predefined set of time to simulate performing other work related to the app.
- Initializing Chartboost Core again with the Chartboost Mediation module.
// Create a CMP module such as the UsercentricsAdapter
var usercentricsAdapter = new UsercentricsAdapter(
new UsercentricsOptions(settingsId: "PUBLISHER_USERCENTRICS_SETTINGS_ID"),
templateIdToPartnerId: templateIdToPartnerId
);
// Create a custom module
var customModule = new CustomModule();
// Initialize Core with this CMP module and Custom Module and skip Mediation
ChartboostCore.ModuleInitializationCompleted += OnInitializationCompleted;
ChartboostCore.Initialize(new SDKConfiguration(
chartboostApplicationIdentifier: "PUBLISHER_CHARTBOOST_APP_ID",
modules: new List<Module> {customModule, usercentricsAdapter},
skippedModuleIdentifiers: new HashSet<string> { ChartboostMediation.CoreModuleId }
));
// Wait some time as an example
await Task.Delay(5000);
// Initialize Core again allowing Mediation Module to initialize
ChartboostCore.ModuleInitializationCompleted += OnInitializationCompleted;
ChartboostCore.Initialize(new SDKConfiguration(
chartboostApplicationIdentifier: "PUBLISHER_CHARTBOOST_APP_ID",
modules: new List<Module>()
));
void OnInitializationCompleted(ModuleInitializationResult result)
{
Debug.Log(result.Error.HasValue
? $"Module {result.ModuleId} initialized with error: {result.Error?.Message}"
: $"Module {result.ModuleId} initialized with success");
ChartboostCore.ModuleInitializationCompleted -= OnInitializationCompleted;
}
Setting Publisher Metadata π
Publishers may optionally set additional information that may be used by any of the modules within the ecosystem to enhance their performance or supplement consent.
The following examples demonstrate setting each of the Publisher metadata fields.
ChartboostCore.PublisherMetadata.SetFramework("Unity", "2022.12345.12345");
ChartboostCore.PublisherMetadata.SetIsUserUnderage(true);
ChartboostCore.PublisherMetadata.SetPlayerIdentifier("player_12345");
ChartboostCore.PublisherMetadata.SetPublisherAppIdentifier("app_id_12345");
ChartboostCore.PublisherMetadata.SetPublisherSessionIdentifier("session_12345");