GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - kazmi-dev/GoogleConsentFormGDPR: This package supports Googleโ€™s User Messaging Platform (UMP) to display a consent form for users in the EU/EEA, complying with GDPR requirements.

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
googleConsentForm
googleConsentForm
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 

Repository files navigation

๐Ÿ“œ Google Consent Form GDPR/EEA Implementation

This is a Simple callback 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
  • โœ… Support both Object and Hilt (Two way integration)
  • โœ… Debug mode for testing in EEA
  • โœ… Ad initialization included
  • โœ… Callback support to load ads after consent
  • โœ… Privacy options support

๐Ÿ› ๏ธ Prerequisites

  • โœ… User Messaging Platform Dependency
  • โœ… Dagger/Hilt Integration (only if using DI)

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 (only required for DI projects)

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 using DI:

@Inject latinit var googleConsentFormManager: GoogleConsentFormManager

googleConsentFormManager.initConsentInfo(
         activity = this,
         debugMode = true,
         onAdsInitialized = {
            //onAdInitialized
         },
         onError = {error->
            //handle error
         }
)

Initialize UMP in your activity as below using Object:

GoogleConsentManager.initConsentInfo(
        activity = this,
        debugMode = true,
        onAdsInitialized = {
            //onAdInitialized
        },
        onError = {error->
            //handle error
        }
)

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

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.