> ## Documentation Index
> Fetch the complete documentation index at: https://developer.onetrust.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Consent Mode

Google Consent Mode enables web and app developers to modify the behavior of Google tags and SDKs based on users' consent preferences. When implemented, it allows Google services such as Google Analytics, Google Ads, Floodlight, and Conversion Linker to dynamically adjust their functionality in response to consent signals. This is achieved through defined consent types, which control specific aspects of how each product behaves depending on the user's choices.

> 📘
>
> 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

1. Enable Google Consent Mode in your geolocation rules and map categories from the OneTrust CMP to Google storage types.
   1. ![](https://files.readme.io/8836730-image.png)
2. Ensure the supported Google products (e.g. Firebase) have been installed on the app already.
3. Set the default consent values for GCM in your app's `info.plist`. Value can be set to true or false.
   ```text
   <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/>
   ```
   1. ![](https://files.readme.io/5aa4221-image.png)
4. 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**.

   ```swift
   OTPublishersHeadlessSDK.shared.getOTGoogleConsentModeData().otSDKStatus
   OTPublishersHeadlessSDK.shared.getOTGoogleConsentModeData().consentType
   ```

   <br />

   | 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.                  |

   <br />

   | 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)
   ```
5. Update the desired Google library from the consent retrieved in Step 5 with the `setConsent()` public method from [Google](https://developers.google.com/tag-platform/security/guides/app-consent?platform=ios\&consentmode=advanced#update-consent).
   ```swift
   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:

1. ```swift
   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
   }
   ```
2. 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](https://developer.onetrust.com/onetrust/docs/when-consent-changes-ios#otconsentupdated).

   ```swift
   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](https://developer.onetrust.com/onetrust/docs/when-consent-changes-ios-legacy#alternative-approach) for more 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.

1. [Enable verbose logging](https://firebase.google.com/docs/analytics/events?platform=ios#view_events_in_the_xcode_debug_console) on your device.
2. 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 IAB TCF

Applications can be configured to instruct Google to interpret the IAB TC String in order to determine consent values for the following Consent Mode settings:

|                     |
| :------------------ |
| ad\_storage         |
| ad\_personalization |
| ad\_user\_data      |

In the OneTrust platform, enable the Google Consent Mode toggle in geolocation rules using the IAB TCF template. When this configuration is enabled, the SDK will write the key `IABTCF_EnableAdvertiserConsentMode` to local storage and allows Google to automatically adjust its signal behavior according to TC String consents.

| Key                                 | value | Description                       |
| :---------------------------------- | :---- | :-------------------------------- |
| IABTCF\_EnableAdvertiserConsentMode | 1     | Indicates GCM is enabled for TCF  |
| IABTCF\_EnableAdvertiserConsentMode | 0     | Indicates GCM is disabled for TCF |

Google Consent Mode storage types are mapped to TCF purposes as follows:

[block:parameters]
{
  "data": {
    "h-0": "Purpose",
    "h-1": "Description",
    "h-2": "Google behavior when Purpose is denied",
    "0-0": "1",
    "0-1": "Store and/or access information on a device.",
    "0-2": "ad_storage = denied  \nad_user_data = denied",
    "1-0": "3",
    "1-1": "Create a personalised ads profile",
    "1-2": "ad_personalization = denied",
    "2-0": "4",
    "2-1": "Select personalized ads",
    "2-2": "ad_personalization = denied"
  },
  "cols": 3,
  "rows": 3,
  "align": [
    "left",
    "left",
    "left"
  ]
}
[/block]

> 📘
>
> For more information about IAB TCF integration behavior with GCM, see Google's documentation [Enable consent mode TCF integration](https://developers.google.com/tag-platform/security/guides/implement-TCF-strings#apps).