googleads-mobile-unity icon indicating copy to clipboard operation
googleads-mobile-unity copied to clipboard

Consent form not Update Status

Open viveksaini75 opened this issue 2 years ago • 9 comments

[REQUIRED] Step 1: Describe your environment Unity version:- 2022.3.6f1 Google Mobile Ads Unity plugin version:- 8.5.3 Platform:- Android

public bool CanRequestAds => ConsentInformation.ConsentStatus == ConsentStatus.NotRequired || ConsentInformation.ConsentStatus == ConsentStatus.Obtained;

public void GatherConsent(Action<string> onComplete)
{
    
    Debug.Log("Gathering consent.");

    var requestParameters = new ConsentRequestParameters
    {
        // False means users are not under age.
        TagForUnderAgeOfConsent = false,
        ConsentDebugSettings = new ConsentDebugSettings
        {
            // For debugging consent settings by geography.
            DebugGeography = DebugGeography.EEA,
            TestDeviceHashedIds = new List<string>
            {
                ""
            }
        }
        
    };

    // The Google Mobile Ads SDK provides the User Messaging Platform (Google's
    // IAB Certified consent management platform) as one solution to capture
    // consent for users in GDPR impacted countries. This is an example and
    // you can choose another consent management platform to capture consent.
    ConsentInformation.Update(requestParameters, (FormError updateError) =>
    {
        if (updateError != null)
        {
            onComplete?.Invoke(updateError.Message);
            return;
        }

        // Determine the consent-related action to take based on the ConsentStatus.
        if (CanRequestAds)
        {
            // Consent has already been gathered or not required.
            // Return control back to the user.
            onComplete?.Invoke(null);
            return;
        }

        // Consent not obtained and is required.
        // Load the initial consent request form for the user.
        ConsentForm.LoadAndShowConsentFormIfRequired((FormError showError) =>
        {
            // Form showing succeeded.
            // Form showing failed.
            onComplete?.Invoke(showError?.Message);
        });
    });
}

We are facing an issue and that is whenever we allow Consent for the first time, things work fine but in the case of a second attempt, "CanRequestAds" shows the false Value. Please review and assist me to resolve this issue.

viveksaini75 avatar Nov 21 '23 07:11 viveksaini75

@viveksaini75

Your sample has old code for checking if you CanRequestAds. We have updated our API to check with a platform client.

https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/GoogleMobileAds/Ump/Api/ConsentInformation.cs#L106

NVentimiglia avatar Nov 21 '23 22:11 NVentimiglia

Thank you for your response @NVentimiglia Please find the Consent implementation script below and currently, I'm using the latest SDK version(8.6.0)

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using GoogleMobileAds.Ump.Api;
 using UnityEngine;

  public class GdprScript
  {
        public bool CanRequestAds => ConsentInformation.CanRequestAds();


       public void GatherConsent(Action<string> onComplete)
       {
    
    Debug.Log("Gathering consent.");

    var requestParameters = new ConsentRequestParameters
    {
        // False means users are not under age.
        TagForUnderAgeOfConsent = false
    };

    // The Google Mobile Ads SDK provides the User Messaging Platform (Google's
    // IAB Certified consent management platform) as one solution to capture
    // consent for users in GDPR impacted countries. This is an example and
    // you can choose another consent management platform to capture consent.
    ConsentInformation.Update(requestParameters, (FormError updateError) =>
    {
        if (updateError != null)
        {
            onComplete?.Invoke(updateError.Message);
            return;
        }

        // Determine the consent-related action to take based on the ConsentStatus.
        if (CanRequestAds)
        {
            // Consent has already been gathered or not required.
            // Return control back to the user.
            onComplete?.Invoke(null);
            return;
        }

        // Consent not obtained and is required.
        // Load the initial consent request form for the user.
        ConsentForm.LoadAndShowConsentFormIfRequired((FormError showError) =>
        {
            // Form showing succeeded.
            // Form showing failed.
            onComplete?.Invoke(showError?.Message);
        });
    });
}

}

Also, please check below the code which is used before initializing Admob

  if (_gdprScript.CanRequestAds)
    {
        InitializeAdsSdk(_adMobHandler);
    }
    else
    {
        InitializeGoogleMobileAdsConsent();
    }

Issue which I'm Facing : Condition written under if (_gdprScript.CanRequestAds) always return False even after i allow the consent.

Please help me to understand this scenario becasue I'm facing this error since long. This CanRequestAds condition must be True after allowing the "Consent".

viveksaini75 avatar Nov 24 '23 05:11 viveksaini75

@viveksaini75

Did you register your device ids in code?

On Android this is a required step.

https://github.com/googleads/googleads-mobile-unity/blob/main/samples/HelloWorld/Assets/Scripts/GoogleMobileAdsController.cs#L17

NVentimiglia avatar Nov 29 '23 00:11 NVentimiglia

@viveksaini75

Your sample has old code for checking if you CanRequestAds. We have updated our API to check with a platform client.

https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/GoogleMobileAds/Ump/Api/ConsentInformation.cs#L106

Is this change updated in the HelloWorld sample code? I think the HelloWorld code still using the old code. I am using the code from there, so not sure which one is correct. Please let me know.

ChaserKnight avatar Nov 29 '23 18:11 ChaserKnight

@viveksaini75

Did you register your device ids in code?

On Android this is a required step.

https://github.com/googleads/googleads-mobile-unity/blob/main/samples/HelloWorld/Assets/Scripts/GoogleMobileAdsController.cs#L17

Hey @NVentimiglia We have already registered device IDs in the code but we didn't mention them in the code I've shared with you.

viveksaini75 avatar Nov 30 '23 05:11 viveksaini75

@viveksaini75 Your sample has old code for checking if you CanRequestAds. We have updated our API to check with a platform client. https://github.com/googleads/googleads-mobile-unity/blob/main/source/plugin/Assets/GoogleMobileAds/Ump/Api/ConsentInformation.cs#L106

Is this change updated in the HelloWorld sample code? I think the HelloWorld code still using the old code. I am using the code from there, so not sure which one is correct. Please let me know.

This fix should be in today.

NVentimiglia avatar Nov 30 '23 23:11 NVentimiglia

requestParameters

Did you set the DebugGeography to EEA ?

https://github.com/googleads/googleads-mobile-unity/blob/main/samples/HelloWorld/Assets/Scripts/GoogleMobileAdsConsentController.cs#L57

NVentimiglia avatar Nov 30 '23 23:11 NVentimiglia

requestParameters

Did you set the DebugGeography to EEA ?

https://github.com/googleads/googleads-mobile-unity/blob/main/samples/HelloWorld/Assets/Scripts/GoogleMobileAdsConsentController.cs#L57

    var requestParameters = new ConsentRequestParameters
    {
        // False means users are not under age.
        TagForUnderAgeOfConsent = false,
        ConsentDebugSettings = new ConsentDebugSettings
        {
            // For debugging consent settings by geography.
            DebugGeography = DebugGeography.EEA,
            TestDeviceHashedIds = new List<string>
            {
                "bb869d72cec9b2427657e990b937acbe"
            }
        }
    };

Yes, we've already set the DebugGeography to EEA, please find the code shared above.

viveksaini75 avatar Dec 01 '23 05:12 viveksaini75

@viveksaini75

I was able to confirm the issue and have an engineer working on the issue.

I posted a workaround here

NVentimiglia avatar Dec 04 '23 23:12 NVentimiglia