GithubHelp home page GithubHelp logo

gdpr-admob-android's Introduction

GDPR Android Admob Library

Class helper to easily interact with google consent SDK easily made with LOVE ❤️ 🌍.

Example:

Demo version app has been added for a better explanation of the library.

Required Dependencies:

Add it in your root build.gradle at the end of repositories:

    allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

    dependencies {
	        implementation 'com.github.ayoubfletcher.GDPR-Admob-Android:consentsdk:0.1.7'
	}

Get requirement you need:

Get your publisher id from admob: Publisher Id Source

To get the device id you have to initialize an adrequest

Java

    // Creating a dummy adview
    AdView adView = new AdView(context);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); // Default test banner id
    adView.loadAd((new AdRequest.Builder()).build());
    
    // Or using this code is the same code above it uses the test banner id provided by admob. 'ca-app-pub-3940256099942544/6300978111'
    ConsentSDK.initDummyBanner(context);

Kotlin

    // Creating a dummy adview
    val adView = AdView(context)
    adView.adSize = AdSize.BANNER
    adView.adUnitId = "ca-app-pub-3940256099942544/6300978111"
    adView.loadAd(AdRequest.Builder().build())
    
    // Or using this code is the same code above it uses the test banner id provided by admob. 'ca-app-pub-3940256099942544/6300978111'
    ConsentSDK.initDummyBanner(context)

How to use library:

1.a Initializing using Builder class

Java

    ConsentSDK consentSDK = new ConsentSDK.Builder(context)
                .addTestDeviceId("your device id from logcat") // Add your test device id "Remove addTestDeviceId on production!"
                .addCustomLogTag("CUSTOM_TAG") // Add custom tag default: ID_LOG
                .addPrivacyPolicy("https://your.privacy.url/") // Add your privacy policy url
                .addPublisherId("pub-0123456789012345") // Add your admob publisher id
                .build();

Kotlin

    val consentSDK = ConsentSDK.Builder(context)
                .addTestDeviceId("your device id from logcat") // Add your test device id "Remove addTestDeviceId on production!"
                .addCustomLogTag("CUSTOM_TAG") // Add custom tag default: ID_LOG
                .addPrivacyPolicy("https://your.privacy.url/") // Add your privacy policy url
                .addPublisherId("pub-0123456789012345") // Add your admob publisher id
                .build()

1.b Initializing without Builder class

Java

    String deviceId = "your device id from logcat";
    String publisherId = "pub-0123456789012345";
    String privacyUrl = "https://your.privacy.url/";
    ConsentSDK consentSDK = new ConsentSDK(context, publisherId, privacyUrl, true);

Kotlin

    val deviceId = "your device id from logcat"
    val publisherId = "pub-0123456789012345"
    val privacyUrl = "https://your.privacy.url/"
    val consentSDK = ConsentSDK(context, publisherId, privacyUrl, true)

Choose one of the methods to initialize the ConsentSDK from above.

2. Then check the consent using:

Java

    consentSDK.checkConsent(new ConsentSDK.ConsentCallback() {
            @Override
            public void onResult(boolean isRequestLocationInEeaOrUnknown) {
                // Your code
            }
        });

Kotlin

    consentSDK.checkConsent(object : ConsentSDK.ConsentCallback() {
            override fun onResult(isRequestLocationInEeaOrUnknown: Boolean) {
                // Your code
            }
        })

How checkConsent works:

- Check the location of the user if it's within EEA and with unknown status.
- If the user is within EEA and with unknown status show the dialog for consent with two options to see relevant ads or to show less relevant ads.
- The function retrieve a callback after the consent has been submitted or if it's not necessary not show the dialog.
- It's save the consent of the user and if the user is not within EEA it saves show relevant ads status.

3. You should load the ads (banner or interstitial ..) using the function below:

Java

    // To Load the banner
    adView.loadAd(ConsentSDK.getAdRequest(context));
    // To Load Interstitial
    interstitialAd.loadAd(ConsentSDK.getAdRequest(context));

Kotlin

    // To Load the banner
    adView.loadAd(ConsentSDK.getAdRequest(context))
    // To Load Interstitial
    interstitialAd.loadAd(ConsentSDK.getAdRequest(context))

4. To Check if the user is within EEA or not.

Java

    // But you must be called after consent.checkConsent(callback) because it will update the status of the user
    ConsentSDK.isUserLocationWithinEea(context); // Returns true if within false if not.

Kotlin

    // But you must be called after consent.checkConsent(callback) because it will update the status of the user
    ConsentSDK.isUserLocationWithinEea(context) // Returns true if within false if not.

5. To request the consent form to re-edit it for the users within EEA.

Java

    // To request the consent form to re-edit it for the users within EEA
    consentSDK.requestConsent(new ConsentSDK.ConsentStatusCallback() {
        @Override
        public void onResult(boolean isRequestLocationInEeaOrUnknown, int isConsentPersonalized) {
            // Your code after the consent is submitted if needed
        }
    });

Kotlin

    // To request the consent form to re-edit it for the users within EEA
    consentSDK.requestConsent(object : ConsentSDK.ConsentStatusCallback() {
            override fun onResult(isRequestLocationInEeaOrUnknown: Boolean, isConsentPersonalized: Int) {
                // Your code after the consent is submitted if needed
            }
        })

Note:

~ This library is just an editing of the official Google Consent SDK Android with some tweaks and with some helper class to simplify the comply of the app to GDPR policy.

~ That's it, if you followed the steps above your app will be comply with the GDPR policy.

Made by Ayoub Fletcher with LOVE ❤️.

gdpr-admob-android's People

Contributors

healthybinary avatar

Stargazers

Abir Hasan avatar  avatar  avatar Hmimssa Soufiane avatar Rohit Verma avatar  avatar  avatar Anuchit Singkhornart avatar Abderrahim Ajakka avatar Guillermo avatar Afzal Khan avatar Sandeep Kurne avatar  avatar  avatar  avatar  avatar Darshan avatar  avatar Andrés Hernández avatar Samuel Philipp avatar Igor Lückel avatar  avatar Infinite Dreams avatar  avatar  avatar  avatar  avatar SALIH EliASSE avatar Simone Mapelli avatar  avatar Nurmuhammad avatar Smart Coders avatar  avatar  avatar  avatar  avatar  avatar Aitoubella Marouane avatar  avatar Shogo Sato avatar

Watchers

James Cloos avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar Aymen Chikhaoui avatar  avatar  avatar

gdpr-admob-android's Issues

Error:(23, 44) error: cannot access zzbej

Hi Ayoub,
After I add implementation 'com.github.ayoubfletcher.GDPR-Admob-Android:consentsdk:0.1.6'

it shows these 2 Errors below

Error:(23, 44) error: cannot access zzbej
class file for com.google.android.gms.internal.zzbej not found

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

and then it takes me to MyFirebaseMessagingService.java

here some screenshots of my build.gradle and the error and MyFirebaseMessagingService.java page
https://imgur.com/a/Q2LP4X6

Can you please help

Please explain Callback

Hi
very nice work !

Please be so nice and make a better explanation here:

consentSDK.checkConsent(new ConsentSDK.ConsentSDKCallback() {
@OverRide
public void onResult() {
// Your code
}
});

how to check ? if result = ? or how
thanx

Is user in eea

Not really an issue. Is your code checking to see if publisher is Is Europe or end app user? It seems like it's using publisher id??

Also can you please let me know if there is a rest api to call directly to see result? Sample parms please. Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.