Unity Gaming Services Analytics always giving consentIdentifiers 0

So I started to play with Unity Services and the Analytics stuff. When I try to get the Consent Identifiers, for some reason I always get back 0.

This is my code (this is a Playmaker custom action btw):

 try
            {
                //wait until Unity Services are initialized
                await UnityServices.InitializeAsync();

                //Check for Required Consent and store each list item as strings
                List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
                Debug.Log("ConsentIdentifiers Count is " + consentIdentifiers.Count);

                if (consentIdentifiers.Count > 0)
                {
                    consentIdentifier.Value = consentIdentifiers[0];
                    Debug.Log("Consent Identifier is: " + consentIdentifiers[0]);
                    country.Value = consentIdentifiers[1];
                    Debug.Log("Country is: " + consentIdentifiers[1]);
                    region.Value = consentIdentifiers[2];
                    Debug.Log("Region is: " + consentIdentifiers[2]);
                    ageGateLimit.Value = consentIdentifiers[3];
                    Debug.Log("Age Gate Limit is: " + consentIdentifiers[3]);

                    //Set Consent Required Bool if Identifier is gdpr, ccpa or pipl
                    isConsentRequired.Value = consentIdentifier.Value == "pipl" || consentIdentifier.Value == "gdpr" || consentIdentifier.Value == "ccpa";
                }

                //send events
                if (isConsentRequired.Value)
                {
                    Fsm.Event(consentRequiredEvent);
                }
                else
                {
                    Fsm.Event(noConsentRequiredEvent);
                }
            }

When I open the Website: https://pls.prd.mz.internal.unity3d.com/api/v1/user-lookup
I do get the identifier and country and all... so in theory it should return the usual 4 rather than 0 items. Why do I get 0 items though all the time?

PS: I'm not in a GDPR, CCPA or PIPL country if that makes any difference.

So trying to debug this further with my limited coding knowledge, the problem actually seems to be that Unity Gaming Services never are initialized.

I use this code (in a playmaker action as well) to initialize:

using UnityEngine;
using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Unity Engine")]
    [Tooltip("Initializes the Unity Gaming Services (UGS) and sends an event when finished.")]
    public class InitializeUGS : FsmStateAction
    {
        [Tooltip("Event to send once the Unity Gaming Services are initialized.")]
        public FsmEvent initializedEvent;

        public ServicesInitializationState initializationState;

        public override void Reset()
        {
            initializedEvent = null;
        }

        public override void OnEnter()
        {
            InitializeUGSAsync();
        }

        public override void OnUpdate()
        {


            if (initializationState == ServicesInitializationState.Initialized)
            {
                Debug.Log("Unity Gaming Services IS " + initializationState);
                Fsm.Event(initializedEvent);
            }

            if (initializationState == ServicesInitializationState.Initializing)
            {
                Debug.Log("Unity Gaming Services is " + initializationState);
            }

            if (initializationState == ServicesInitializationState.Uninitialized)
            {
                Debug.Log("Unity Gaming Services is " + initializationState);
            }
        }

        async void InitializeUGSAsync()
        {
            try
            {
                var options = new InitializationOptions()
                    .SetEnvironmentName("production");

                await UnityServices.InitializeAsync(options);
            }

            catch (Exception exception)
            {
                Debug.Log("An error occured during initializing the Unity Gaming Services. Reason: " + exception);
            }

        }
    }
}

I did the OnUpdate part to debug and it just continues to stay on Uninitialized. Doesn't even go into Initializing... what could be the reason for this? The action is called, and the code clearly runs...

ok, ChatGPT to the rescue. Got me to correct my action to:

using UnityEngine;
using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory("Unity Engine")]
   [Tooltip("Initializes the Unity Gaming Services (UGS) and sends an event when finished.")]
   public class InitializeUGS : FsmStateAction
   {
        [Tooltip("Event to send once the Unity Gaming Services are initialized.")]
       public FsmEvent initializedEvent;

       public override void Reset()
       {
           initializedEvent = null;
       }

       public override void OnEnter()
       {
           InitializeUGSAsync();
       }

        async void InitializeUGSAsync()
        {
            try
            {
                var options = new InitializationOptions()
                    .SetEnvironmentName("production");

                await UnityServices.InitializeAsync(options);
            }

            catch (Exception exception)
            {
                Debug.Log("An error occured during initializing the Unity Gaming Services. Reason: " + exception);
            }

        }

        public override void OnUpdate()
        {
            if (UnityServices.State == ServicesInitializationState.Initialized)
            {
                Debug.Log("Unity Gaming Services is " + UnityServices.State);
                Fsm.Event(initializedEvent);
            }
            else if (UnityServices.State == ServicesInitializationState.Initializing)
            {
                Debug.Log("Unity Gaming Services is " + UnityServices.State);
            }
            else if (UnityServices.State == ServicesInitializationState.Uninitialized)
            {
                Debug.Log("Unity Gaming Services is " + UnityServices.State);
            }
        }
    }
}

Now it works and seems it's actually initializing correctly. My debug code was wrong. :P

Will keep researching why the heck I get 0 consentidentifiers...

No matter what I do I always get a consentIdentifiers.Count of 0. Anyone could help?

I connected with a VPN and even being in France it shows that the count is 0. It just won't fill the list with the needed items.

What could be the problem?

A count of 0 indicates you are in a PIPL region, try connecting without a VPN.

Data privacy and consent (unity.com)


Wouldn't the identifier be 'pipl' rather than it being 0? Also, pipl should show/apply only in China as far as I'm aware.

I tried with and without a VPN. I'm myself in a no consent required country, but it still shows 0. In Europe it should show 'gdpr', yet still 0, in USA, California it should show 'ccpa' yet it still shows 0.

I can make a webrequest and the items show correctly as they should with or without VPN on. So for some reason the API request is not working.

I can't advocate that using ChatGPT will solve any issues surrounding UGS Analytics as it contains no knowledge of the service because the data it has access to is only up to 2021.

I wrote a support article a while ago, which is now included in the documentation: Analytics GDPR, CCPA and PIPL Consent, Opt-Out and Opt-BackIn – Unity
It might be worth checking it out though as you might still find it useful, and trying the method which has been tested to work.

If the documentation samples do not work for you then please let me know.

Even though the GeoIP loopup request is primed during initialisation, this happens internally so its result must be checked manually by you by calling the CheckForRequiredConsents method once UGS initialisation is complete.

If it succeeds, this returns a list of consents that apply to the player that require opt-in consent.

  • If this list is empty, then the SDK has already started collecting events and everything is "fine" - (GDPR and CCPA)
  • If this list contains any entries, the developer must call ProvideOptInConsent(identifier, true) for each before the SDK will become active (they may also call 'false' if the player decided not to provide consent) - (PIPL)

This logic is effectively hardcoded to only function for PIPL. Other legislations are assumed to be opt-out only and will not be included in the list returned by the CheckForRequiredConsents call, regardless of what legislation is actually returned by the user-lookup service.

Note: If the geoIP call returns PIPL, the SDK remains dormant until the explicit opt-in is provided. Only PIPL will make it through to the end-user. The other legislations are accepted internally and assume an opt-in-by-default, explicit opt-out situation.

(Fun fact: if the player was to move between countries during a single session, no change in effective legislation would be detected.)

We are currently aware of this and are actively reworking the privacy flow to address these4 concerns.

2 Likes


CheckForRequiredConsents method is obsolete in Analytics SDK 5.0.0. How can I check if a user is from GDPR or CCPA or PIPL area?