Google Consent Mode
Introduction
Google Consent Mode is a way to set the behaviour of the Firebase Analytics SDK by specifying the consent decisions of the user. This can be achieved
by calling the setConsent
method of the Firebase SDK with one of the consent types. Cookie Information's Mobile Consent Management platform allows you to
effortlessly manage your users' consents ant update Firebase using Consent Mode to ensure compliance with regulations.
Consent Mode 2.0 supports the following consent types:
ad_user_data
ad_storage
ad_personalization
analytics_storage
Prerequisites
By default, no consent mode values are set. In order to comply with privacy regulations explicit consent is required before data collection is started. To prevent Firebase from collecting such information, you need to specify default values for the above mentioned consent types.
Android
To disable data collection and storage by default add the following XML AndroidManifest.xml
<meta-data android:name="google_analytics_default_allow_ad_user_data"
android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_storage"
android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals"
android:value="false" />
<meta-data android:name="google_analytics_default_allow_analytics_storage"
android:value="false" />
iOS
To disable data collection and storage by default add the following key-value pairs to the Info.plist
of your application.
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key>
<false/>
Update consent
It is cruitial to inform the Firebase SDK when the user changes their consent. To update consent values after an app has launched, call the setConsent
method.
The value set by the setConsent method overrides the default setting and persists across app executions. The value remains in that state until
setConsent
is called again, even if a user closes and reopens the app. setConsent
only updates the parameters you specify.
Android
The setConsent
method is used to update the consents in the Firebase SDK:
Firebase.analytics.setConsent {
analyticsStorage(<consent status>)
adStorage(<consent status>)
adUserData(<consent status>)
adPersonalization(<consent status>)
}
Using the Cookie Information Android SDK you can retrieve the latest user consents. The consent decisions are stored as Boolean, so they need to be mapped to ConsentStatus.GRANTED
and ConsentStatus.DENIED
to be used with Firebase.
lifecycleScope.launch {
(applicationContext as App).sdk.getSavedConsentsWithType(object : CallListener<Map<UUID, ConsentWithType>> {
override fun onSuccess(result: Map<UUID, ConsentWithType>) {
val mapped = result.values.associate { it.type to it.consented }
Firebase.analytics.setConsent {
analyticsStorage(if(mapped[ConsentItem.Type.TypeStatistical] == true) ConsentStatus.GRANTED else ConsentStatus.DENIED )
adStorage(if(mapped[ConsentItem.Type.TypeMarketing] == true) ConsentStatus.GRANTED else ConsentStatus.DENIED )
adUserData(if(mapped[ConsentItem.Type.TypeMarketing] == true) ConsentStatus.GRANTED else ConsentStatus.DENIED )
adPersonalization(if(mapped[ConsentItem.Type.TypeFunctional] == true) ConsentStatus.GRANTED else ConsentStatus.DENIED )
}
}
override fun onFailure(error: IOException) {}
})
}
See the previous chapters about more details on the SDK setup and implementation.
iOS
Similarly to Android, the consents are updated using the setConsent
method. The following snippet demonstrates an optional extention that maps
the Cookie Information consent status to the Firebase Analytics ConsentStatus
type.
extention UserConsent {
var consentStatus: ConsentStatus {
return isSelected ? ConsentStatus.GRANTED : ConsentStatus.DENIED
}
}
mobileConsentsSDK.showPrivacyPopUp() { settings in
settings.forEach { consent in
switch consent.purpose {
case .statistical:
Analytics.setConsent(.analyticsStorage: consent.consentStatus
case .functional: break
case .marketing: break
Analytics.setConsent([
.adStorage: consent.consentStatus,
.adUserData: consent.consentStatus,
.adPersonalization: consent.consentStatus,
])
case .necessary: break
@unknown default:
break
}
print("Consent given for:\(consent.purpose): \(consent.isSelected)")
}
Analytics.setConsent([
.analyticsStorage: ,
.adStorage: <consent status>,
.adUserData: <consent status>,
.adPersonalization: <consent status>,
])
}
See the previous chapters about more details on the SDK setup and implementation.
Verify your setup
You can verify that your consent settings are working as intended by viewing the log messages for your app.
Android
Follow these steps:
Enable verbose logging on your device. In the Android Studio logcat, find the log message that starts with Setting consent. For example, Ad storage is enabled, you'll see the following log message:
Setting consent, ... AD_STORAGE=granted
iOS
You can verify that your consent settings are working as intended by viewing the Xcode debug console for your app.
Follow these steps:
Enable verbose logging on your device. In the Xcode debug console, look for:
ad_storage analytics_storage ad_user_data ad_personalization For example, if Ad storage are enabled, you'll see the following message:
ad_storage is granted.
References
For further information and more technical details please refer to the Google Consent Mode documentation for mobile apps.