I want to implement GDPR in Unity for my game using Admob Mobile SDK - com.google.android.gms:play-services-ads:22.2.0
In Editor the modal window pops up, but on release, and on test devices it doesn't work.
Unity 2022.3.7f
Here's the implementation code:
using System.Collections.Generic;
using GoogleMobileAds.Ump.Api;
using UnityEngine;
namespace _Code.Scripts._ADS
{
public class GDPRScript : MonoBehaviour
{
private ConsentForm _consentForm;
// Start is called before the first frame update
private void Start()
{
var debugSettings = new ConsentDebugSettings
{
// Geography appears as in EEA for debug devices.
DebugGeography = DebugGeography.EEA,
TestDeviceHashedIds = new List<string>
{
"d8d9feb5-1f1a-40db-a19f-5d70eaee8f50"
}
};
// Here false means users are not under age.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
private void OnConsentInfoUpdated(FormError error)
{
if (error != null)
{
// Handle the error.
UnityEngine.Debug.LogError(error);
return;
}
if (ConsentInformation.IsConsentFormAvailable())
{
LoadConsentForm();
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
}
private void LoadConsentForm()
{
// Loads a consent form.
ConsentForm.Load(OnLoadConsentForm);
}
private void OnLoadConsentForm(ConsentForm consentForm, FormError error)
{
if (error != null)
{
// Handle the error.
UnityEngine.Debug.LogError(error);
return;
}
// The consent form was loaded.
// Save the consent form for future requests.
_consentForm = consentForm;
// You are now ready to show the form.
if (ConsentInformation.ConsentStatus == ConsentStatus.Required)
{
_consentForm.Show(OnShowForm);
}
}
private void OnShowForm(FormError error)
{
if (error != null)
{
// Handle the error.
UnityEngine.Debug.LogError(error);
return;
}
// Handle dismissal by reloading form.
LoadConsentForm();
}
}
}
понеділок, 20 листопада 2023 р. о 06:41:36 UTC+2 Mobile Ads SDK Forum Advisor пише: