Consulta le guide per gli sviluppatori Google per gli SDK:
Funzionalità dell'SDK della modalità di consenso di Google
Per i requisiti e l'implementazione complessivi dell'SDK, consulta le guide all'inizio di questo documento. Se hai attivato il supporto della modalità di consenso di Privacy e messaggi, ti consigliamo di implementare anche le funzionalità aggiuntive descritte qui.
Modalità di consenso: supporto della modalità di base
Dopo aver implementato l'SDK pertinente, aver attivato la modalità di consenso di Google in Privacy e messaggistica, e aver stabilito che implementerai la modalità di consenso di base, segui queste istruzioni.
Per implementare la modalità di base:
- Disattiva temporaneamente la raccolta di Analytics (Android, iOS).
- Quando è tutto pronto per sbloccare la funzionalità di Google Analytics, riattiva la raccolta Analytics (Android, iOS).
Per il passaggio 2, rivolgiti a un esperto legale per determinare i criteri per riattivare la funzionalità di Analytics.
Ad esempio, puoi riattivare la funzionalità di Google Analytics dopo che l'utente ha scelto di dare il consenso riattivando la funzionalità di Google Analytics nel callback di loadAndShowConsentFormIfRequired
(riferimento API:
Android,
iOS).
In alternativa, per determinare se riattivare la raccolta di Analytics in base alle scelte dell'utente relative alla modalità di consenso, leggi la chiave dello spazio di archiviazione locale UMP_consentModeValues
. Il valore è una stringa di quattro cifre.
- La prima cifra indica il valore dello scopo ad_storage
- La seconda cifra indica il valore dello scopo ad_user_data
- La terza cifra indica il valore dello scopo ad_personalization
- La quarta cifra indica il valore dello scopo analytics_storage
La tabella seguente descrive i possibili valori per ogni cifra:
Valore | Significato |
---|---|
0 |
Nessun valore ancora disponibile. |
1 |
L'utente GRANTED questa finalità. |
2 |
L'utente DENIED questa finalità. |
3 |
La modalità di consenso non si applica a questo utente. |
4 |
La modalità di consenso non è configurata per questo scopo. |
L'esempio seguente analizza UMP_consentModeValues
, attiva Google Analytics se tutte le finalità sono GRANTED
o non si applicano e disattiva la raccolta di Analytics in caso contrario:
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;
}
Chiama maybeReEnableAnalyticsCollection
quando:
- le informazioni sul consenso vengono aggiornate
- Il consenso viene raccolto.