Info
Contenido

Compatibilidad con el modo de consentimiento de Google v2 para SDK inApp

¿Busca un CMP que admita el modo de consentimiento de Google? Vea nuestro Modo de consentimiento de Google v2 página del producto.

Esta guía proporciona instrucciones sobre cómo integrar el Modo de consentimiento de Google con el formulario personalizado. ConsentManager en tu aplicación de Android o iOS.

Requisitos previos

  • Asegúrese de que el modo de consentimiento esté habilitado (Menú > CMP > Integraciones > Modo de consentimiento de Google)
  • Asegúrese de que Google Analytics, Google Ads u otros servicios de Google estén en su lista de proveedores
  • Un proyecto de Firebase con Google Analytics habilitado.
  • Firebase SDK integrado en su proyecto iOS.
  • CMPManager configurar en su proyecto.

Descripción General

A continuación, encontrará métodos de ayuda que le permitirán recuperar y administrar el estado de consentimiento de Google mediante nuestro SDK de CMP. 

iOS

/// Synchronizes the consent status from CMP to Firebase Analytics
func syncConsentToFirebase() {
    let cmpManager = CMPManager.shared
    guard let googleConsentModeStatus = cmpManager.getGoogleConsentModeStatus() else {
        print("Google Consent Mode status not available")
        return
    }

    // Define all expected consent types
    let consentTypes = [
        "analytics_storage",
        "ad_storage",
        "ad_user_data",
        "ad_personalization"
    ]

    // Build Firebase settings with proper defaults
    var firebaseConsentSettings = [String: String]()

    // Set defaults for all expected types (denied)
    for consentType in consentTypes {
      firebaseConsentSettings[consentType] = "denied"
    }

    // Override with actual values from CMP
    for (key, value) in googleConsentModeStatus {
        if consentTypes.contains(key) {
            firebaseConsentSettings[key] = value
        }
    }

    // Set the consent in Firebase
    Analytics.setConsent(firebaseConsentSettings)
    print("Firebase consent settings updated: \(firebaseConsentSettings)")
}

Android

/// Synchronizes the consent status from CMP to Firebase Analytics
fun updateFirebaseConsent(firebaseAnalytics: FirebaseAnalytics, cmpManager: CMPManager) {
    // Get consent settings from CMP SDK
    val cmpConsentSettings = cmpManager.getGoogleConsentModeStatus()
    
    // Convert to Firebase's types
    val firebaseConsentSettings = mutableMapOf<ConsentType, ConsentStatus>()
    
    cmpConsentSettings.forEach { (key, value) ->
        try {
            val consentType = ConsentType.valueOf(key.uppercase())
            val consentStatus = if (value == "granted") 
                ConsentStatus.GRANTED else ConsentStatus.DENIED
            
            firebaseConsentSettings[consentType] = consentStatus
        } catch (e: IllegalArgumentException) {
            Log.w("ConsentManager", "Unknown consent type: $key")
        }
    }
    
    // Update Firebase consent
    firebaseAnalytics.setConsent(firebaseConsentSettings)
    Log.d("ConsentManager", "Updated Firebase consent: $firebaseConsentSettings")
}

 

Volver