I have setup 3 environments (development, production and beta_testing). I encapsulated the tracking code in a GameAnalytics class:
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Services.Analytics;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
public class GameAnalytics : Singleton<GameAnalytics> {
private async Task Start() // Changed to async Task
{
try
{
var options = new InitializationOptions();
options.SetEnvironmentName("development");
await UnityServices.InitializeAsync(options);
// If you want a custom user id
// UnityServices.ExternalUserId = "some-user-id";
Debug.Log("Analytics service initialised");
}
catch (System.Exception ex)
{
Debug.LogError($"Failed to initialize UnityServices: {ex.Message}");
}
}
public void TrackLevelStarted(int userLevel)
{
if (AnalyticsService.Instance == null)
{
Debug.LogError("AnalyticsService is not initialized.");
return;
}
var parameters = new Dictionary<string, object>
{
{ "userLevel", userLevel }
};
AnalyticsService.Instance.CustomData("levelStarted", parameters);
Debug.Log("Sent event levelStarted:" + userLevel);
}
}
After running the game, triggering the event a couple of times and waiting for 24h (48h now) I noticed the Analytics dashboard is not showing anything (both in the valid and invalid events section). I’m using the custom levelStarted event defined in the Event Manager section.
UPDATE: some events are being sent but to the “Production” envinronment, not sure why.
Looks like the
options.SetEnvironmentName("development");
is not working
Also, no error was reported in the logs, what could be the problem?