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

Question How do I Know, that the user has opted out?

Discussion in 'Unity Analytics' started by manuelgoellnitz, Feb 8, 2023.

  1. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    398
    In the Legacy Analytics there was "Analytics.playerOptedOut" to check if the user has opted out.

    Is there a similar call in the new Unity Analytics? So far I did not find one.
     
  2. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Yes there is,

    This method calls the opt out function, an ideal use case, would be to have a button which calls the function that the user can then press if they don't want to have any data collected on them.
    You can then use a bool and save it then do a check at start up.

    Code (CSharp):
    1. public void OptOut()
    2.     {
    3.         try
    4.         {
    5.             if (!consentHasBeenChecked)
    6.             {
    7.                 // Show a GDPR/COPPA/other opt-out consent flow
    8.                 // If a user opts out
    9.                 AnalyticsService.Instance.OptOut();
    10.              }
    11.              // Record that we have checked a user's consent, so we don't repeat the flow unnecessarily.
    12.              // In a real game, use PlayerPrefs or an equivalent to persist this state between sessions
    13.             consentHasBeenChecked = true;
    14.         }
    15.         catch (ConsentCheckException e)
    16.         {
    17.             // Handle the exception by checking e.Reason
    18.         }
    19.   }
    You kind out more information in the documentation here: Data privacy and consent (unity.com)
     
  3. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    398
    The "Analytics.playerOptedOut" was exactly that bool you describe.
    Since you can re-optin by deleteing all playerPrefs, the optout state is probably stored there as well, couldn't you just create an API call to that state?
    Instead of haveing us do it our selfs
     
  4. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Yes, this was for Legacy Analytics.

    If the player wishes to opt-back in,

    Opt-BackIn#
    Unfortunately there is no easy method to opt back in.

    There are three options:
    1. Delete PlayerPrefs and restart application.
    2. Clear all data and cache for application.
    3. Uninstall application and reinstall.
     
  5. Korczu

    Korczu

    Joined:
    Apr 4, 2020
    Posts:
    10
    Hi guys, I have a similar question. Is there any option to check if all data from analytics has been removed? Let's say that a user requested to delete all app data, including cloud saves and opted out. I would like to redirect the player to a window in which they will be prompted to press the refresh button. Then, I can check if the data from the cloud/local storage was removed and if the opt-out process was successful. While removing and checking the data is not a problem, I'm having trouble finding information on how to check if the user was successfully opted out.

    Maybe if I save the user ID temporarily and check if it exists, but I haven't found any solution for that either. Is there any way to do it in code?