Skip to content

This package supports Google’s User Messaging Platform (UMP) to display a consent form for users in the EU/EEA, complying with GDPR requirements.

License

Notifications You must be signed in to change notification settings

kazmi-dev/GoogleConsentFormGDPR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

📜 Google Consent Form GDPR/EEA Implementation

This is a lightweight Kotlin-based utility class to easily implement Google UMP (User Messaging Platform) Consent Form for GDPR/EEA compliance in your Android apps.

Supports:

  • ✅ Consent request using Google UMP SDK
  • ✅ Debug mode for testing in EEA
  • ✅ Callback support to load ads after consent
  • ✅ Privacy options support
  • ✅ Easy integration with Dagger Hilt

🛠️ Prerequisites

  • ✅ User Messaging Platform Dependency
  • ✅ Dagger/Hilt Integration

1. 📌 Add UMP dependency in your libs.versions.toml:

Dependency:

ump = { group = "com.google.android.ump", name = "user-messaging-platform", version.ref = "ump_version" }

2. 📌 Add Dagger/Hilt support

Add following depedencies and plugins to libs.versions.toml

Dependencies:

dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "daggerHilt_version" }
dagger-ksp = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "daggerHilt_version" }

Plugin:

hilt = { id = "com.google.dagger.hilt.android", version.ref = "daggerHilt_version" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp_version" }

Versions:

daggerHilt_version = "2.55"
ksp_version = "2.1.0-1.0.29"

Now add add dependencies and plugins in build.gradle for both app and project level as below:

App Level:

Plugins:

alias(libs.plugins.ksp)
alias(libs.plugins.hilt)

Dependencies:

implementation(libs.dagger.hilt)
ksp(libs.dagger.ksp)

Project Level:

Plugin:

alias(libs.plugins.hilt) apply  false
alias(libs.plugins.ksp) apply  false

📌 2. Annotate Your Application Class

@HiltAndroidApp
class MyApp : Application()

📌 3. Update Manifest file

<application
    android:name=".MyApp"
    ... >
</application>

📜 Initilization

Initialize UMP in your activity as below:

@Inject latinit var googleConsentFormManager: GoogleConsentFormManager

1. Implement UmpCallbacks in your activity or fragment:

class MainActivity : AppCompatActivity(), GoogleConsentFormManager.UmpCallbacks {

    override fun onRequestAds() {
        // Consent is gathered — load ads now
    }

    override fun onConsentFormError(error: String) {
        // Handle any error that occurred
        Log.e("ConsentError", error)
    }
}

2. Request Consent:

consentManager.setConsentCallbacks(this)
consentManager.gatherConsentIfAvailable(this) { consentGiven ->
    Log.d("ConsentResult", "Consent gathered: $consentGiven")
}

3. Optional – Show Privacy Options Manually:

consentManager.showPrivacyOptionsForm(this) { formError ->
    Log.e("PrivacyFormError", "Error: ${formError.message}")
}

4. Optional – Reset Consent (Debug/Test Mode Only):

consentManager.consentReset()

🧪 Debug Mode Setup

To test consent form in debug mode (EEA simulation)

1. Generate your hashed device ID using this code:

val id = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
val hashed = MessageDigest.getInstance("MD5").digest(id.toByteArray()).joinToString("") {
    "%02x".format(it)
}
Log.d("DeviceHash", hashed)

2. Replace "YOUR-DEVICE-HASHED-ID" in the manager class with your hashed ID.

val debugSettings = ConsentDebugSettings.Builder(it)
    .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
    .addTestDeviceHashedId("YOUR-DEVICE-HASHED-ID")
    .build()

✅ Done!

You’ve now implemented Google’s UMP Consent Form in your app with clean separation of concerns and Hilt support.

About

This package supports Google’s User Messaging Platform (UMP) to display a consent form for users in the EU/EEA, complying with GDPR requirements.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages