Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Setting Unity Services analytics custom user id

Discussion in 'Unity Analytics' started by DevelopingSlowlyButProudly, Jan 26, 2022.

  1. DevelopingSlowlyButProudly

    DevelopingSlowlyButProudly

    Joined:
    Dec 10, 2021
    Posts:
    17
    Hi,

    https://docs.unity.com/analytics/CustomUserIDSupport.htm

    Code (CSharp):
    1. options.SetAnalyticsUserId("some-user-id");
    There is no such option to call. How can i set custom user id for analytics?

    Do I miss some packages?
    I am using:
    "com.unity.services.analytics": "3.0.0-pre.2",
    "com.unity.remote-config": "3.0.0-pre.3"
     
    Last edited: Jan 26, 2022
  2. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi there,

    You do not need to add any extra packages to your project, but in the script you should make sure that you also include
    using Unity.Services.Core;
    in the imports section. That is where the option to call that can be found.
     
  3. DevelopingSlowlyButProudly

    DevelopingSlowlyButProudly

    Joined:
    Dec 10, 2021
    Posts:
    17
    @EllieF_Unity Thanks for fast reply. Unfortunately I already have:

    using Unity.Services.Core; 
    and
    using Unity.Services.Core.Environments;
    and there is no such option.

    All I have is:
     
  4. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi there,

    Looking further into the issue, I have also noticed that the function is not there as I thought. This includes some other option functions that I expect should be there. I am communicating with the developers to find out what the situation is. Please bear with me.
     
  5. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    It seems that I have been caught out and thought that this feature was already released. This feature is available in the next version of the SDK that is coming out very soon. The documentation pages were unfortunately published a little prematurely.
     
  6. DevelopingSlowlyButProudly

    DevelopingSlowlyButProudly

    Joined:
    Dec 10, 2021
    Posts:
    17
    Thanks, is there any specific date when it will come out?
     
  7. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    I can't give a specific date unfortunately, but I'll make sure to reply to this thread to notify you when I have a confirmation of the release being out.
     
  8. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi there,

    The new version of the analytics SDK has been released. The new version number is 3.0.0-pre.3

    Thank you for your patience.
     
  9. DevelopingSlowlyButProudly

    DevelopingSlowlyButProudly

    Joined:
    Dec 10, 2021
    Posts:
    17
    Thank you, but new version is still missing the feature.
     
    Last edited: Jan 28, 2022
  10. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    You should now also import
    Unity.Services.Core.Analytics
    to be able to set a custom user id.
     
  11. DevelopingSlowlyButProudly

    DevelopingSlowlyButProudly

    Joined:
    Dec 10, 2021
    Posts:
    17
    Thank you very much!
     
    EllieF_Unity likes this.
  12. Tomumental

    Tomumental

    Joined:
    Nov 2, 2021
    Posts:
    11
    Does this functionality only work once per run? After a user logs out and a different one logs in I am trying to reinitialize with a new user ID. Events continue to send, but every event arrives in the dashsboard with the first user's ID

    Code (CSharp):
    1. options.SetAnalyticsUserId(loggedInUserId);
    2. await UnityServices.InitializeAsync(options);
     
  13. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
  14. Tomumental

    Tomumental

    Joined:
    Nov 2, 2021
    Posts:
    11
    I've given a profile management a shot, but the second initialization is not taking effect - I keep seeing the first UserID.
    My process is:
    1. Initialize Unity Game Services with a profile and specific Analytics UserID
    2. Initialize RemoteConfig with a CustomUserID
    3. Send a custom event
    4. Try a few ways of adding 'padding' to ensure first event has fully sent through (i.e. Task.Delay and Events.Flush)
    5. Log out of AuthenticationService
    6. Reinitialize Unity Game Services with a new profile and a new Analytics UserID
    7. Reinitialize RemoteConfig with a new CustomUserID
    8. Send another custom event
    I am expecting to see a different userID and uasUserID on the second event in step 8, but I always see the first user's IDs.

    Code (CSharp):
    1. public async void Init()
    2. {
    3.       var firstUserID = "FirstUser";
    4.       //Initialize UnityServices
    5.       var options = new InitializationOptions();
    6.       options.SetEnvironmentName("development");
    7.       options.SetProfile("MyFirstProfile");
    8.       options.SetAnalyticsUserId(firstUserID);
    9.  
    10.       if (UnityServices.State == ServicesInitializationState.Initialized && AuthenticationService.Instance.IsSignedIn)
    11.       {
    12.           AuthenticationService.Instance.SignOut();
    13.       }
    14.  
    15.       await UnityServices.InitializeAsync(options);
    16.       AuthenticationService.Instance.SwitchProfile("MyFirstProfile");
    17.       //End Initialize UnityServices
    18.  
    19.       //Initialize Remote Config
    20.       await AuthenticationService.Instance.SignInAnonymouslyAsync();
    21.       ConfigManager.FetchCompleted -= ApplyRemoteSettings;
    22.       ConfigManager.FetchCompleted += ApplyRemoteSettings;
    23.       ConfigManager.SetEnvironmentID("redacted-for-forums");
    24.       ConfigManager.SetCustomUserID(firstUserID);
    25.       await ConfigManager.FetchConfigsAsync(new userAttributes(), new appAttributes());
    26.       //End Initialize Remote Config
    27.  
    28.       //Send First Event
    29.       Dictionary<string, object> firstEventParamaters = new Dictionary<string, object>();
    30.       firstEventParamaters.Add("uasUserID", AuthenticationService.Instance.PlayerId);
    31.       firstEventParamaters.Add("packType", "This Is The First Event");
    32.       Events.CustomData("TestCustomUser", firstEventParamaters);
    33.       //End Send First Event
    34.  
    35.       Debug.Log("End of Send First Event");
    36.  
    37.       Events.Flush(); //Have tried with and without Events.Flush()
    38.       await Task.Delay(1000 * 180 /* 3 min */); //Tried with and without this delay timing padding to simulate normal sending
    39.  
    40.       var secondUserID = "2ndUser";
    41.       //Reinitialize UnityServices with a new Profile
    42.       var reinitializeOptions = new InitializationOptions();
    43.       reinitializeOptions.SetEnvironmentName("development");
    44.       reinitializeOptions.SetProfile("MySecondProfile");
    45.       reinitializeOptions.SetAnalyticsUserId(secondUserID);
    46.  
    47.       if (UnityServices.State == ServicesInitializationState.Initialized && AuthenticationService.Instance.IsSignedIn)
    48.       {
    49.           AuthenticationService.Instance.SignOut();
    50.       }
    51.  
    52.       await UnityServices.InitializeAsync(reinitializeOptions);
    53.       AuthenticationService.Instance.SwitchProfile("MySecondProfile");
    54.       //End Reinitialize UnityServices with a new Profile
    55.  
    56.       //Reinitialize Remote Config with new customID
    57.       await AuthenticationService.Instance.SignInAnonymouslyAsync();
    58.       ConfigManager.FetchCompleted -= ApplyRemoteSettings;
    59.       ConfigManager.FetchCompleted += ApplyRemoteSettings;
    60.       ConfigManager.SetEnvironmentID("redacted-for-forums");
    61.       ConfigManager.SetCustomUserID(secondUserID);
    62.       await ConfigManager.FetchConfigsAsync(new userAttributes(), new appAttributes());
    63.       //End Reinitialize Remote Config with new customID
    64.  
    65.       //Send Second Event
    66.       Dictionary<string, object> secondEventParamaters = new Dictionary<string, object>();
    67.       secondEventParamaters.Add("uasUserID", AuthenticationService.Instance.PlayerId);
    68.       secondEventParamaters.Add("packType", "Here we find a second event");
    69.       Events.CustomData("TestCustomUser", secondEventParamaters);
    70.       //End Send Second Event
    71.  
    72.       Debug.Log("End of Send Second Event");
    73.  
    74.       Events.Flush(); //Tried with and without .Flush()
    75.       await Task.Delay(1000 * 180 /* 3 min */); //Tried with and without this delay timing padding to simulate normal sending
    76.  
    77.       Debug.Log("End of test process");
    78. }
    79.  
    80. void ApplyRemoteSettings(ConfigResponse configResponse)
    81. {
    82.       switch (configResponse.requestOrigin)
    83.       {
    84.           case ConfigOrigin.Default:
    85.               Debug.Log("RemoteConfig not loaded, using default values.");
    86.               break;
    87.           case ConfigOrigin.Cached:
    88.               Debug.Log("RemoteConfig using cached values from a previous session.");
    89.               break;
    90.           case ConfigOrigin.Remote:
    91.               Debug.Log("New RemoteConfig settings loaded from Remote");
    92.               break;
    93.           default:
    94.               Debug.LogWarning($"Unrecognized ConfigOrigin: {configResponse.requestOrigin}");
    95.               break;
    96.       }
    97.   }
    edit: While I had missed a couple AuthenticationService.Instance.SwitchProfile calls, the events still are being sent as the first user. I've included the missing calls in the above snippet

    Screen Shot 2022-02-02 at 3.47.23 AM.png Screen Shot 2022-02-02 at 3.47.37 AM.png
     
    Last edited: Feb 4, 2022
    lanpartygamesstudio likes this.
  15. UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    Joined:
    May 2, 2019
    Posts:
    3
    I cannot see the option "SetAnalyticsUserId"..
    I`m using "3.0.0-pre.3" now.
    and I set like this..
    upload_2022-2-4_0-2-7.png
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  17. UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    Joined:
    May 2, 2019
    Posts:
    3
  18. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I just confirmed by updating my project to 3.0.0-pre.3 and I see Unity.Services.Core.Analytics. Please compare to a new project in your case. You may need to regenerate your VS files.
     
  19. UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    UDN_2537f5a4-a085-44eb-8338-8dea8fa76a9e

    Joined:
    May 2, 2019
    Posts:
    3
    oh solved! thanks!
     
    unity_Ctri likes this.