SDKs de la solución de administración del consentimiento de Google

Consulta las Guías para desarrolladores de Google de los SDKs:


Consulta las guías que se encuentran al comienzo de este documento para conocer los requisitos y la implementación generales del SDK. Si habilitaste la compatibilidad con el modo de consentimiento de Privacidad y mensajería, te recomendamos que también implementes la funcionalidad adicional que se describe aquí.

Una vez que hayas implementado el SDK relevante, habilitado el modo de consentimiento de Google en Privacidad y mensajería y determinado que implementarás el modo de consentimiento básico, sigue estas instrucciones.

Para implementar el modo básico, sigue estos pasos:

  1. Inhabilita temporalmente la recopilación de Analytics (Android, iOS).
  2. Cuando esté todo listo para desbloquear la funcionalidad de Google Analytics, vuelve a habilitar la recopilación de Analytics (Android, iOS).

En el paso 2, consulta a un experto legal para determinar los criterios para volver a habilitar la funcionalidad de Analytics.

Por ejemplo, puedes volver a habilitar la funcionalidad de Google Analytics después de que el usuario haya tomado una decisión de consentimiento. Para ello, vuelve a habilitar la funcionalidad de Google Analytics en la devolución de llamada de loadAndShowConsentFormIfRequired (referencia de la API: Android, iOS).

Como alternativa, para determinar si se debe volver a habilitar la recopilación de Analytics en función de las elecciones del modo de consentimiento del usuario, lee la clave de almacenamiento local UMP_consentModeValues. El valor es una cadena de cuatro dígitos.

  • El primer dígito indica el valor del propósito de ad_storage.
  • El segundo dígito indica el valor del propósito ad_user_data.
  • El tercer dígito indica el valor del propósito ad_personalization.
  • El cuarto dígito indica el valor del propósito de analytics_storage.

En la siguiente tabla, se describen los valores posibles para cada dígito:

Valor Significado
0 Aún no hay ningún valor disponible.
1 El usuario GRANTED este propósito.
2 El usuario DENIED este propósito.
3 El modo de consentimiento no se aplica a este usuario.
4 El modo de consentimiento no está configurado para este fin.

En el siguiente ejemplo, se analiza UMP_consentModeValues, se habilita Google Analytics si todos los fines son GRANTED o no se aplican, y se inhabilita la recopilación de Analytics en 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;
  }

Llama a maybeReEnableAnalyticsCollection en los siguientes casos:

  • se actualiza la información de consentimiento
  • consentimiento.