Google Analytics offers Consent Mode v2 to adjust how your SDK behaves based on the consent status of your users. You can indicate whether consent has been granted for Analytics and Ads cookies. To implement Consent Mode v2 for apps, use the Google Analytics for Firebase SDK to set default consent values and use the setConsent method to update these values programmatically, based on in-app user consent. To learn more, see Consent Mode.
Google Consent Mode allows you to configure the status for the following parameters or Consent Types:
ANALYTICS_STORAGE
AD_STORAGE
AD_USER_DATA
AD_PERSONALIZATION
Initial setup
By default, no Consent Type values are set. Follow the instructions below to change the default consent state for your app.
Analytics storage
To disable Analytics storage, set the value of google_analytics_default_allow_analytics_storage to false in the application tag of your app's AndroidManifest.xml file. For example:
To disable Ad storage, set the value of google_analytics_default_allow_ad_storage to false in the application tag of your app's AndroidManifest.xml file. For example:
To disable Ad user data, set the value of google_analytics_default_allow_ad_user_data to false in the application tag of your app's AndroidManifest.xml file. For example:
To disable Ad personalization, set the value of google_analytics_default_allow_ad_personalization_signals to false in the application tag of your app's AndroidManifest.xml file. For example:
To update the Consent Type values after an app has launched, call the setConsent method of the Analytics library.
The value set by the setConsent method persists across app executions and overrides the default values configured through the Info.plist and AndroidManifest.xml files . The value remains in that state until setConsent is called again, even if a user closes and reopens the app. Calling setConsent to modify Ad storage does not change the state of Analytics storage or any other consent mode value.
The following example shows the setConsent method updating values for Analytics, Ad storage, Ad user data and Ad personalization to granted or denied:
// Set consent types.Map<ConsentType,ConsentSetting> consentMap =newEnumMap<>(ConsentType.class);consentMap.put(ConsentType.ANALYTICS_STORAGE,ConsentStatus.GRANTED|ConsentStatus.DENIED);consentMap.put(ConsentType.AD_STORAGE,ConsentStatus.GRANTED|ConsentStatus.DENIED);consentMap.put(ConsentType.AD_USER_DATA,ConsentStatus.GRANTED|ConsentStatus.DENIED);consentMap.put(ConsentType.AD_PERSONALIZATION,ConsentStatus.GRANTED|ConsentStatus.DENIED);mFirebaseAnalytics.setConsent(consentMap);
To update the Consent Type values after a user has provided their consent choices, use the setConsent method of the Analytics library as shown in the examples below.
The status of Google Vendor with ID google will be used to get the value for:
AD_STORAGE
AD_USER_DATA
AD_PERSONALIZATION
The status of Google Analytics Vendor with ID c:googleana-4TXnJigR will be used to get the value for:
ANALYTICS_STORAGE
The following examples show how to get the user status from the Didomi SDK and apply that status to Google Consent Mode.
Didomi.getInstance().addEventListener(newEventListener() { @OverridepublicvoidconsentChanged(ConsentChangedEvent event) {// The status of the user has changedUserStatus userStatus =Didomi.getInstance().getUserStatus();// Ids of enabled vendorsSet<String> enabledVendorIds =userStatus.getVendors().getGlobal().getEnabled();// Search for Google vendors ConsentStatus googleAnalyticsStatus = enabledVendorIds.contains("c:googleana-4TXnJigR") ? ConsentStatus.GRANTED : ConsentStatus.DENIED
ConsentStatus googleStatus =enabledVendorIds.contains("google") ?ConsentStatus.GRANTED:ConsentStatus.DENIED// Set consent typesMap<ConsentType,ConsentSetting> consentMap =newEnumMap<>(ConsentType.class);consentMap.put(ConsentType.ANALYTICS_STORAGE, googleAnalyticsStatus);consentMap.put(ConsentType.AD_STORAGE, googleStatus);consentMap.put(ConsentType.AD_USER_DATA, googleStatus);consentMap.put(ConsentType.AD_PERSONALIZATION, googleStatus);mFirebaseAnalytics.setConsent(consentMap); }})
Didomi.getInstance().addEventListener(object : EventListener() {overridefunconsentChanged(event: ConsentChangedEvent) {// The status of the user has changedval userStatus = Didomi.getInstance().userStatus// Ids of enabled vendorsval enabledVendorIds = userStatus.vendors.global.enabled// Search for Google vendors val googleAnalyticsStatus = if (enabledVendorIds.contains("c:googleana-4TXnJigR")) ConsentStatus.GRANTED else ConsentStatus.DENIED
val googleStatus =if (enabledVendorIds.contains("google")) ConsentStatus.GRANTED else ConsentStatus.DENIED// Set consent types Firebase.analytics.setConsent { analyticsStorage = googleAnalyticsStatus adStorage = googleStatus adUserData = googleStatus adPersonalization = googleStatus } }})
let didomiEventListener =EventListener()didomiEventListener.onConsentChanged = { event in// The status of the user has changedlet userStatus = Didomi.shared.getUserStatus()// Ids of enabled vendorslet enabledVendorIDs = userStatus.vendors.global.enabled// Search for Google vendors let googleAnalyticsStatus: FirebaseAnalytics.ConsentStatus = enabledVendorIDs.contains("c:googleana-4TXnJigR") ? .granted : .denied
let googleStatus: FirebaseAnalytics.ConsentStatus = enabledVendorIDs.contains("google")? .granted : .denied// Set consent types Analytics.setConsent([ .analyticsStorage: googleAnalyticsStatus, .adStorage: googleStatus, .adUserData: googleStatus, .adPersonalization: googleStatus ])}
DDMEventListener *didomiEventListener = [[DDMEventListener alloc] init];
[didomiEventListener setOnConsentChanged:^(enum DDMEventType event) {
// The status of the user has changed
Didomi *didomi = [Didomi shared];
DDMUserStatus *userStatus = [didomi getUserStatus];
// Ids of enabled vendors
NSSet *enabledVendorIDs = [[[userStatus vendors] global] enabled];
// Search for Google vendors
FIRConsentType googleAnalyticsStatus = [enabledVendorIDs containsObject:@"c:googleana-4TXnJigR"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
FIRConsentType googleStatus = [enabledVendorIDs containsObject:@"google"] ? FIRConsentStatusGranted : FIRConsentStatusDenied;
// Set consent types
[FIRAnalytics setConsent:@{
FIRConsentTypeAnalyticsStorage : googleAnalyticsStatus,
FIRConsentTypeAdStorage : googleStatus,
FIRConsentTypeAdUserData : googleStatus,
FIRConsentTypeAdPersonalization : googleStatus
}];
}];
Enabling Consent mode's TCF integration
You can optionally enable Consent mode's TCF integration which will allow setting consent mode status from the user’s choice in the TC string.
Consent mode's TCF integration is only valid when you use both TCF integration and Google's Consent mode.
It is only valid for advertising consent types: ad_storagead_user_data and ad_personalization.
It does not apply to analytics_storage.
As of now, ad_user_data is only compatible with IAB purpose 7 (“Measure advertising performance”) being used in consent legal basis for the Vendor Google Advertising Products.
To enable this integration:
Login to the Didomi Console.
Go to Consent notices and select your Mobile App consent notice.
Navigate to Customization -> Integrations -> Advertising.
Make sure the Consent mode integration checkbox is selected.
Select the option "Enable IAB TCF integration with Google Consent Mode". Click on Save.
Add the publisher restriction for IAB Purpose #7 on the Vendor Google Advertising Products. To do so:
Navigate to Regulations -> GDPR -> Edit vendors & purposes
Go to TCF settings -> IAB TCF Publisher Restrictions
Click "Add restriction"
Choose purpose "Measure advertising performance"
Un-select "All IAB vendors".
Publish your notice.
In the code of your Mobile app make sure you do not setConsent for the following consent types:
ad_storage
ad_user_data
ad_personalization
Make sure setConsent is still done for analytics_storage.
As a result:
When user consent is collected on your CMP, the Didomi SDK will setup the IABTCF_EnableAdvertiserConsentMode key on NSUserDefaults (iOS) and Shared Preferences (Android) to true .
Consent mode status for ad_storagead_user_data and ad_personalization will then be calculated from the status of TCF purposes in the TC string, as defined in this documentation.
analytics_storage is not impacted by Consent mode's TCF integration, and must be covered by setConsent as documented above.