Hi,
https://docs.unity.com/analytics/CustomUserIDSupport.htm
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”
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.
@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:
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.
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.
Thanks, is there any specific date when it will come out?
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.
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.
1 Like
Thank you, but new version is still missing the feature.
You should now also import Unity.Services.Core.Analytics
to be able to set a custom user id.
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
options.SetAnalyticsUserId(loggedInUserId);
await UnityServices.InitializeAsync(options);
@Tomumental Changing user ids through this system is not a supported feature here. If you would like to have multiple users on one device, I would recommend you have a look at the Profile Management feature from the Authentication tool: Manage profiles
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:
-
Initialize Unity Game Services with a profile and specific Analytics UserID
-
Initialize RemoteConfig with a CustomUserID
-
Send a custom event
-
Try a few ways of adding ‘padding’ to ensure first event has fully sent through (i.e. Task.Delay and Events.Flush)
-
Log out of AuthenticationService
-
Reinitialize Unity Game Services with a new profile and a new Analytics UserID
-
Reinitialize RemoteConfig with a new CustomUserID
-
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.
public async void Init()
{
var firstUserID = "FirstUser";
//Initialize UnityServices
var options = new InitializationOptions();
options.SetEnvironmentName("development");
options.SetProfile("MyFirstProfile");
options.SetAnalyticsUserId(firstUserID);
if (UnityServices.State == ServicesInitializationState.Initialized && AuthenticationService.Instance.IsSignedIn)
{
AuthenticationService.Instance.SignOut();
}
await UnityServices.InitializeAsync(options);
AuthenticationService.Instance.SwitchProfile("MyFirstProfile");
//End Initialize UnityServices
//Initialize Remote Config
await AuthenticationService.Instance.SignInAnonymouslyAsync();
ConfigManager.FetchCompleted -= ApplyRemoteSettings;
ConfigManager.FetchCompleted += ApplyRemoteSettings;
ConfigManager.SetEnvironmentID("redacted-for-forums");
ConfigManager.SetCustomUserID(firstUserID);
await ConfigManager.FetchConfigsAsync(new userAttributes(), new appAttributes());
//End Initialize Remote Config
//Send First Event
Dictionary<string, object> firstEventParamaters = new Dictionary<string, object>();
firstEventParamaters.Add("uasUserID", AuthenticationService.Instance.PlayerId);
firstEventParamaters.Add("packType", "This Is The First Event");
Events.CustomData("TestCustomUser", firstEventParamaters);
//End Send First Event
Debug.Log("End of Send First Event");
Events.Flush(); //Have tried with and without Events.Flush()
await Task.Delay(1000 * 180 /* 3 min */); //Tried with and without this delay timing padding to simulate normal sending
var secondUserID = "2ndUser";
//Reinitialize UnityServices with a new Profile
var reinitializeOptions = new InitializationOptions();
reinitializeOptions.SetEnvironmentName("development");
reinitializeOptions.SetProfile("MySecondProfile");
reinitializeOptions.SetAnalyticsUserId(secondUserID);
if (UnityServices.State == ServicesInitializationState.Initialized && AuthenticationService.Instance.IsSignedIn)
{
AuthenticationService.Instance.SignOut();
}
await UnityServices.InitializeAsync(reinitializeOptions);
AuthenticationService.Instance.SwitchProfile("MySecondProfile");
//End Reinitialize UnityServices with a new Profile
//Reinitialize Remote Config with new customID
await AuthenticationService.Instance.SignInAnonymouslyAsync();
ConfigManager.FetchCompleted -= ApplyRemoteSettings;
ConfigManager.FetchCompleted += ApplyRemoteSettings;
ConfigManager.SetEnvironmentID("redacted-for-forums");
ConfigManager.SetCustomUserID(secondUserID);
await ConfigManager.FetchConfigsAsync(new userAttributes(), new appAttributes());
//End Reinitialize Remote Config with new customID
//Send Second Event
Dictionary<string, object> secondEventParamaters = new Dictionary<string, object>();
secondEventParamaters.Add("uasUserID", AuthenticationService.Instance.PlayerId);
secondEventParamaters.Add("packType", "Here we find a second event");
Events.CustomData("TestCustomUser", secondEventParamaters);
//End Send Second Event
Debug.Log("End of Send Second Event");
Events.Flush(); //Tried with and without .Flush()
await Task.Delay(1000 * 180 /* 3 min */); //Tried with and without this delay timing padding to simulate normal sending
Debug.Log("End of test process");
}
void ApplyRemoteSettings(ConfigResponse configResponse)
{
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("RemoteConfig not loaded, using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log("RemoteConfig using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
Debug.Log("New RemoteConfig settings loaded from Remote");
break;
default:
Debug.LogWarning($"Unrecognized ConfigOrigin: {configResponse.requestOrigin}");
break;
}
}
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
1 Like
I cannot see the option “SetAnalyticsUserId”…
I`m using “3.0.0-pre.3” now.
and I set like this…
Please see this previous message in this thread https://discussions.unity.com/t/869673/10 , you need
using Unity.Services.Core.Analytics;
but… i cannot find it.
there`s only .Environment being.
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.