Hi everyone,
I’m having some trouble with recording a custom event using Unity Analytics, and I’m hoping someone can help me out. I’ve followed the documentation and set up my code to record a custom event called *user_jumped*, but nothing appears on the dashboards in either the production or development environments. Here’s the code I’m using:
using Unity.Services.Analytics;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
using System;
public class GameAnalytics : Singleton<GameAnalytics> {
public enum EnvironmentType {
Development,
Production
}
[SerializeField]
private EnvironmentType _environment = EnvironmentType.Production;
protected override void Awake () {
base.Awake ();
}
async void Start () {
try {
// Specify the environment options
var options = new InitializationOptions();
options.SetEnvironmentName(_environment.ToString().ToLower());
await UnityServices.InitializeAsync(options);
Debug.Log("Analytics initialized successfully.");
} catch (Exception ex) {
Debug.LogError($"Failed to initialize analytics: {ex.Message}");
}
}
void Update () { }
public void TrackUserJumpedEvent (float jumpDistance) {
if (UnityServices.State != ServicesInitializationState.Initialized) {
Debug.LogError("Analytics is not initialized. Event not sent.");
return;
}
try {
CustomEvent e = new CustomEvent("user_jumped");
e.Add("jump_distance", jumpDistance);
AnalyticsService.Instance.RecordEvent(e);
AnalyticsService.Instance.Flush();
Debug.Log("Analytics event 'user_jumped' sent successfully.");
} catch (Exception ex) {
Debug.LogError($"Failed to send analytics event: {ex.Message}");
}
}
}
What’s happening:
- The analytics service initializes without any errors, and I see the debug message “Analytics initialized successfully.”
- When recording the
user_jumpedevent, the debug message “Analytics event ‘user_jumped’ sent successfully.” is logged. - The event does not show up on the analytics dashboards in either production or development environments.
- I’ve verified that the environment names are correctly set.
Am I missing something? Are there additional steps or configurations needed to ensure that custom events are properly recorded and displayed on the dashboards?
Any help or advice would be greatly appreciated!
Thanks!