Informatie
Beschrijving

Google Consent Mode v2 Ondersteuning voor inApp SDK's

Op zoek naar een CMP die de toestemmingsmodus van Google ondersteunt? Zie onze Google-toestemmingsmodus v2 productpagina.

Deze handleiding biedt instructies voor het integreren van de Google-toestemmingsmodus met de aangepaste modus ConsentManager in uw Android- of iOS-applicatie.

Voorwaarden

  • Zorg ervoor dat de toestemmingsmodus is ingeschakeld (Menu > CMP's > Integraties > Google-toestemmingsmodus)
  • Zorg ervoor dat Google Analytics, Google Ads of de andere Google-services in uw leverancierslijst staan
  • Een Firebase-project waarvoor Google Analytics is ingeschakeld.
  • Firebase SDK geïntegreerd in uw iOS-project.
  • CMPManager instellen in uw project.

Overzicht

Hieronder vindt u hulpmiddelen waarmee u de Google-toestemmingsstatus kunt ophalen en beheren met behulp van onze CMP SDK. 

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")
}

 

Terug naar boven