async void Start()
{
try
{
await UnityServices.InitializeAsync();
List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
}
catch (ConsentCheckException e)
{
// Something went wrong when checking the GeoIP, check the e.Reason and handle appropriately
}
}
is used to opt-out of data collection.
So if I understand correclty, this code is used to “not collect analytics”.
So I should only call this piece of code if the user doesn’t want their data to be collected.
This is the bare minimum for GDPR and CCPA for automatic consent however, you need to provide an opt out method to the user.
Here’s an example of an opt out method:
Opt-Out
If the user wants to later opt-out they can do so using the same method for all applicable regulations by using the public void OptOut().
bool consentHasBeenChecked;
{
try
{
if (!consentHasBeenChecked)
{
// Show a GDPR/COPPA/other opt-out consent flow
// If a user opts out
AnalyticsService.Instance.OptOut();
}
// Record that we have checked a user's consent, so we don't repeat the flow unnecessarily.
// In a real game, use PlayerPrefs or an equivalent to persist this state between sessions
consentHasBeenChecked = true;
}
catch (ConsentCheckException e)
{
// Handle the exception by checking e.Reason
}
}```
I've written a little guide here how to do this in further detail: [Analytics GDPR, CCPA and PIPL Consent, Opt-Out and Opt-BackIn – Unity](https://support.unity.com/hc/en-us/articles/8769224780820)
I've noted your feedback and will report this to the documentation team so that we can get the documentation updated :)
Another question : what should be in consentIdentfiers ?
because mine is empty :
async void Start()
{
try
{
await UnityServices.InitializeAsync();
List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
Debug.Log($"Services initialized with ID {consentIdentifiers[0]}");
}
catch (ConsentCheckException e)
{
// Something went wrong when checking the GeoIP, check the e.Reason and handle appropriately.
Debug.LogError($"User did not consent {e}", this);
}
}
Check for any necessary consent from users which depends on their region. The CheckRequiredConsent() uses geoIP tools to determine player region based on IP and will return an empty list if the player is in an ‘opt-in by default’ region (GDPR, CCPA), or “pipl” if they’re in a PIPL region which requires opt-in consent. The SDK will not send any events unless CheckForRequiredConsent() is called.
If the player is in a region where opt-in is required (i.e. PIPL) the game must display a UI asking for consent and then inform the SDK of their choice using AnalyticsService.Instance.ProvideOptInConsent()
The game must provide a menu options / UI / link / etc… to allow the player to opt-out. This applies both to “opt-in by default” regions, and also PIPL regions. So players who were opted in automatically should be able to opt-out … and players who previously manually opted-in should also be able to later choose to opt-out.
Thank you it is clearer now.
I though consentIdentifiers[0] contained something that tells me “this person has accepted or not”.
I think your explanation should be in the documentation because it is very clear.