Search Unity

Change Analytics Unique Identifier?

Discussion in 'Unity Analytics' started by Greyborn, Aug 25, 2018.

  1. Greyborn

    Greyborn

    Joined:
    May 26, 2016
    Posts:
    61
    Hello, I have been trying to figure out a way to easily test our funnel logic by doing multiple playthroughs of our game on the same system. Is there an easy way to change my dev system's identifier so Unity Analytics will see it as a new user/machine when I reset our game and do another playthrough?

    I've seen this: https://docs.unity3d.com/ScriptReference/Analytics.Analytics.SetUserId.html

    ...but the documentation for its use (and even what exactly you pass for "userId") is a bit... sparse ;) Can I just pass a random int?

    Is the unique id something I change in Windows 10 (and is that what Unity is using for its ID)?

    Thank you for any suggestions!
     
    Last edited: Aug 25, 2018
  2. Greyborn

    Greyborn

    Joined:
    May 26, 2016
    Posts:
    61
    Also, a related question - what c# code can I use to print the current unique id Analytics is using for my system? While I see there is a SetUserId I don't see any kind of "GetUserId". Thanks again!
     
  3. Greyborn

    Greyborn

    Joined:
    May 26, 2016
    Posts:
    61
    Anyone from the Unity Analytics team that could help us out here?
     
  4. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @Greyborn,

    I would suggest doing this example to change your sessionId for your funnel tests:

    1. Fire the funnel.
    2. Call `PlayerPrefs.DeleteKey("unity.cloud_userid_h2665564582");`
    3. Restart the editor/build
    4. Repeat.

    Restarting will re-create the key "unity.cloud_userid_h2665564582" and also assign the new value to
    AnalyticsSessionInfo.userId
    . I found this post useful as it shows a list of keys for playerPrefs.

    Note: Different Unity versions might have different player pref keys. I'm using 2018.1.5f1 for my test.

    We will be deprecating
    Analytics.SetUserId()
    in the next version of Unity. This is to help developers to comply to GDPR better by avoiding the sending of analytics events that may contain personal data. Before the deprecation you could essentially submit your own userID to help identify where the events are coming from and identify the players.

    If you want to print the userId to the console then you can use
    AnalyticsSessionInfo.userId
    or
    print(PlayerPrefs.GetString("unity.cloud_userid_h2665564582"));
    .

    Hope this helps!
     
    Greyborn likes this.
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    An app reinstall would be considered a new user.
     
    Greyborn likes this.
  6. Greyborn

    Greyborn

    Joined:
    May 26, 2016
    Posts:
    61
    Thank you both, very helpful info!
     
  7. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    How would you reset the Analytics user ID in the Unity Editor (for testing)? It's not convenient to reinstall the app in the editor.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What are you testing in the Editor that requires a new ID? And you would not "reinstall" in the Editor, you just press Play to run the game.
     
  9. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    Well, as you saw in this thread, we're trying to make sure that when a user opts out, we can detect it in our game and disable Facebook/AppsFlyer data tracking as well. We need to be able to reset the randomly generated analytics user GUID in the Editor, since opting-out is a permanent choice for a given user.

    It looks like UnityEngine.Analytics stores this value in PlayerPrefs, so we just need to delete the key "unity.cloud_userid" before playing the game.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Each user has their own "opt out" page where they can change their setting, if that helps. It's also informative to run Charles Proxy to see the network requests https://support.unity3d.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity
     
  11. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    Exactly, that's what I'm referring to. I'd like to "generate a new user" when testing these cases from within the Unity Editor and using the Data Privacy button.