admob-plus / admob-plus

Trustable AdMob Plugin for Cordova, Capacitor, Ionic, React Native
https://admob-plus.github.io
MIT License
361 stars 150 forks source link

consentStatus always has the value 0 (Unknown) #631

Open sergip76 opened 5 months ago

sergip76 commented 5 months ago

Plugin version: admob-plus-cordova 2.0.0-alpha.13 cordova-plugin-consent 3.0.0-alpha.4

When starting the application for the first time consentStatus always has the value 0 (Unknown). Therefore the form is not displayed. If I force to show the form using this code:

    if (consentStatus === consent.ConsentStatus.Required || consentStatus === consent.ConsentStatus.Unknown) {

        await consent.requestInfoUpdate()

    }

    const formStatus = await consent.getFormStatus();

    if (formStatus === consent.FormStatus.Available) {

        const form = await consent.loadForm();
        form.show();

    }

the form is displayed. I do not respond and I close the app. The next times the application is opened consentStatus is already set to 1 (Required). It seems that the form must be displayed at least once for the consentStatus to have a correct value and not be 0.

The behavior is the same for both Android and iOS.

1n3JgKl9pQ6cUMrW commented 5 months ago

This is a well known bug, the plugin "as is" doesn't work 100% flawless.

See my workaround;

https://github.com/admob-plus/admob-plus/issues/601#issuecomment-1702578477

You can get rid of the "on exit kill this app" plugin (mentioned in this thread) by setting another boolean check before really showing the form;

image

(raw code, not the code from the plugin)

fredriksthlm commented 5 months ago

to get the consent.ConsentStatus you must always first execute consent.requestInfoUpdate()

This is well explained in the official Admob documentation, but not explained in this plugin. But regardless, your app should always execute consent.requestInfoUpdate() to start with, then the consentstatus will be updated, then you can show the form if status states 'required'

sergip76 commented 5 months ago

to get the consent.ConsentStatus you must always first execute consent.requestInfoUpdate()

This is well explained in the official Admob documentation, but not explained in this plugin. But regardless, your app should always execute consent.requestInfoUpdate() to start with, then the consentstatus will be updated, then you can show the form if status states 'required'

Thank you very much! That is the solution. I changed the order of the sentences in the code and now it works perfectly. This is how it looks like:

    await consent.requestInfoUpdate()
    const consentStatus = await consent.getConsentStatus();

    if (consentStatus === consent.ConsentStatus.Required) {

        const formStatus = await consent.getFormStatus();

        if (formStatus === consent.FormStatus.Available) {

            const form = await consent.loadForm();
            form.show();

        }

    }

@ratson It must be changed in the plugin documentation.

AbdulRazak-Naeate commented 5 months ago

@sergip76 I tried it, but it's not working, i got no response from ' const consentStatus = await consent.getConsentStatus();' please can you explain more about how to integrate it I may have missed something.

sergip76 commented 5 months ago

@sergip76 I tried it, but it's not working, i got no response from ' const consentStatus = await consent.getConsentStatus();' please can you explain more about how to integrate it I may have missed something.

I simply added this code just before displaying the advertisement. You have to keep in mind that it must be inside an asynchronous function. For example:

async function askBeforePublicity() {

     // ----> I add here code for Tracking Authorization in iOS

    await consent.requestInfoUpdate()
    const consentStatus = await consent.getConsentStatus();

    if (consentStatus === consent.ConsentStatus.Required) {

        const formStatus = await consent.getFormStatus();

        if (formStatus === consent.FormStatus.Available) {

            const form = await consent.loadForm();
            form.show();

        }

    }

}

And to show it:

     (async () => {

            await askBeforePublicity();
            await admob.start();

           // --> Here your code to show publicity

    })()

IMPORTANT: Remember to add your custom message for the specific application in your Admob account.