Search Unity

Question Unity Analytics Beta not sending Consent on WebGL

Discussion in 'Unity Analytics' started by DaimenP, Jan 14, 2022.

  1. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    Hello, I'm currently working on a game that uses the new Unity Gaming Services Analytics, and have set up the appropriate class with a consent flow, privacy confirmation, and all. The game is aimed for WebGL, Windows, and Android. When testing, all of the platforms are able to send the consent status properly except for WebGL. When calling
    Events.CheckForRequiredConsents()
    , WebGL never ends up reaching the server, and in the Console of the browser will throw the error posted below. It's not even entering the "Catch" and throwing a reason. Is there something I'm doing wrong, or is the CORS policy trying to reach the Unity site normal?


    Code (CSharp):
    1.  
    2. private async void Start()
    3. {
    4.     Instance = this;
    5.     PlayerPrefs.SetInt("AcceptedPrivacyPolicy", 0);
    6.  
    7.     //return;
    8.    
    9.     if (resettingPlayerConsent) PlayerPrefs.SetInt("ConsentChecked", 0);
    10.    
    11.    consentHasBeenChecked = PlayerPrefs.GetInt("ConsentChecked", 0) == 1;
    12.  
    13.     try
    14.     {
    15.         Debug.LogError("Before Init");
    16.         await UnityServices.InitializeAsync();
    17.         Debug.LogError("After Init");
    18.         List<string> consentIdentifiers = await Events.CheckForRequiredConsents();
    19.         Debug.LogError("After Consent");
    20.     }
    21.     catch (ConsentCheckException e)
    22.     {
    23.         // Something went wrong when checking the GeoIP, check the e.Reason and handle appropriately
    24.         Debug.LogError("Failed at Catch");
    25.         Debug.LogError(e.Reason);
    26.     }
    27.    
    28.     //Debug
    29.     if (resettingPlayerConsent)
    30.     {
    31.         Events.ProvideOptInConsent("0", true);
    32.         resettingPlayerConsent = false;
    33.     }
    34.  
    35.     //If hasn't consented, display Window
    36.     if (!consentHasBeenChecked)
    37.     {
    38.         // Show a GDPR/COPPA/other opt-out consent flow
    39.         privacyPolicyWindow.OpenWindow(AcceptPrivacyPolicy);
    40.     }
    41. }
    42.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @DaimenP Thanks for the report, we will check
     
  3. Newcomma

    Newcomma

    Joined:
    Feb 10, 2015
    Posts:
    89
    Screenshot 2022-01-15 at 12.44.43.png
    Just to add a plus one to this, encountered the consent error when trying to flush events (although I haven't coded up any consent flow, just following the basic 'getting started' guide on the udocs)
     
    zhijiewu likes this.
  4. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    Yeah I was getting a similar error before configuring the consent flow. Once you register the Consent with the Events.CheckForRequiredConsent it should be good, but the problem is that GeoIP isn't working for me on WebGL, and it looks like it's being blocked by domain that Analytics is trying to communicate with. For me, I'm trying to call Events.CheckForRequiredConsent from an itch.io WebGL page. Any info on how I could resolve this would be very appreciated. I want to use the new Unity Gaming Services Beta Analytics for our project, might I might have to resort to implementing Google Analytics instead :/
     
    unity_Ctri likes this.
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You mention "looks like", please confirm and provide the logs here.
     
  6. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    I'm referring to the console logs I posted in the first post of the thread. Specifically,
    Access to XMLHttpRequest at 'https://pls.prd.mz.internal.unity3d.com/api/v1/user-lookup' from origin 'https://v6p9d9t4.ssl.hwcdn.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


    I'll try to see if I can get any more detail than this, but is there something else I can provide that would be more helpful?
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Upon further discussion here, it appears that support on WebGL is not yet fully supported with the Analytics beta. No ETA but hopefully soon
     
    szsahajsz, unity_Ctri and SebT_Unity like this.
  8. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    Oh okay. Well that's good to know, thank you! I thought I saw it in the supported platforms so that may be my mistake. Do the Legacy Analytics work with WebGL still? I think not being able to get WebGL Analytics will be enough to switch back to the Legacy Analytics.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, events do work with legacy Analytics on WebGL but you need to call Analytics.FlushEvents() after every Analytics.CustomEvent() call.
     
  10. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    Okay perfect, can do! Thanks for the information, I really appreciate it. Looking forward to using the Analytics Beta with WebGL games in the future :D
     
  11. szsahajsz

    szsahajsz

    Joined:
    Aug 17, 2018
    Posts:
    13


    would be nice to get beta going with WebGL, this is what I get in browser console
     

    Attached Files:

  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, this has been reported and discussed in this thread.
     
  13. matt_cauldron

    matt_cauldron

    Joined:
    Dec 17, 2021
    Posts:
    48
    Thanks for the info Jeff - are you able to give any guidance on what 'soon' means? i.e. weeks, months, totally undetermined? And of course appreciate that any guidance may change during dev :D
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Hopefully in Q1 of this year.
     
    matt_cauldron likes this.
  15. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    As an update: I heard that Unity may have fixed the issue on their end so I went to give this another try. I was told that it's possible that an ad blocker could be blocking the connection, so I went and gave that a go! However, I tried both disabling the ad blocker and opening the game in an incognito browser, but the code execution is still completely stopping at the Events.CheckForRequiredConsent(), and the same ConsentCheckException occurs when I go to call an Event. So I'm not sure if it's something I'm doing wrong on my end or not, but I'm open to any suggestions.
     
  16. DaimenP

    DaimenP

    Joined:
    Dec 10, 2017
    Posts:
    7
    So I was looking further into this issue, and decided to see if any other services were returning similar errors. I installed the "Authentication" SDK into my project and put the Example Scene that it comes with as the only scene in the Build Settings. In Editor, everything works as expected. However, in an incognito WebGL window we see similar errors to the ones I was getting with the Analytics, mentioning the CORS policy and retrying the sign-in process a few times before throwing an exception. Just posting these findings here in case they help at all.

    upload_2022-1-25_10-26-25.png upload_2022-1-25_10-26-34.png
    upload_2022-1-25_10-27-3.png
     
  17. matt_cauldron

    matt_cauldron

    Joined:
    Dec 17, 2021
    Posts:
    48
    Hi @JeffDUnity3D - just wondering if there were any updates around this issue? Thanks!
     
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No updates at this time. We are still looking into WebGL support
     
    ridley122 and matt_cauldron like this.
  19. matt_cauldron

    matt_cauldron

    Joined:
    Dec 17, 2021
    Posts:
    48
    Appreciate the prompt response!
     
  20. ridley122

    ridley122

    Joined:
    Sep 4, 2017
    Posts:
    3
    I'm running into this same issue - just thought I'd chime in with the rest of you. I see it's only been about a couple weeks since the last ask, but... any updates? Having the new unity analytics work with WebGL would be amazing.
     
  21. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We will post updates here when available, no ETA yet at this time.
     
    ridley122 likes this.
  22. Sam9116_Unity

    Sam9116_Unity

    Unity Technologies

    Joined:
    May 5, 2020
    Posts:
    2
    weird, what do you mean analytics beta is not supported for WebGL? We've been using 2.0.7-pre.7 for WebGL since last November, we didn't use it through package manager though. The package is imported directly as dll through Library\ScriptAssemblies
    there was also no requirement for consent gathering
     
    Last edited: May 5, 2022
  23. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    If your implementation is currently working for you, then great! Yes, consent laws are constantly changing. But the Unity Analytics beta is installed via Package Manager, there is more information here https://support.unity.com/hc/en-us/articles/4408915768724-General-FAQ and https://docs.unity.com/analytics/ComplyingWithGDPRandCCPA.html
     
  24. Mobazy

    Mobazy

    Joined:
    Jan 27, 2018
    Posts:
    9
  25. atomikm

    atomikm

    Joined:
    Feb 8, 2020
    Posts:
    20
    We're also waiting for WebGL support
     
  26. Nurallaerel

    Nurallaerel

    Joined:
    May 6, 2015
    Posts:
    13
    @JeffDUnity3D please advise on this. Is there any (latest?) version of Unity which supports Unity Analytics with WebGL?
     
  27. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Not yet, but we are testing an upcoming release what will support WebGL. So the release will be soon, likely in a few weeks or less if we find no issues in our testing.
     
  28. atomikm

    atomikm

    Joined:
    Feb 8, 2020
    Posts:
    20
    Thank you! I can't emphasize how important this is to us. We are in a very crucial time where we need data analytics on our live game and we are operating blindly because of this issue.
     
    Hojou likes this.
  29. Hojou

    Hojou

    Joined:
    Apr 27, 2015
    Posts:
    7
    I'm also curious if this is still being looked at or dropped? I will need a solution for WebGL but i wait if it on its way - but if it has been dropped, i guess i'll have to use the legacy analytics?
     
  30. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    UGS Analytics 4.2.0 now supports WebGL. If you don't see 4.2.0 listed in Package Manager, then use "Add package by name..." and use com.unity.services.analytics
     
  31. af_unity994

    af_unity994

    Joined:
    Aug 17, 2022
    Posts:
    2
    But async doesn't work for webgl, so how do I initialize it?