Skip to main content

Google Consent Mode

The Osano Consent Manager SDK 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

  1. Enable Google Consent Mode in your Osano configuration on the Osano website
  2. Firebase Analytics must be integrated in your Android project (Firebase Setup Guide)
  3. Configure manifest defaults for GDPR compliance

Note: If you also enable IAB/TCF in your Osano configuration, TCF integration will be automatically enabled by the Osano SDK.

Quick Setup

1. Configure Manifest Defaults

Add these <meta-data> tags to your AndroidManifest.xml within the <application> tag:

<application>
<!-- Google Consent Mode v2 default values -->
<!-- These are read automatically by Firebase Analytics before user consent is collected -->
<!-- Set to false for GDPR compliance - consent must be explicitly granted -->
<meta-data android:name="google_analytics_default_allow_analytics_storage" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_storage" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="false" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="false" />

<!-- For EEA countries, you can use "eu_consent_policy" instead of "false" -->
<!-- <meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="eu_consent_policy" /> -->
<!-- <meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="eu_consent_policy" /> -->
</application>

Important: These defaults are crucial for GDPR compliance. They tell Google to deny consent by default until the user explicitly grants it through the CMP.

Implement the GoogleConsentModeCallback to receive consent updates:

import com.google.firebase.Firebase
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.analytics
import com.osano.mobile_sdk.GoogleConsentModeCallback

val googleConsentModeCallback = object : GoogleConsentModeCallback {
override fun onGoogleConsentUpdate(consentMap: Map<String, String>) {
// Convert Osano consent map to Firebase format
val firebaseConsent = mutableMapOf<FirebaseAnalytics.ConsentType, FirebaseAnalytics.ConsentStatus>()

consentMap.forEach { (key, value) ->
val consentType = when (key) {
"analytics_storage" -> FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE
"ad_storage" -> FirebaseAnalytics.ConsentType.AD_STORAGE
"ad_user_data" -> FirebaseAnalytics.ConsentType.AD_USER_DATA
"ad_personalization" -> FirebaseAnalytics.ConsentType.AD_PERSONALIZATION
else -> null
}

consentType?.let {
firebaseConsent[it] = if (value == "granted")
FirebaseAnalytics.ConsentStatus.GRANTED
else
FirebaseAnalytics.ConsentStatus.DENIED
}
}

// Apply consent to Firebase Analytics
Firebase.analytics.setConsent(firebaseConsent)
}
}

3. Configure the ConsentManager

Set the callback when building your ConsentManager:

val consentManager = ConsentManager.Builder(this)
.setConfigId("your_config_id")
.setCustomerId("your_customer_id")
.setConsentingDomain("your_domain")
.setGoogleConsentModeCallback(googleConsentModeCallback)
.build()

How It Works

Category Mapping

The SDK automatically maps Osano consent categories to Google Consent Mode v2 parameters:

Osano CategoryGoogle Consent Mode Parameters
ANALYTICSanalytics_storage
MARKETINGad_storage, ad_user_data, ad_personalization
Other categoriesNo mapping (Essential, Personalization, Storage, etc.)
  1. App Launch: Manifest defaults are applied (typically all denied)
  2. SDK Initialization: If user has existing consent, callback is triggered immediately
  3. User Interaction: When user grants/denies consent, callback is triggered with updated parameters
  4. 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 manifest configuration is required.

The SDK handles this automatically by:

  • Setting the IABTCF_EnableAdvertiserConsentMode parameter to enable Google's TCF integration
  • Providing all required IABTCF SharedPreferences 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

Note: The AndroidManifest.xml google_analytics_tcf_data_enabled flag is not required when using Osano as your CMP, as we handle TCF enablement automatically through the CMP API.

For ad_user_data and ad_personalization parameters, you can use eu_consent_policy instead of false in your manifest defaults. Unlike false which denies consent for all users globally, eu_consent_policy only denies consent for users in regions subject to the EU User Consent Policy, while granting consent by default for users outside these regions:

<meta-data android:name="google_analytics_default_allow_ad_user_data" android:value="eu_consent_policy" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="eu_consent_policy" />

Debugging & Testing

Enable Debug Logging

Enable debug logging to see detailed consent flow:

ConsentManager.Builder(this)
.setDebugMode(true)
// ... other configuration

Firebase Debug View

To verify consent is working with Firebase Analytics:

  1. Enable Firebase Debug Mode:
# Replace with your actual app package name (e.g., com.example.myapp)
adb shell setprop debug.firebase.analytics.app your.package.name
  1. Enable Verbose Logging:
adb shell setprop log.tag.FA VERBOSE
adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC
  1. Check Firebase DebugView: View real-time events in the Firebase Console

Common Log Messages

Look for these log messages to verify correct operation:

GoogleConsentMode: === CONSENT UPDATE RECEIVED ===
GoogleConsentMode: Consent map: {analytics_storage=granted, ad_storage=denied, ...}
GoogleConsentMode: Firebase Analytics consent applied: {ANALYTICS_STORAGE=GRANTED, ...}

Additional Resources