How to Track Same User on WebGL?

Hello,

It seems that on our WebGL build, each time the webpage gets refreshed, it's recorded as a new user. This is in contrast to mobile games where you can track the user because they installed the app. It seems like WebGL analytics should be storing a playerPref or a cookie in the browser in order to track the same user.

Another solution for us would be the ability to assign a player's UID to the analytics session once the player logs into our game. But it seems that analytics doesn't support this very well? Why is it so hard to change the unique identifier of an analytics session during the session? Is there an easy way that I'm missing?

Hi atomikm,

Thanks for reaching out (and apologies for the delay). I will look into the initial concern about always providing a unique identifier, as this is not intended behavior. As for setting the userID, you can absolutely do that using this code:

using Unity.Services.Core.Analytics;
var options = new InitializationOptions();
options.SetAnalyticsUserId(“some-user-id”);

await UnityServices.InitializeAsync(options);

using Unity.Services.Core.Analytics;
var options = new InitializationOptions();
options.SetAnalyticsUserId("some-user-id");
       
await UnityServices.InitializeAsync(options);

This comes from the Custom User ID Support documentation in the Analytics docs. Let me know if that helps!

Best,
Randy

Hello again,

Sorry I did not get around to testing your issue yet. Before I do, could you answer a few questions?

  • Which Browser is your WebGL game being used on when this issue occurs?
  • Are you using an adBlocker, or something of the sort, on the browser?
  • Which version of the Analytics package are you using?

Best,
Randy

Hey Randy! Thanks for reaching out, this is definitely an important issue :slight_smile:

  1. 90% of our users are using Chrome with the rest on Firefox and Brave. The issue definitely occurs on Chrome.
  2. I do use an Adblocker, but I disable it for our game’s webpage.
  3. We’re using Analytics Version 4.2.0 and Analytics Library Version 3.6.12

Hopefully that helps, let me know if you need any more info!

So the reason we can’t do this at the moment is because we have to initialize Unity Services before the player logs in. This is because we have to fetch Remote Configs from Unity Services before the game starts. The player can play the game without logging in. So we need to have the ability to assign a UserId to an analytics session after the player logs in, which will be after Unity Services has been initialized.

Hi atomikm,

Changing/assigning a userID after the player logs in isn't something you can do with the latest Analytics package, however, soon we will release a new version that should include this very behavior, the ability to change the userID after initialization.

Best,
Randy

Hi again @atomikm ,

The latest Unity Analytics SDK 4.4.1 allows you to change the USER_ID after initializing Unity Services using:

UnityServices.ExternalUserId = "TestUserID";

Best,
Randy

1 Like

i need this coin value from unity custom event.How to get it in unity?. i need a script for it.Thanks

Hi @pgescapegames ,

Thanks for reaching out! This appears to be a custom event, so I'm guessing you're also setting that coin value in your custom parameter "Coin"? What exactly are you trying to do?

Best,
Randy

Yes, I set that currency value in a custom parameter and push some values. I will try to get the value of that coin next time I log in. Like a login system. Is it possible?

Hi again @pgescapegames ,

So you'd like a Coin value to persist when logging into your profile, essentially? Is it possible you're looking to use a service like Economy? Unity’s Economy service provides you with an easy way to create, manage and publish an economy system to be used in your game. So if you wanted to have a currency called COIN which tracks the increments and decrements of the total over time, you could do that using Economy, as a simple example. You can read more about all of this in the Introduction to Resources section of the Economy Documentation.

I'm not going anywhere, but thought I'd see what you think after checking out those pieces of documentation.

Best,
Randy