Procedure:
This article explains how to record custom analytics events in Unity using the new generic CustomEvent class introduced in Analytics SDK version 5.1.0. This class lets you send custom event data without manually creating dictionaries, simplifying event recording in your game code.
Sections:
Prerequisites: Defining your custom event in the Unity Dashboard
Recording a custom event using
CustomEventAdditional resources
Detailed information:
Prerequisites:
Before recording any custom event, ensure that you have defined the event and its parameters in the Unity Analytics Event Manager via the Unity Dashboard.
The event name and parameters must follow the naming and type rules defined by Unity Analytics.
Recording a custom event using the CustomEvent class:
As of version 5.1.0 of the Analytics SDK, you can use the new generic CustomEvent class without needing to create a dictionary manually:
CustomEvent myEvent = new CustomEvent("MyEvent")
{
{ "fabulousString", "woah!" },
{ "peculiarBool", true },
{ "sparklingInt", 1337 },
{ "spectacularFloat", 313.37f }
};
AnalyticsService.Instance.RecordEvent(myEvent);
This code records a custom event named "MyEvent" with several parameters.
Additional resources:
For more examples and use cases, check out the Analytics Samples package available in the Unity Package Manager.
For details on creating and managing custom events in the Dashboard, see the Unity Analytics Create a custom event documentation.