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.) |
Consent Flow
- App Launch: Manifest/Info.plist defaults are applied
- SDK Initialization: If user has existing consent, callback is triggered immediately
- Remote Consent Sync: If
remoteConsent
is enabled and user data (extUsrData
) is provided, the SDK fetches remote consent from Osano servers and compares timestamps with local consent to use the most recent version - User Interaction: When user grants/denies consent, callback is triggered with updated parameters
- Firebase Update: Your callback converts and applies consent to Firebase Analytics
Automatic TCF Integration
As your Consent Management Platform (CMP), Osano automatically enables TCF (Transparency & Consent Framework) integration when both Google Consent Mode and IAB/TCF are enabled in your Osano configuration. No additional configuration is required.
The SDK handles this automatically by:
- Setting the
IABTCF_EnableAdvertiserConsentMode
parameter to 1 when both Google Consent Mode and IAB TCF are applicable for the user - Providing all required IABTCF NSUserDefaults keys that Google services expect
- Enabling this only when both features are active and TCF is applicable for the user's region
- Allowing Google services to read the TCF consent string directly for detailed consent information
- Automatically disabling TCF integration (
IABTCF_EnableAdvertiserConsentMode
= 0) when either feature is not applicable
Note: The google_analytics_tcf_data_enabled
flag is not required when using Osano as your CMP, as we handle TCF enablement automatically.
Debug Logging
The SDK provides comprehensive logging to help with development and troubleshooting. Debug logging is disabled by default and must be explicitly enabled.
// Debug logging is OFF by default - must be explicitly enabled
// Enable debug logging for development (shows all SDK logs)
#if DEBUG
consentManager.setDebugLogging(true) // Required to see any SDK logs
#endif
// Check if debug logging is enabled
if consentManager.isDebugLoggingEnabled() {
print("Debug logging is active")
}
Log Levels:
- Error/Fault: Always shown (cannot be disabled)
- Info/Warn/Debug/Verbose: Only shown when
setDebugLogging(true)
is enabled (defaults to OFF)
Default Behavior:
- ❌ Debug logging: Disabled by default - must call
setDebugLogging(true)
- ✅ Error logging: Always enabled (cannot be disabled)
Recommended Usage:
- Debug logging defaults to OFF - explicitly enable only during development
- Use
setDebugLogging(true)
to see detailed consent flow information - Keep debug logging disabled in production to prevent any console noise
- Errors are always logged regardless of settings for critical issue detection