Search Unity

Resolved Unity Gaming Services Analytics always giving consentIdentifiers 0

Discussion in 'Unity Analytics' started by el_Guero, Apr 7, 2023.

  1. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    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):

    Code (CSharp):
    1.  try
    2.             {
    3.                 //wait until Unity Services are initialized
    4.                 await UnityServices.InitializeAsync();
    5.  
    6.                 //Check for Required Consent and store each list item as strings
    7.                 List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
    8.                 Debug.Log("ConsentIdentifiers Count is " + consentIdentifiers.Count);
    9.  
    10.                 if (consentIdentifiers.Count > 0)
    11.                 {
    12.                     consentIdentifier.Value = consentIdentifiers[0];
    13.                     Debug.Log("Consent Identifier is: " + consentIdentifiers[0]);
    14.                     country.Value = consentIdentifiers[1];
    15.                     Debug.Log("Country is: " + consentIdentifiers[1]);
    16.                     region.Value = consentIdentifiers[2];
    17.                     Debug.Log("Region is: " + consentIdentifiers[2]);
    18.                     ageGateLimit.Value = consentIdentifiers[3];
    19.                     Debug.Log("Age Gate Limit is: " + consentIdentifiers[3]);
    20.  
    21.                     //Set Consent Required Bool if Identifier is gdpr, ccpa or pipl
    22.                     isConsentRequired.Value = consentIdentifier.Value == "pipl" || consentIdentifier.Value == "gdpr" || consentIdentifier.Value == "ccpa";
    23.                 }
    24.  
    25.                 //send events
    26.                 if (isConsentRequired.Value)
    27.                 {
    28.                     Fsm.Event(consentRequiredEvent);
    29.                 }
    30.                 else
    31.                 {
    32.                     Fsm.Event(noConsentRequiredEvent);
    33.                 }
    34.             }
    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.
     
  2. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    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:
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using Unity.Services.Core;
    4. using Unity.Services.Core.Environments;
    5.  
    6. namespace HutongGames.PlayMaker.Actions
    7. {
    8.     [ActionCategory("Unity Engine")]
    9.     [Tooltip("Initializes the Unity Gaming Services (UGS) and sends an event when finished.")]
    10.     public class InitializeUGS : FsmStateAction
    11.     {
    12.         [Tooltip("Event to send once the Unity Gaming Services are initialized.")]
    13.         public FsmEvent initializedEvent;
    14.  
    15.         public ServicesInitializationState initializationState;
    16.  
    17.         public override void Reset()
    18.         {
    19.             initializedEvent = null;
    20.         }
    21.  
    22.         public override void OnEnter()
    23.         {
    24.             InitializeUGSAsync();
    25.         }
    26.  
    27.         public override void OnUpdate()
    28.         {
    29.            
    30.  
    31.             if (initializationState == ServicesInitializationState.Initialized)
    32.             {
    33.                 Debug.Log("Unity Gaming Services IS " + initializationState);
    34.                 Fsm.Event(initializedEvent);
    35.             }
    36.  
    37.             if (initializationState == ServicesInitializationState.Initializing)
    38.             {
    39.                 Debug.Log("Unity Gaming Services is " + initializationState);
    40.             }
    41.  
    42.             if (initializationState == ServicesInitializationState.Uninitialized)
    43.             {
    44.                 Debug.Log("Unity Gaming Services is " + initializationState);
    45.             }
    46.         }
    47.  
    48.         async void InitializeUGSAsync()
    49.         {
    50.             try
    51.             {
    52.                 var options = new InitializationOptions()
    53.                     .SetEnvironmentName("production");
    54.  
    55.                 await UnityServices.InitializeAsync(options);
    56.             }
    57.  
    58.             catch (Exception exception)
    59.             {
    60.                 Debug.Log("An error occured during initializing the Unity Gaming Services. Reason: " + exception);
    61.             }
    62.          
    63.         }
    64.     }
    65. }
    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...
     
  3. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    ok, ChatGPT to the rescue. Got me to correct my action to:

    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using Unity.Services.Core;
    4. using Unity.Services.Core.Environments;
    5.  
    6. namespace HutongGames.PlayMaker.Actions
    7. {
    8.    [ActionCategory("Unity Engine")]
    9.    [Tooltip("Initializes the Unity Gaming Services (UGS) and sends an event when finished.")]
    10.    public class InitializeUGS : FsmStateAction
    11.    {
    12.         [Tooltip("Event to send once the Unity Gaming Services are initialized.")]
    13.        public FsmEvent initializedEvent;
    14.  
    15.        public override void Reset()
    16.        {
    17.            initializedEvent = null;
    18.        }
    19.  
    20.        public override void OnEnter()
    21.        {
    22.            InitializeUGSAsync();
    23.        }
    24.  
    25.         async void InitializeUGSAsync()
    26.         {
    27.             try
    28.             {
    29.                 var options = new InitializationOptions()
    30.                     .SetEnvironmentName("production");
    31.  
    32.                 await UnityServices.InitializeAsync(options);
    33.             }
    34.  
    35.             catch (Exception exception)
    36.             {
    37.                 Debug.Log("An error occured during initializing the Unity Gaming Services. Reason: " + exception);
    38.             }
    39.            
    40.         }
    41.  
    42.         public override void OnUpdate()
    43.         {
    44.             if (UnityServices.State == ServicesInitializationState.Initialized)
    45.             {
    46.                 Debug.Log("Unity Gaming Services is " + UnityServices.State);
    47.                 Fsm.Event(initializedEvent);
    48.             }
    49.             else if (UnityServices.State == ServicesInitializationState.Initializing)
    50.             {
    51.                 Debug.Log("Unity Gaming Services is " + UnityServices.State);
    52.             }
    53.             else if (UnityServices.State == ServicesInitializationState.Uninitialized)
    54.             {
    55.                 Debug.Log("Unity Gaming Services is " + UnityServices.State);
    56.             }
    57.         }
    58.     }
    59. }
    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...
     
  4. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    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?
     
  5. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
  6. el_Guero

    el_Guero

    Joined:
    Sep 15, 2017
    Posts:
    185
    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.
     
  7. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    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.
     
    el_Guero and MiTschMR like this.
  8. abatushkova

    abatushkova

    Joined:
    Jun 21, 2023
    Posts:
    1
    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?