Info
Content

Google Consent Mode v2 Ondersteuning voor inApp SDK's

Sinds versie 2.1.0 in Android en versie 1.99.3 in iOS

Deze handleiding biedt instructies voor het integreren van de Google-toestemmingsmodus met de aangepaste modus ConsentManager in uw Android- of iOS-applicatie. Er wordt van uitgegaan dat Firebase Analytics al in uw project is ingesteld.

Voorwaarden

  1. Zorg ervoor dat de toestemmingsmodus is ingeschakeld (Menu > CMP's > Integraties > Google-toestemmingsmodus)
  2. Zorg ervoor dat Google Analytics, Google Ads of de andere Google-services in uw leverancierslijst staan

iOS

Voorwaarden
  • Een Firebase-project waarvoor Google Analytics is ingeschakeld.
  • Firebase SDK geïntegreerd in uw iOS-project.
  • CMPConsentTool instellen in uw project.
Stap 1: Configureer CMPConsentTool

Instellen CMPConsentTool met uw specifieke configuratie. Deze tool beheert de toestemmingsinteracties van gebruikers:

import CmpSdk

var cmpManager: CMPConsentTool?

func configureCMPConsentTool() {
let cmpConfig = CMPConfig(...) // Configure as per your requirements

cmpManager = CMPConsentTool(cmpConfig: cmpConfig)
.withUpdateGoogleConsent(onCmpUpdateGoogleConsent)
}
Stap 2: Verwerk toestemmingsupdates

Implementeer de callback-functie om updates van de toestemmingsstatus af te handelen. Deze functie wordt geactiveerd wanneer er een wijziging optreedt in de toestemming van de gebruiker.

    func onCmpUpdateGoogleConsent(consentMap: [String: String]?) -> Void {
        guard let consentMap = consentMap else { return }

        var firebaseConsentMap: [ConsentType: ConsentStatus] = [:]

        consentMap.forEach { key, value in
            if let consentType = convertToFirebaseConsentType(from: key),
               let consentStatus = convertToFirebaseConsentStatus(from: value) {
                firebaseConsentMap[consentType] = consentStatus
            }
        }

        Analytics.setConsent(firebaseConsentMap)
    }
    
    func convertToFirebaseConsentType(from key: String) -> ConsentType? {
        switch key {
        case "analyticsStorage":
            return .analyticsStorage
        case "adStorage":
            return .adStorage
        case "adUserData":
            return .adUserData
        case "adPersonalization":
            return .adPersonalization
        default:
            return nil
        }
    }

    func convertToFirebaseConsentStatus(from value: String) -> ConsentStatus? {
        switch value {
        case "granted":
            return .granted
        case "denied":
            return .denied
        default:
            return nil
        }
    }

De onCmpUpdateGoogleConsent -functie werkt de toestemming in Google Analytics bij met behulp van de Firebase SDK.

  • De functie vertaalt de toestemming van de gebruiker van de CMPConsentTool in een indeling die Firebase Analytics begrijpt.
  • Vervolgens wordt Google Analytics bijgewerkt met de huidige toestemmingsstatus van de gebruiker.

Android

Voorwaarden
  • Android-applicatie met Firebase Analytics geïntegreerd.
  • CmpManager klasse geïmplementeerd in uw toepassing.
Stap 1: Firebase Analytics instellen

Voeg Firebase Analytics toe aan uw Android-project als u dat nog niet heeft gedaan. Volg de ambtenaar Firebase-documentatie om het in te stellen.

Stap 2: Implementeer de Google Firebase Analytics-callback
// add the AnalyticsInterface
class ConsentActivity() : FragmentActivity(), CmpGoogleAnalyticsInterface {
  
// Set the Callback
cmpManager.setGoogleAnalyticsCallback(this)

// Define Callback
override fun updateGoogleConsent(consentMap: Map<ConsentType, ConsentStatus>) {
	val firebaseConsentMap = consentMap.entries.associate { entry ->
		val firebaseConsentType = when (entry.key) {
			ConsentType.ANALYTICS_STORAGE -> FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE
			ConsentType.AD_STORAGE -> FirebaseAnalytics.ConsentType.AD_STORAGE
			ConsentType.AD_USER_DATA -> FirebaseAnalytics.ConsentType.AD_USER_DATA
			ConsentType.AD_PERSONALIZATION -> FirebaseAnalytics.ConsentType.AD_PERSONALIZATION
		}
	
		val firebaseConsentStatus = when (entry.value) {
			ConsentStatus.GRANTED -> FirebaseAnalytics.ConsentStatus.GRANTED
			ConsentStatus.DENIED -> FirebaseAnalytics.ConsentStatus.DENIED
		}
		
		firebaseConsentType to firebaseConsentStatus
	}
	
	FirebaseAnalytics.getInstance(applicationContext).setConsent(firebaseConsentMap)
}
Terug naar boven