Skip to content

6 - Integrate with a Consent Management Platform (CMP)

X3M provides a mechanism for automating the integration with Google's User Messaging Platform. To enable this feature, set the flag isCMPAutomationEnabled to true:

XMediatorAds.startWith(
    activity = activity,
    appKey = "<your-app-key>",
    initSettings = InitSettings(
        consentInformation = ConsentInformation(
            isCMPAutomationEnabled = true
        )
    ),
    initCallback = { result -> }
)
boolean isConsentInformationEnabled = true;

XMediatorAds.startWith(
        activity,
        "<your-app-key>",
        new InitSettings.Builder()
                .setConsentInformation(new ConsentInformation(
                        null,
                        null,
                        null,
                        isConsentInformationEnabled,
                        null))
                .build(),
        initResult -> {
            return Unit.INSTANCE;
        }
);

This will prompt the user for consent only when required, and continue with the SDK initialization after the signals have been collected.

Display a Privacy Settings button inside your app

To give users the option to change their consent during the session, you may want to display a button in your app's settings when a form is available. X3M's SDK provides the following methods to achieve this:

if (XMediatorAds.CMPProvider.isPrivacyFormAvailable(context)) {
    // ... display the privacy settings form button
}

// [...]

XMediatorAds.CMPProvider.showPrivacyForm(activity) { error ->
    if (error != null) {
        Log.d("PrivacyForm", "Error: $error")
    }

    Log.d("PrivacyForm", "showPrivacyForm complete!")
}
if (XMediatorAds.getCMPProvider().isPrivacyFormAvailable(context)) {
    // ... display the privacy settings form button
}

// [...]

XMediatorAds.getCMPProvider().showPrivacyForm(activity, error -> {
    if (error != null) {
        Log.d("PrivacyForm", "Error: $error");
    }

    Log.d("PrivacyForm", "showPrivacyForm complete!");
    return Unit.INSTANCE;
});

Debug your integration

When using the CMP Automation feature, you can use the following methods to debug your integration:

// Configure a Debug Geography to trigger Privacy Form display
XMediatorAds.startWith(
    activity = activity,
    appKey = "<your-app-key>",
    initSettings = InitSettings(
        consentInformation = ConsentInformation(
            isCMPAutomationEnabled = true,
            cmpDebugSettings = CMPDebugSettings(
                cmpDebugGeography = CMPDebugGeography.EEA  // Available options: Disabled, EEA and NotEEA
            )
        )
    ),
    initCallback = { result -> }
)

// Clear the collected consent signals from the device 
XMediatorAds.CMPProvider.reset(context)
// Configure a Debug Geography to trigger Privacy Form display
XMediatorAds.startWith(
        activity,
        "<your-app-key>",
        new InitSettings.Builder()
                .setConsentInformation(new ConsentInformation(
                        null,
                        null,
                        null,
                        isCMPAutomationEnabled,
                        new CMPDebugSettings(
                                CMPDebugGeography.EEA.INSTANCE  // Available options: Disabled, EEA and NotEEA
                        )))
                .build(),
        initResult -> {
            return Unit.INSTANCE;
        }
);

// Clear the collected consent signals from the device 
XMediatorAds.getCMPProvider().reset(context);