Google Analytics offers Consent Mode to adjust how your Google tags behave
based on the consent status of your users. You can indicate whether consent has
been granted for Analytics and Ads identifiers. To implement Consent Mode for
apps, use the Google Analytics for Firebase SDK to set a default setting and use
the setConsent
API to manage the setting programmatically, based on in-app
user consent. To learn more, see Consent Mode.
Initial setup
By default, Analytics and Ad storage are enabled. Follow the instructions below to change the default state for your app.
Analytics storage
To disable Analytics storage, set the value of
GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE
to NO
in your app's
Info.plist file. For example, viewed in the source XML:
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key>
<false/>
Ad storage
To disable Ad storage, set the value of
GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE
to NO
in your app's Info.plist
file. For example, viewed in the source XML:
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key>
<false/>
To re-enable Analytics and Ad storage, such as after an end-user provides
consent, call the
setConsent
instance method of Analytics
.
Update consent
To update the Analytics and Ad storage values after an app has launched, call
the setConsent
method.
The value set by the setConsent
method persists across app executions and
overrides the default setting. 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.
The following example shows the setConsent
method updating values for
Analytics and Ad storage to granted:
Swift
Analytics.setConsent([
.analyticsStorage: .granted
.adStorage: .granted
])
Objective-C
[FIRAnalytics setConsent:@{
FIRConsentTypeAnalyticsStorage : FIRConsentStatusGranted
FIRConsentTypeAdStorage : FIRConsentStatusGranted
}];