Confira os guias para desenvolvedores do Google sobre os SDKs:
Funcionalidade do SDK do modo de consentimento do Google
Consulte os guias no início deste documento para conferir os requisitos gerais do SDK e a implementação. Se você tiver ativado o suporte ao modo de consentimento da API Privacy & messaging, também poderá implementar a funcionalidade adicional descrita aqui.
Modo de consentimento: suporte ao modo básico
Depois de implementar o SDK relevante, ativar o modo de consentimento do Google em "Privacidade e mensagens" e determinar que você vai implementar o modo de consentimento básico, siga estas instruções.
Para implementar o modo básico:
- Desative temporariamente a coleta do Google Analytics (Android, iOS).
- Quando estiver tudo pronto para desbloquear a funcionalidade do Google Analytics, reative a coleta do Analytics (Android, iOS).
Na etapa 2, consulte um especialista jurídico para determinar seus critérios para reativar a funcionalidade do Google Analytics.
Por exemplo, é possível reativar a funcionalidade do Google Analytics depois que o usuário
escolher uma opção de consentimento, reativando a funcionalidade no
callback de loadAndShowConsentFormIfRequired
(referência da API:
Android,
iOS).
Como alternativa, para determinar se a coleta do Google Analytics será reativada com base nas
escolhas do modo de consentimento do usuário, leia a chave de armazenamento local UMP_consentModeValues
. O valor é uma string de quatro dígitos.
- O primeiro dígito indica o valor da finalidade ad_storage
- O segundo dígito indica o valor da finalidade ad_user_data
- O terceiro dígito indica o valor da finalidade ad_personalization
- O quarto dígito indica o valor da finalidade analytics_storage
A tabela a seguir descreve os valores possíveis para cada dígito:
Valor | Significado |
---|---|
0 |
Nenhum valor está disponível ainda. |
1 |
O usuário GRANTED essa finalidade. |
2 |
O usuário DENIED essa finalidade. |
3 |
O modo de consentimento não se aplica a este usuário. |
4 |
O modo de consentimento não está configurado para essa finalidade. |
O exemplo a seguir analisa UMP_consentModeValues
, ativa o Google Analytics
se todos os propósitos forem GRANTED
ou não se aplicarem e desativa a coleta do Google Analytics
caso contrário:
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;
}
Chame maybeReEnableAnalyticsCollection
quando:
- as informações de consentimento são atualizadas
- consentimento é coletado.