Stay organized with collections
Save and categorize content based on your preferences.
This page is for developers that use the Google Analytics for Firebase SDK in
their app and want to integrate consent mode. For an introduction to consent
mode, read Consent mode
overview.
Google Analytics offers consent mode to adjust how your SDK behaves based on the
consent status of your users. You can implement consent mode in a basic or
advanced way. If you aren't sure whether to implement basic or advanced consent
mode, learn more about basic versus advanced consent
mode and check
with your company's guidelines.
Before you begin
Before you can manage user consent, you need to implement:
Add the consent mode key-value pairs. The key describes the consent
type and the
value indicates consent state. Values can either be true, meaning consent
was granted, or false, meaning consent was denied.
In accordance with the updates to consent mode for traffic in
European Economic Area (EEA), a value of eu_consent_policy can be set
for ad_user_data and ad_personalization, meaning consent is denied only
for users in regions subject to the EU User Consent Policy.
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.
If a user withdraws their previously given consent for Analytics or Ad
storage, Google Analytics deletes all user properties, including consent for
ad_personalization.
To preserve the user's consent choice for ad personalization, restore the
previous value for ad personalization using setConsent
(Swift
| Obj-C)
.
The following example shows the setConsent method updating the different
consent values to granted:
If a user decides to revoke their consent, make sure you update the consent
states accordingly
Upgrade to consent mode v2
As a part of Google's ongoing commitment to a privacy-safe digital advertising
ecosystem, we are strengthening the enforcement of our EU user consent
policy.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-09 UTC."],[[["\u003cp\u003eThis guide helps Firebase developers integrate consent mode to control data collection based on user consent, covering both basic and advanced implementation options.\u003c/p\u003e\n"],["\u003cp\u003eBefore setup, ensure you've implemented the Google Analytics for Firebase SDK and a consent settings banner or CMP.\u003c/p\u003e\n"],["\u003cp\u003eTo set up consent mode, define default consent states in your app's info.plist file and use the \u003ccode\u003esetConsent\u003c/code\u003e method to dynamically update consent values based on user choices.\u003c/p\u003e\n"],["\u003cp\u003eConsent mode v2 introduces two additional parameters, \u003ccode\u003ead_user_data\u003c/code\u003e and \u003ccode\u003ead_personalization\u003c/code\u003e, to comply with Google's updated EU user consent policy, requiring updates to your app's info.plist and consent calls.\u003c/p\u003e\n"],["\u003cp\u003eVerify your implementation by checking the Xcode debug console for consent settings like \u003ccode\u003ead_storage\u003c/code\u003e, \u003ccode\u003eanalytics_storage\u003c/code\u003e, \u003ccode\u003ead_user_data\u003c/code\u003e, and \u003ccode\u003ead_personalization\u003c/code\u003e.\u003c/p\u003e\n"]]],["Developers integrate consent mode with the Google Analytics for Firebase SDK to manage user consent. Key actions involve setting default consent states in the `info.plist` file using keys like `GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE` with `true` or `false` values, which now include `ad_user_data` and `ad_personalization`. The `setConsent` method updates consent after app launch, overriding defaults and persisting across sessions. Upgrading to consent mode v2 requires adding the two new consent parameters to both `info.plist` and `setConsent` calls. Verification is done via the Xcode debug console, checking for specific consent parameters.\n"],null,["\u003e This page is for developers that use the Google Analytics for Firebase SDK in\n\u003e their app and want to integrate consent mode. For an introduction to consent\n\u003e mode, read [Consent mode\n\u003e overview](/tag-platform/security/concepts/consent-mode).\n\nGoogle Analytics offers consent mode to adjust how your SDK behaves based on the\nconsent status of your users. You can implement consent mode in a basic or\nadvanced way. If you aren't sure whether to implement basic or advanced consent\nmode, learn more about [basic versus advanced consent\nmode](/tag-platform/security/concepts/consent-mode#basic-vs-advanced) and check\nwith your company's guidelines. \nAdvanced consent mode Basic consent mode \niOS Android\n| **Important** : Consent mode for apps was updated Oct 30th 2023 and now contains two additional parameters. If you already use consent mode, [upgrade to consent mode v2](#upgrade-consent-v2). Learn more about Google's [Updates to consent mode for traffic in European Economic Area (EEA)](https://support.google.com/tagmanager/answer/13695607).\n\nBefore you begin\n\nBefore you can manage user consent, you need to implement:\n\n- [Google Analytics for Firebase SDK](https://firebase.google.com/docs/analytics)\n- A consent settings banner to capture user consent\n\n | **Tip:** If you don't want to implement consent settings yourself, consider using a consent management platform (CMP).\n\nSet up consent mode\n\nTo set up consent mode, you need to:\n\n1. [Set the default consent state](#default-consent).\n\nSet the default consent state\n\nBy default, no consent mode values are set. To set the default consent state for\nyour app:\n\n1. Open your app's [info.plist](https://developer.apple.com/documentation/bundleresources/information_property_list) file.\n2. Add the consent mode key-value pairs. The key describes the [consent\n type](/tag-platform/security/concepts/consent-mode#consent-types) and the\n value indicates consent state. Values can either be `true`, meaning consent\n was granted, or `false`, meaning consent was denied.\n\n In accordance with the updates to consent mode for traffic in\n European Economic Area (EEA), a value of `eu_consent_policy` can be set\n for `ad_user_data` and `ad_personalization`, meaning consent is denied only\n for users in regions subject to the EU User Consent Policy.\n\n Set the following:\n - `GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE`\n - `GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE`\n - `GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA`\n - `GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS`\n3. Save your changes. Next, implement the mechanism to update consent values.\n\nFor example, to set all grant consent for all parameters by default: \n\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE\u003c/key\u003e \u003ctrue/\u003e\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE\u003c/key\u003e \u003ctrue/\u003e\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA\u003c/key\u003e \u003ctrue/\u003e\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS\u003c/key\u003e \u003ctrue/\u003e\n\nUpdate consent\n\nTo update consent values after an app has launched, call the\n[`setConsent`](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics#setConsent) method.\n\nThe value set by the `setConsent` method overrides the default setting and\npersists across app executions. The value remains in that state until\n`setConsent` is called again, even if a user closes and reopens the app.\n`setConsent` only updates the parameters you specify.\n\u003e If a user withdraws their previously given consent for Analytics or Ad\n\u003e storage, Google Analytics deletes all user properties, including consent for\n\u003e [`ad_personalization`](https://developers.google.com/tag-platform/security/concepts/consent-mode#consent-type).\n\u003e To preserve the user's consent choice for ad personalization, restore the\n\u003e previous value for ad personalization using `setConsent`\n\u003e\n\u003e ([Swift](https://firebase.google.com/docs/reference/swift/firebaseanalytics/api/reference/Categories/FIRAnalytics(Consent)#setconsent_:)\n\u003e \\| [Obj-C](https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#+setconsent:))\n\u003e .\n\nThe following example shows the `setConsent` method updating the different\nconsent values to `granted`: \n\nSwift \n\n Analytics.setConsent([\n .analyticsStorage: .granted,\n .adStorage: .granted,\n .adUserData: .granted,\n .adPersonalization: .granted,\n ])\n\nObjective-C \n\n [FIRAnalytics setConsent:@{\n FIRConsentTypeAnalyticsStorage : FIRConsentStatusGranted,\n FIRConsentTypeAdStorage : FIRConsentStatusGranted,\n FIRConsentTypeAdUserData : FIRConsentStatusGranted,\n FIRConsentTypeAdPersonalization : FIRConsentStatusGranted,\n }];\n\nIf a user decides to revoke their consent, make sure you update the consent\nstates accordingly\n\n\nUpgrade to consent mode v2\n\nAs a part of Google's ongoing commitment to a privacy-safe digital advertising\necosystem, we are strengthening the enforcement of our [EU user consent\npolicy](https://www.google.com/about/company/user-consent-policy/).\n\nLearn more about Google's [Updates to consent mode for traffic in European\nEconomic Area (EEA)](https://support.google.com/tagmanager/answer/13695607).\n\nConsent mode users need to send two new parameters in addition to ad storage and\nanalytics storage:\n\n1. Update your app's info.plist to include:\n\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA\u003c/key\u003e \u003ctrue/\u003e\n \u003ckey\u003eGOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS\u003c/key\u003e \u003ctrue/\u003e\n\n2. Update your consent calls to include the parameters for ad user data and ad\n personalization:\n\n Swift \n\n Analytics.setConsent([\n .analyticsStorage: .granted,\n .adStorage: .granted,\n .adUserData: .granted,\n .adPersonalization: .granted,\n ])\n\n Objective-C \n\n [FIRAnalytics setConsent:@{\n FIRConsentTypeAnalyticsStorage : FIRConsentStatusGranted,\n FIRConsentTypeAdStorage : FIRConsentStatusGranted,\n FIRConsentTypeAdUserData : FIRConsentStatusGranted,\n FIRConsentTypeAdPersonalization : FIRConsentStatusGranted,\n }];\n\nVerify consent settings\n\nYou can verify that your consent settings are working as intended by viewing the\nXcode debug console for your app.\n\nFollow these steps:\n\n1. [Enable verbose logging](https://firebase.google.com/docs/analytics/events?platform=ios#view_events_in_the_xcode_debug_console) on your device.\n2. In the Xcode debug console, look for:\n\n - `ad_storage`\n - `analytics_storage`\n - `ad_user_data`\n - `ad_personalization`\n\n For example, if Ad storage are enabled, you'll see the following message: \n\n ad_storage is granted."]]