Check out the Google Developer Guides for the SDKs:
Google consent mode SDK functionality
Consult the guides at the start of this document for overall SDK requirements and implementation. If you've enabled Privacy & messaging's Consent Mode support, you may also want to implement the additional functionality covered here.
Consent mode: basic mode support
Once you have implemented the relevant SDK, enabled Google Consent Mode in Privacy & messaging , and determined that you will implement basic consent mode , follow these instructions.
To implement basic mode:
- Temporarily disable Analytics collection ( Android , iOS ).
- When you are ready to unblock Google Analytics functionality, re-enable Analytics collection ( Android , iOS ).
For Step 2, consult with a legal expert to determine your criteria for re-enabling Analytics functionality.
For example, you can re-enable Google Analytics functionality after the user has
made a consent choice by re-enabling Google Analytics functionality in the
callback of loadAndShowConsentFormIfRequired
(API reference: Android
, iOS
).
Alternatively, to determine whether to re-enable Analytics collection based on
the user's consent mode choices, read the UMP_consentModeValues
local storage
key. The value is a four-digit string.
- The first digit indicates the ad_storage purpose value
- The second digit indicates the ad_user_data purpose value
- The third digit indicates the ad_personalization purpose value
- The fourth digit indicates the analytics_storage purpose value
The following table describes the possible values for each digit:
Value | Meaning |
---|---|
0
|
No value is available yet. |
1
|
The user GRANTED
this purpose. |
2
|
The user DENIED
this purpose. |
3
|
Consent mode does not apply for this user. |
4
|
Consent mode is not configured for this purpose. |
The following example parses UMP_consentModeValues
, enables Google Analytics
if all purposes are GRANTED
or do not apply, and disables Analytics collection
otherwise:
Java
// Helper function that sets Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private
void
maybeReEnableAnalyticsCollection
()
{
String
consentModeValues
=
sharedPreferences
.
getString
(
"UMP_consentModeValues"
,
null
);
if
(
shouldReEnableAnalyticsCollection
(
consentModeValues
))
{
firebaseAnalytics
.
setAnalyticsCollectionEnabled
(
true
);
}
else
{
firebaseAnalytics
.
setAnalyticsCollectionEnabled
(
false
);
}
}
// Helper function to determine whether Analytics collection should be enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private
boolean
shouldReEnableAnalyticsCollection
(
String
consentModeValues
)
{
if
(
consentModeValues
.
isEmpty
())
{
return
false
;
}
for
(
int
i
=
0
;
i
<
consentModeValues
.
length
();
i
++
)
{
char
consentModeValue
=
consentModeValues
.
charAt
(
i
);
switch
(
consentModeValue
)
{
case
'0'
:
// Consent mode data not ready yet.
return
false
;
case
1
:
// Consent mode is granted for this purpose.
break
;
case
'2'
:
// Consent is denied for this consent mode purpose.
return
false
;
case
'3'
:
// Consent does not apply for this purpose at this time.
break
;
case
'4'
:
// Consent mode is not configured for this purpose.
break
;
default
:
// Unexpected value encountered.
return
false
;
}
}
// If all checks pass, re-enable Analytics collection.
return
true
;
}
Kotlin
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private
fun
maybeReEnableAnalyticsCollection
()
{
val
consentModeValues
=
sharedPreferences
.
getString
(
"UMP_consentModeValues"
,
null
)
if
(
shouldReEnableAnalyticsCollection
(
consentModeValues
))
{
firebaseAnalytics
.
setAnalyticsCollectionEnabled
(
true
)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private
fun
shouldReEnableAnalyticsCollection
(
consentModeValues
:
String?
):
Boolean
{
if
(
consentModeValues
.
isNullOrEmpty
())
{
return
false
}
for
(
consentModeValue
in
consentModeValues
)
{
when
(
consentModeValue
)
{
'0'
-
>
{
// Consent mode data not ready yet.
return
false
}
'1'
-
>
{
// Consent mode is granted for this purpose.
}
'2'
-
>
{
// Consent is denied for this consent mode purpose.
return
false
}
'3'
-
>
{
// Consent does not apply for this purpose at this time.
}
'4'
-
>
{
// Consent mode is not configured for this purpose.
}
else
-
>
{
// Unexpected value encountered.
return
false
}
}
}
// If all checks pass, can re-enable Analytics collection.
return
true
}
Swift
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
private
func
maybeReEnableAnalyticsCollection
()
{
let
consentModeValues
=
userDefaults
.
string
(
forKey
:
"UMP_consentModeValues"
)
if
shouldReEnableAnalyticsCollection
(
consentModeValues
)
{
Analytics
.
setAnalyticsCollectionEnabled
(
true
)
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
private
func
shouldReEnableAnalyticsCollection
(
_
consentModeValues
:
String
?)
-
>
Bool
{
guard
let
consentModeValues
=
consentModeValues
,
!
consentModeValues
.
isEmpty
else
{
return
false
}
for
consentModeValue
in
consentModeValues
{
switch
consentModeValue
{
case
"0"
:
// Consent mode data not ready yet.
return
false
case
"1"
:
// Consent mode is granted for this purpose.
break
case
"2"
:
// Consent is denied for this consent mode purpose.
return
false
case
"3"
:
// Consent does not apply for this purpose at this time.
break
case
"4"
:
// Consent mode is not configured for this purpose.
break
default
:
// Unexpected value encountered.
return
false
}
}
// If all checks pass, can re-enable Analytics collection.
return
true
}
Objective-C
// Helper function that may re-enable Analytics collection based on the value of the
// UMP_consentModeValues local storage key.
-
(
void
)
maybeReEnableAnalyticsCollection
{
NSUserDefaults
*
defaults
=
[
NSUserDefaults
standardUserDefaults
];
NSString
*
consentModeValues
=
[
defaults
stringForKey
:
@"UMP_consentModeValues"
];
if
([
self
shouldReEnableAnalyticsCollection
:
consentModeValues
])
{
[
FIRAnalytics
setAnalyticsCollectionEnabled
:
YES
];
}
}
// Helper function to determine whether Analytics collection should be re-enabled. Returns true
// if all consent mode values are either granted, not applicable, or not configured.
-
(
BOOL
)
shouldReEnableAnalyticsCollection:
(
NSString
*
)
consentModeValues
{
if
(
!
consentModeValues
||
[
consentModeValues
length
]
==
0
)
{
return
NO
;
}
for
(
NSUInteger
i
=
0
;
i
<
[
consentModeValues
length
];
i
++
)
{
unichar
consentModeValue
=
[
consentModeValues
characterAtIndex
:
i
];
switch
(
consentModeValue
)
{
case
'0'
:
// Consent mode data not ready yet.
return
NO
;
case
'1'
:
// Consent mode is granted for this purpose.
break
;
case
'2'
:
// Consent is denied for this consent mode purpose.
return
NO
;
case
'3'
:
// Consent does not apply for this purpose at this time.
break
;
case
'4'
:
// Consent mode is not configured for this purpose.
break
;
default
:
// Unexpected value encountered.
return
NO
;
}
}
// If all checks pass, can re-enable Analytics collection.
return
YES
;
}
Call maybeReEnableAnalyticsCollection
when:
- consent information is updated
- consent is gathered.