Google Consent Mode
The Osano ConsentSDK for iOS supports Google's Consent Mode v2, providing seamless integration with Firebase Analytics and other Google services. This feature automatically maps Osano consent categories to Google Consent Mode parameters, ensuring compliance with Google's data collection requirements.
Prerequisites
- Enable Google Consent Mode in your Osano configuration on the Osano website
- Firebase Analytics for iOS must be integrated in your project (Firebase Setup Guide)
- Configure consent defaults for GDPR compliance
Quick Setup
1. Configure Consent Defaults (Info.plist)
Add these keys to your iOS Info.plist file to set Google Consent Mode v2 default values:
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key>
<false/>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key>
<false/>
<!-- For EEA countries, you can use the string "eu_consent_policy" instead of false -->
<!--
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA</key>
<string>eu_consent_policy</string>
<key>GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS</key>
<string>eu_consent_policy</string>
-->
2. Initialize ConsentManager
Initialize your ConsentManager as described in the Getting Started guide:
import ConsentSDK
let consentManager = ConsentManager(
customerId: "your_customer_id",
configId: "your_config_id",
consentingDomain: "your.domain.com",
extUsrData: "your_user_data"
) { error in
if let error = error {
print("Initialization failed with error: \(error)")
} else {
print("ConsentManager initialized successfully")
}
}
// Optional: Enable debug logging for development
#if DEBUG
consentManager.setDebugLogging(true)
#endif
3. Implement Google Consent Mode Callback
Add the Google Consent Mode callback to receive consent updates and apply them to Firebase Analytics:
import FirebaseAnalytics
consentManager.withGoogleConsent { (googleConsent) in
Analytics.setConsent([
.analyticsStorage: googleConsent["analytics_storage"] == "granted" ? .granted : .denied,
.adStorage: googleConsent["ad_storage"] == "granted" ? .granted : .denied,
.adUserData: googleConsent["ad_user_data"] == "granted" ? .granted : .denied,
.adPersonalization: googleConsent["ad_personalization"] == "granted" ? .granted : .denied
])
}
How It Works
Category Mapping
The SDK automatically maps Osano consent categories to Google Consent Mode v2 parameters:
| Osano Category | Google Consent Mode Parameters |
|---|---|
| ANALYTICS | analytics_storage |
| MARKETING | ad_storage, ad_user_data, ad_personalization |
| Other categories | No mapping (Essential, Personalization, Storage, etc.) |