Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consentStatus always has the value 0 (Unknown) #631

Open
sergip76 opened this issue Nov 30, 2023 · 5 comments
Open

consentStatus always has the value 0 (Unknown) #631

sergip76 opened this issue Nov 30, 2023 · 5 comments

Comments

@sergip76
Copy link

sergip76 commented Nov 30, 2023

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
Copy link
Contributor

1n3JgKl9pQ6cUMrW commented Nov 30, 2023

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

See my workaround;

#601 (comment)

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
Copy link

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
Copy link
Author

sergip76 commented Nov 30, 2023

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
Copy link

AbdulRazak-Naeate commented Dec 8, 2023

@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
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants