GDPR Message in sketchware | Admob in Sketchware

Dear Sketchware users, 
Are you getting admob warning to implement GDPR in your app? If yes, then this post is for you because I am here to fix your all problem related to Sketchware and Ads in Sketchware.

What is GDPR?
Admob has announced that All admob users who are using admob alone or with bidding, are needed to show GDPR message in their app. Currently this message is supposed to shown to your app users who are from UK. But Admob allows you to show this message to your all users.

Why it is necessory? 
Admob show personalised ads as per user search history and show ads on topic what user like. But if a user declines to personalised ads then you can't show him ads based on his interest. So that user gets random ads if he declines. This give an impact on our ad revenue also because if user don't see personalised ads then he might not click on that ad. So here GDPR form comes for betterment of both the app user and the app developer.

Let's Start Coding
I recommend you should try to make it in an empty or new project. so you can understand the process then you can implement in sketchware project.

Moreblock 
Create a moreblock and name it "loadform"

OnCreate
Go inside OnCreate event and add one ASD and then add moreblock loadform and then add one more ASD.


In the first ASD add this code

ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .setTagForUnderAgeOfConsent(false)
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
            @Override
            public void onConsentInfoUpdateSuccess() {
                // The consent information state was updated.
                // You are now ready to check if a form is available.
          if (consentInformation.isConsentFormAvailable()) {
               

In the second ASD add this code

}
  }
        },
        new ConsentInformation.OnConsentInfoUpdateFailureListener() {
            @Override
            public void onConsentInfoUpdateFailure(FormError formError) {
                // Handle the error.
            }
        });


Import


Add the imports option and add the following imports 

com.google.android.ump.ConsentForm;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform



Moreblock LOADFORM

In the moreblock loadform add an ASD block and add the following code.



// Loads a consent form. Must be called on the main thread.
UserMessagingPlatform.loadConsentForm(
    this,
    new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
        @Override
        public void onConsentFormLoadSuccess(ConsentForm consentForm) {
            MainActivity.this.consentForm = consentForm;
            if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.REQUIRED) {
                consentForm.show(
                    MainActivity.this,
                    new ConsentForm.OnConsentFormDismissedListener() {
                        @Override
                        public void onConsentFormDismissed(@Nullable FormError formError) {
                            if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                                // User has given consent, load personalized ads
                                _loadPersonalizedAds();
                            } else {
                                // User has declined consent or consent not obtained, load non-personalized ads
                                _loadNonPersonalizedAds();
                            }
                        }
                    });
            } else if (consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
                // Consent is already obtained, load personalized ads
                _loadPersonalizedAds();
            } else {
                // Consent is not required, load personalized ads by default
               _loadPersonalizedAds();
            }
        }
    },
    new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
        @Override
        public void onConsentFormLoadFailure(FormError formError) {
            // Handle Error.
SketchwareUtil.showMessage(getApplicationContext(), "bus1344y");
        }
    }
);


In this code I added reference to two moreblocks the first is 

loadNonPersonalizedAds

And the second is 

loadPersonalizedAds



So you have to create two moreblocks with the same name.


After creating moreblocks you have got the data whether you have to show non personalised ads or personalised ads. So you can add any code on basis of your need. For example you can add shared preferences to store user consent status or you can show ads on that activity. Or you can Give other codes. 

For example I added the adview load in personalised and toast in non personalised .




Mistake points 

You have to change activity name if your launcher activity is not mainactivity

You have to create three moreblocks and be sure while writing their names.

ADDING APP ID 

Go androidmanifest editor in sketchware 


Click on App Components 

Add the following code there 

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxxxx~xxxxx"/>

Remember to replace your app id here.

LOCAL LIBRARY

Download the library by clicking on this link 

https://www.mediafire.com/file/rw49fo3icnjuqiq/user-messaging-platform_V_2.0.0.zip/file

After that add that library to sketchware local library and turn on it in by going to project libraries.



I forgot to tell you have to add two custom variables

ConsentInformation consentInformation

ConsentForm consentForm

Look the image




Please add them so your project works perfectly




This is the all work which was to be done in sketchware. I hope you like the tutorial. 

For admob settings Read this post

http://swrevo.blogspot.com/2023/09/gdpr-message-in-sketchware-part-2-admob.html

Previous Post Next Post