Google Consent Mode v2-Unterstützung für InApp-SDKs
Suchen Sie nach einem CMP, das den Google Consent Mode unterstützt? Sehen Sie sich unsere an Google Consent Mode v2 Produktseite.
Diese Anleitung enthält Anweisungen zur Integration des Google Consent Mode in den benutzerdefinierten Modus ConsentManager in Ihrer Android- oder iOS-Anwendung.
Voraussetzungen:
- Stellen Sie sicher, dass der Einwilligungsmodus aktiviert ist (Menü > CMPs > Integrationen > Google Consent Mode)
- Stellen Sie sicher, dass Google Analytics, Google Ads oder die anderen Google-Dienste in Ihrer Anbieterliste enthalten sind
- Ein Firebase-Projekt mit aktiviertem Google Analytics.
- Firebase SDK in Ihr iOS-Projekt integriert.
-
CMPManager
in Ihrem Projekt einrichten.
Übersicht
Nachfolgend finden Sie Hilfsmethoden, mit denen Sie den Google-Einwilligungsstatus mithilfe unseres CMP SDK abrufen und verwalten können.
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")
}