Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question UGS Analytics initialization error - DeserializationIssue

Discussion in 'Unity Analytics' started by Bryarey, Oct 26, 2023.

  1. Bryarey

    Bryarey

    Joined:
    Aug 24, 2014
    Posts:
    25
    Hi there! After having UGS Analytics perfectly work for a while, I have created a new build (without any major changes related to analytics itself) - and have everything stuck. My errors during initialization:
    1:
    Error Unity ServicesInitializationException: The Analytics service has not been initialized. Please initialize Unity Services.
    2:
    Error Unity [ServicesCore]: An error occured while trying to get the project configuration for services.
    3:
    Error Unity Can not initialize UGS Analytics! Consent error, reason: DeserializationIssue

    - My UGS Analytics version from package manager is 4.4.2 (and I can't get the docs for exactly this version)
    - My unity engine version is 2020.3.38f1

    How can I fix it?

    How I initialize:

    await UnityServices.InitializeAsync();

    // checking consent identifiers and showing popup, if needed - no errors here

    //if got PIPL consent:
    AnalyticsService.Instance.ProvideOptInConsent(PIPL_CONSENT_IDENTIFIER, result);

    //after all the consent manipulations
    _ = AnalyticsService.Instance.SetAnalyticsEnabled(true);

    Full code:

    Code (CSharp):
    1. public UgsAnalytics(PopupManager popupManager)
    2. {
    3.     _popupManager = popupManager;
    4.     if (PlayerPrefs.HasKey(ANALYTICS_OPT_OUT_KEY) && PlayerPrefs.GetInt(ANALYTICS_OPT_OUT_KEY) == 1)
    5.     {
    6.         AnalyticsService.Instance.OptOut();
    7.     }
    8.  
    9.     InitializeUnityAnalyticsAsync();
    10. }
    11.  
    12. private async void InitializeUnityAnalyticsAsync()
    13. {
    14.     try
    15.     {
    16.         await UnityServices.InitializeAsync();
    17.         List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
    18.         foreach (var identifier in consentIdentifiers)
    19.         {
    20.             if (identifier == PIPL_CONSENT_IDENTIFIER)
    21.             {
    22.                 CheckUserConsent();
    23.             }      
    24.         }
    25.     }
    26.     catch (ConsentCheckException e)
    27.     {
    28.         Debug.LogError("Can not initialize UGS Analytics! Consent error, reason: " + e.Reason);
    29.     }
    30.     _ = AnalyticsService.Instance.SetAnalyticsEnabled(true);
    31. }
    32.  
    33. public void CheckUserConsent()
    34. {
    35.     try
    36.     {
    37.         var consentPopup = _popupManager.GetPopup<UgsAnalyticsConsentController, UgsAnalyticsConsentController.Factory>();
    38.         consentPopup.OnResult += OnConsentResult;
    39.         consentPopup.Show();
    40.     }
    41.     catch (ConsentCheckException e)
    42.     {
    43.         Debug.LogError("Error during getting PIPL consent, reason: " + e.Reason);
    44.     }
    45.  
    46. }
    47.  
    48. private void OnConsentResult(bool result)
    49. {
    50.     AnalyticsService.Instance.ProvideOptInConsent(PIPL_CONSENT_IDENTIFIER, result);
    51. }
     
  2. ransuz

    ransuz

    Joined:
    May 22, 2017
    Posts:
    6
    In my case, strangely enough. It had to do with the app version set in Unity.
    For example, if you set the app version to 11.1 and used Analytics even once, and then changed the version to 10.0, an error occurred saying that init was not performed. And setting it back to version 11.1 or higher fixed the error.