Google Consent Mode
Google Consent Mode allows web and app developers to adjust tag and app SDK behavior based on user consent choices. Google will be able to dynamically adapt the behavior of Google tags, Google Analytics, Google Ads, Floodlight and Conversion Linker. To accomplish this, consent types have been created to alter specific behavior in the aforementioned products.
Platform support
GCM is supported for iOS and tvOS.
Consent types include:
Consent type | Description | Consent statuses |
---|---|---|
analytics_storage | Enables storage, such as cookies (web) or device identifiers (apps), related to analytics, for example, visit duration. | granted | denied |
ad_storage | Enables storage, such as cookies (web) or device identifiers (apps), related to advertising. | granted | denied |
ad_user_data | Sets consent for sending user data to Google for online advertising purposes. | granted | denied |
ad_personalization | Sets consent for personalized advertising. | granted | denied |
More information here: https://support.google.com/google-ads/answer/10000067?hl=en
Setting up Google Consent Mode (GCM) for iOS/tvOS
-
Enable Google Consent Mode in your geolocation rules and map categories from the OneTrust CMP to Google storage types.
-
Ensure the supported Google products (e.g. Firebase) have been installed on the app already.
-
Set the default consent values for GCM in your app's
info.plist
. Value can be set to true or false.<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key> <false/> <key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key> <false/> <key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key> <false/> <key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key> <false/>
-
Query for Google Consent Mode consent statuses from the OneTrust SDK.
getOTGoogleConsentModeData()
will return an object containing the current status and values for each of the Google Consent types based on the mapping done in Step 1.OTPublishersHeadlessSDK.shared.getOTGoogleConsentModeData().otSDKStatus OTPublishersHeadlessSDK.shared.getOTGoogleConsentModeData().consentType
Status type Description notInitialized Application calls method before a successful SDK initialization (at least once). Consent has not been collected. notConsented Application calls method before user interacts with and dismisses the banner. Consent has not been collected. consented Application calls method after user has interacted with the banner. Consent has been collected.
Consent type Description unassigned 'Do not Assign Category' was mapped to this storage/consent type in the geolocation rules. undefined The SDK was not initialized successfully at least once, data was not fetched, or the mapped category does not exist (no SDKs assigned). denied Consent is rejected/withdrawn for the associated category. granted Consent is given/provided to associated category. Sample Response:
//consent interaction status OneTrust GCM SDK status: consented //consent value of each storage type OTGoogleConsentType( analyticsStorage: OTPublishersHeadlessSDK.OTGoogleConsentMode.granted, adStorage: OTPublishersHeadlessSDK.OTGoogleConsentMode.granted, adUserData: OTPublishersHeadlessSDK.OTGoogleConsentMode.granted, adPersonalization: OTPublishersHeadlessSDK.OTGoogleConsentMode.granted)
-
Update the desired Google library from the consent retrieved in Step 5 with the
setConsent()
public method from Google.Analytics.setConsent([ .analyticsStorage: .granted, .adStorage: .granted, .adUserData: .granted, .adPersonalization: .granted, ])
As the application will need to retrieve the consents for each Consent type and set it in the Google library as indicated in steps 4 and 5, OneTrust has written a function to assist with and simplify the process:
-
func handleGoogleConsentMode() { let gcmOTData = OTPublishersHeadlessSDK.shared.getOTGoogleConsentModeData() #if canImport(FirebaseAnalytics) Analytics.setConsent([ .adStorage: gcmOTData.consentType.adStorage == .granted ? .granted : .denied, .analyticsStorage: gcmOTData.consentType.analyticsStorage == .granted ? .granted : .denied, .adUserData: gcmOTData.consentType.adUserData == .granted ? .granted : .denied, .adPersonalization: gcmOTData.consentType.adPersonalization == .granted ? .granted : .denied, ]) #endif }
-
OneTrust recommends calling the
handleGoogleConsentMode()
function above when the OTConsentUpdated broadcast is triggered. OTConsentUpdated is triggered every time any OneTrust UI is dismissed. More info on that method here.NotificationCenter.default.addObserver(self, selector: #selector(returnConsentOTConsentUpdated(_:)), name: Notification.Name("OTConsentUpdated"), object: nil) @objc func returnConsentOTConsentUpdated(_ notification:Notification){ handleGoogleConsentMode() }
Alternatively, you can also use UI Interaction Events instead of broadcast receivers to know when to call
handleGoogleConsentMode()
. Reference this page for more information.
Additional Information
You can view more information regarding consent mode setup here: https://developers.google.com/tag-platform/security/guides/app-consent?platform=ios&consentmode=advanced
Verifying consent settings
You can verify that your consent settings are working as intended by viewing the Xcode debug console for your app.
-
Enable verbose logging on your device.
-
In the Xcode debug console, look for:
- analytics_storage
- ad_storage
- ad_user_data
- ad_personalization
For example, if Ad storage are enabled, you'll see the following message:
ad_storage is granted.
Google Consent Mode for TCF Templates.
Applications can be configured to tell Google to use the TC string to infer the settings for ad_storage, ad_personalization, and ad_user_data settings. Google will ensure to detect this key and value to adjust their signals
The key “IABTCF_EnableAdvertiserConsentMode” indicates whether Google consent mode is enabled or not for TCF templates, this key will be stored under shared preferences when user access the application from an IAB Region.
Key | value | Description |
---|---|---|
IABTCF_EnableAdvertiserConsentMode | 1 | Indicates GCM is enabled for TCF template |
IABTCF_EnableAdvertiserConsentMode | 0 | Indicates GCM is disabled for TCF template |
Note
- Don’t get confused with the naming convention of the key, this is not defined in IAB spec. Google has recommended this attribute to make it available for them to adjust signals
- For a Geo-rule with TCF template - if the GCM categories are mapped to non IAB categories - OT GCM public method will still provide the response with ‘granted’ or ‘denied’
- Application developer should be aware of based on the use-case whether to consume above flag for IAB template OR the OT public method response for Non IAB template
To find out more information about TCF integration behaviour with GCM and category mapping please visit Google Documentation here
Updated 5 months ago