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

Help with consent #447

Closed
dookeybre opened this issue Nov 27, 2023 · 8 comments
Closed

Help with consent #447

dookeybre opened this issue Nov 27, 2023 · 8 comments
Assignees
Labels
solved Developer confirm that issue solved.

Comments

@dookeybre
Copy link

Can anybody help me with implementing gdpr consent?
I have a problem that even tho i show consent dialog and use builder to set consent string, every time i enter my game OnConsentSuccess returns that isNeedConsent is true and consentStatus is UNKNOWN.
Here is the code for settings consent status:

 void SetHuaweiBuilder(int state)
    {
        #if !UNITY_EDITOR
        var builder = HwAds.RequestOptions.ToBuilder();
        if (IsUserUnderAge())
        {
            HwAds.RequestOptions = builder
                .SetConsent("tcfString")
                .SetNonPersonalizedAd(state)
                .SetTagForUnderAgeOfPromise(UnderAge.PROMISE_TRUE)
                .Build();
        }
        else
        {
            HwAds.RequestOptions = builder
                .SetConsent("tcfString")
                .SetNonPersonalizedAd(state)
                .Build();
        }
        #endif
    }

and I call SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_ALL); or SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_NON_PERSONALIZED); depending of the status returned in OnConsentSuccess or the choise user clicked in my custom consent screen

Copy link

 Thank you for reporting this issue/advice.
We will get back to you as soon as possible.
    Would you like to star our plugin
   to support us?:sparkles:

@Andronovo-bit
Copy link
Collaborator

Andronovo-bit commented Nov 28, 2023

Hi dookeybre,

Thank you for reaching out and providing the details of the issue you're encountering with GDPR consent implementation in the game using Huawei's Ads Kit.

Firstly, can you check if the ads kit is active?

Can you check out this demo implementation? AdsDemoManager

@dookeybre
Copy link
Author

Hi,
thank you for your reply. I did enable Ads Kit, also i did check your demo but you just set consent to 'ALLOW_ALL'. I followed the same logic as found on huawei android demo

Here is my full logic

using System.Collections;
using System.Collections.Generic;
using HmsPlugin;
using HuaweiMobileServices.Ads;
using UnityEngine;

public class ConsentController : MonoBehaviour
{
    private readonly string TAG = "[HMS] AdsMyManager: ";
    
    // Start is called before the first frame update
    void Start()
    {
         HMSAdsKitManager.Instance.ConsentOnFail = OnConsentFail;
        HMSAdsKitManager.Instance.ConsentOnSuccess = OnConsentSuccess;
        HMSAdsKitManager.Instance.RequestConsentUpdate();
    }
 private void OnConsentSuccess(ConsentStatus consentStatus, bool isNeedConsent, IList<AdProvider> adProviders)
    {
        Debug.Log($"{TAG}OnConsentSuccess consentStatus:{consentStatus} isNeedConsent:{isNeedConsent}");
        foreach (var AdProvider in adProviders)
        {
            Debug.Log($"{TAG}OnConsentSuccess adproviders: Id:{AdProvider.Id} Name:{AdProvider.Name} PrivacyPolicyUrl:{AdProvider.PrivacyPolicyUrl} ServiceArea:{AdProvider.ServiceArea}");
        }

        if (!isNeedConsent)
        {
            //out of eu and similar
        }
        else
        {
            if (consentStatus == ConsentStatus.PERSONALIZED)
            {
                //request personalized
                SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_ALL);
            }
            else if (consentStatus == ConsentStatus.NON_PERSONALIZED)
            {
                //request non personalized
                SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_NON_PERSONALIZED);
            }
            else if (consentStatus == ConsentStatus.UNKNOWN)
            {
                //If ConsentStatus is UNKNOWN, request user consent (for example, in a dialog box).
//                UnityMainThreadDispatcher.Instance().Enqueue(ConsentNeeded());
                StartCoroutine(nameof(ConsentNeeded));

            }
            
        }
    }

    private void OnConsentFail(string desc)
    {
        Debug.LogError($"{TAG}OnConsentFail:{desc}");
    }
    IEnumerator ConsentNeeded()
    {
        yield return new WaitForEndOfFrame();
        ShowConsentDialog();
    }
    public GameObject huaweiConsentDialog;
    private void ShowConsentDialog () {
        //show the custom dialog box
        huaweiConsentDialog.SetActive(true);
    }

    public void AcceptButtonClicked()
    {
        SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_ALL);
        
    }

    public void DeclineButtonClicked()
    {
        SetHuaweiBuilder((int) NonPersonalizedAd.ALLOW_NON_PERSONALIZED);
    }
    
    
    void SetHuaweiBuilder(int state)
    {
        var builder = HwAds.RequestOptions.ToBuilder();
        builder
            .SetConsent("tcfString")
            .SetNonPersonalizedAd(state)
            .Build();
        
    }
}

My understanding is that when i run the game for the first time it should tell me that consentStatus is 'UNKNOWN' and when i show my custom dialog and choose either accept or decline that choice should be saved on server(or device, I don't understand completely) and next time when i open the game it should return either 'PERSONALIZED' or 'NON_PERSONALIZED'. When I use this code it always returns 'UNKNOWN' like I'm never settings users choice. Any help will mean a lot.

@alihan98ersoy alihan98ersoy added question Further information is requested and removed new labels Nov 29, 2023
@Andronovo-bit
Copy link
Collaborator

Thanks for sharing your code with me @dookeybre. 😊

You should use the account kit with the ad kit (consent) together. And you can try this simple code block below. It's working.

    public void AcceptButtonClicked()
    {
        HMSAdsKitManager.Instance.SetConsentStatus(ConsentStatus.PERSONALIZED);
        HMSAdsKitManager.Instance.RequestConsentUpdate();
        Debug.Log($"[HMS] AdsDemoManager AcceptButtonClicked PERSONALIZED");
        
    }

    public void DeclineButtonClicked()
    {
        HMSAdsKitManager.Instance.SetConsentStatus(ConsentStatus.NON_PERSONALIZED);
        HMSAdsKitManager.Instance.RequestConsentUpdate();
        Debug.Log($"[HMS] AdsDemoManager DeclineButtonClicked NON_PERSONALIZED");
    }

@dookeybre
Copy link
Author

Thank you for your reply, it is solved now.
I have one more question regarding GDPR if you don't mind . When I finish with obtaining and setting consent I then change HwAds.RequestOptions with methods SetNonPersonalizedAd() and SetTagForUnderAgeOfPromise() inside builder. After that I start loading ads for exampe:
interstitialView.LoadAd(new AdParam.Builder().Build());
I saw that AdParam also has similar methods like RequestOptions(SetNonPersonalizedAd and SetTagForUnderAgeOfPromise).
Do I need to call them also when creating AdParam or setting HwAds.RequestOptions was enough?

@Andronovo-bit
Copy link
Collaborator

Andronovo-bit commented Nov 30, 2023

It was my pleasure to assist you.

The HwAds.RequestOptions configuration is enough.

@dookeybre
Copy link
Author

Thank you for all your help.

Copy link

Thank you for using our repository! We're glad we could help solve your issue. If you found our repository helpful, please consider giving us a star ⭐ on GitHub: https://github.com/EvilMindDevs/hms-unity-plugin

Your support helps us continue to improve our repository and provide valuable resources for others.

@alihan98ersoy alihan98ersoy added solved Developer confirm that issue solved. and removed question Further information is requested labels Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved Developer confirm that issue solved.
Projects
None yet
Development

No branches or pull requests

3 participants