Google CMP
Handle consent using Google User Messaging Platform
Requirements
Obtain a Google app ID by following the Google Funding Choices Help Center instructions.
Set the Google appID in the AndroidManifest.xml file:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR-APP-ID"/>
Add the Google CMP dependency to your build.gradle:
implementation ('com.google.android.ump:user-messaging-platform:3.1.0')
Make sure, your Google CMP has been set up at its backend dashboard. Our support recommends certain vendors to be included in your server-side setup in order to yield optimal revenues. We also recommend that CMP should be geographically targeted to "Everywhere", for handling of opt-out consent scenarios. Please also refer to your Google CMP’s documentation.
Usage
Follow the instructions in the Managed Consent introduction section.
Create an instance of
CMPGoogle
(CMPGoogle
implementsCMP
interface).Pass the created
CMPGoogle
instance while creating the ManagedConsent using thepublic constructor ManagedConsent(cmp: CMP, context: Context, delegate: ManagedConsent.ManagedConsentDelegate)
.
private ManagedConsent managedConsent;
public void onActivityReady(Activity activity) {
if (managedConsent == null) { //we want to do it only once
CMP cmp = new CMPGoogle(activity);
managedConsent = new ManagedConsent(cmp, this, this);
AATKitRuntimeConfiguration newConf = new AATKitRuntimeConfiguration();
newConf.setConsent(managedConsent);
AATKit.reconfigure(newConf);
managedConsent.showIfNeeded(activity);
OR
managedConsent.showIfNeededOrRejected(10, activity);
}
}
// ManagedConsentDelegate implementation
@Override
public void managedConsentNeedsUserInterface(@NonNull ManagedConsent managedConsent) {
// CMP is loaded and ready to be shown
// Show the CMP using active Activity
managedConsent.showIfNeeded(<ACTIVITY_INSTANCE>);
OR
managedConsent.showIfNeededOrRejected(10, <ACTIVITY_INSTANCE>)
}
@Override
public void managedConsentCMPFinished(@NonNull ManagedConsent.ManagedConsentState state) {
// The user finished his action with CMP with the state as the user chosen state
}
@Override
public void managedConsentCMPFailedToLoad(@NonNull ManagedConsent managedConsent, String error) {
// CMP failed to load with the error message.
// Consider reloading the CMP using the active Activity:
// managedConsent.reload(<ACTIVITY_INSTANCE>);
// if you know that the user is in GDPR region
}
@Override
public void managedConsentCMPFailedToShow(@NonNull ManagedConsent managedConsent, String error) {
// CMP failed to show with the error message
}
Last updated