Google Analytics introduces Consent Mode v2, providing a streamlined approach to adjust your SDK's behavior based on user consent status. This feature lets you easily indicate whether consent has been granted for Analytics and Ads cookies. To implement Consent Mode v2 for your apps, follow these straightforward steps:
setConsent
method programmatically to update these values based on in-app user consent.For more information, see Consent mode on websites and mobile apps.
Consent Types | Consent Mode V2 | InMobi CMP (Web) | Description |
---|---|---|---|
ad_storage |
Mandatory | Supported | Enables storage for advertising, like web cookies or app device identifiers. |
analytics_storage |
Mandatory | Supported | Enables storage for analytics, e.g., visit duration cookies or app device identifiers. |
ad_user_data |
Mandatory | Supported | Consent is required to send user data to Google for online advertising. |
ad_personalization |
Mandatory | Supported | Consents to personalized advertising. |
After selecting GBC on the portal for AMP sites and saving it, you should copy the final AMP tag and update it on your AMP site. Unlike the non-AMP sites, you should manually update the AMP sites' tags after any configuration changes.
To enable GBC for your Android app, you need to first set the default consent state and values.
AndroidManifest.xml
file. Update the consent state based on the user interaction with the consent settings.AndroidManifest.xml
file since no consent mode values are pre-configured by default.google_analytics_default_allow_analytics_storage
google_analytics_default_allow_ad_storage
google_analytics_default_allow_ad_user_data
google_analytics_default_allow_ad_personalization_signals
<meta-data android:name="google_analytics_default_allow_analytics_storage" android:value="true" />
<meta-data android:name="google_analytics_default_allow_ad_storage" android:value="true" />
<meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="true" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="true" />
showGBCScreen(activity: Activity)
API to show the standalone popup:
fun showGoogleConsent() {
// Show Google basic consent
ChoiceCmp.showGBCScreen(this)
}
public void showGoogleConsent() {
// Show Google basic consent
ChoiceCmp.showGBCScreen(this);
}
onGoogleBasicConsentChange(consents: GoogleBasicConsents)
:
override fun onGoogleBasicConsentChange(consents: GoogleBasicConsents) {
Log.i("Ad Storage", consents.adStorage.value)
Log.i("AdUserData", consents.adUserData.value)
Log.i("AdPersonalization", consents.adPersonalization.value)
Log.i("AnalyticsStorage", consents.analyticsStorage.value)
}
@override
public void onGoogleBasicConsentChange(GoogleBasicConsents consents) {
Log.i("Ad Storage", consents.getAdStorage().getValue());
Log.i("AdUserData", consents.getAdUserData().getValue());
Log.i("AdPersonalization", consents.getAdPersonalization().getValue());
Log.i("AnalyticsStorage", consents.getAnalyticsStorage().getValue());
}
onGoogleBasicConsentChange(consents: GoogleBasicConsents)
callback and set the consent using the setConsent
method of Google’s Analytics API. The callback will be called only when Google consent is enabled in the portal and consent is given by the user. It won’t be called during the consecutive app launches.
You need to call the setConsent
method to set the consent provided by the callback API. InMobi CMP will NOT automatically set the setConsent
method.
The following example shows the setConsent
method updating values for Analytics, Ad storage, Ad user data and Ad personalization to granted or denied:
override fun onGoogleBasicConsentChange(consents: GoogleBasicConsents) {
Firebase.analytics.setConsent {
adStorage = getFirebaseAnalyticsConsentValue(consents.adStorage == GBCConsentValue.GRANTED)
adUserData = getFirebaseAnalyticsConsentValue(consents.adStorage == GBCConsentValue.GRANTED)
adPersonalization = getFirebaseAnalyticsConsentValue(consents.adStorage == GBCConsentValue.GRANTED)
analyticsStorage = getFirebaseAnalyticsConsentValue(consents.adStorage == GBCConsentValue.GRANTED)
}
}
fun getFirebaseAnalyticsConsentValue(value: Boolean): FirebaseAnalytics.ConsentStatus {
return if (value)
FirebaseAnalytics.ConsentStatus.GRANTED
else
FirebaseAnalytics.ConsentStatus.DENIED
}
@override
public void onGoogleBasicConsentChange(GoogleBasicConsents consents) {
// Set consent types.
Map<ConsentType, ConsentStatus> consentMap = new EnumMap<>(ConsentType.class);
consentMap.put(ConsentType.ANALYTICS_STORAGE, consents.getAnalyticsStorage() == GBCConsentValue.GRANTED ?
ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(ConsentType.AD_STORAGE, consents.getAdStorage() == GBCConsentValue.GRANTED ?
ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(ConsentType.AD_USER_DATA, consents.getAdUserData() == GBCConsentValue.GRANTED ?
ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(ConsentType.AD_PERSONALIZATION, consents.getAdPersonalization() == GBCConsentValue.GRANTED ?
ConsentStatus.GRANTED : ConsentStatus.DENIED);
mFirebaseAnalytics.setConsent(consentMap);
}
The value set by the setConsent
method persists across app executions and overrides the default values configured through the AndroidManifest.xml
file. The value remains in that state until setConsent
is called again, even if a user closes and reopens the app.
By installing this SDK update, you agree that your Children Privacy Compliance setting remains accurate or that you will update that setting, whenever there is a change in your app's audience. You may update the app's Children Privacy Compliance settings at https://publisher.inmobi.com/my-inventory/app-and-placements.