Create a custom event
Create custom events to track player actions that are unique to your game, and implement them in your game code.
Read time 2 minutesLast updated 19 hours ago
Unity Analytics comes with standard events that work without the need for additional configuration. However, you can create custom events to record player actions that are unique to your game. These must be created on the Unity Dashboard and then implemented in your game code.
Create a custom event through the Unity Dashboard
- Go to the Event Manager and select Add New > Custom Event.
-
Enter an event name and description.
- The first character of your event name must be a letter.
- The event name must consist only of English alphanumeric and underscore characters (,
a-z,A-Zor0-9)._
-
Select Assign Parameter to add parameters to your event. You can add existing parameters or create new ones here by selecting Assign Parameter > Create New Parameter. A parameter needs a name, description and data type.
- The first character of your parameter name must be a letter.
- The name must consist only of English alphanumeric and underscore characters.
- There is a set of reserved parameter names that cannot be used in custom event definitions (refer to the list of reserved parameter names).
- Parameters are unique within an environment. The recommended best practice is to test your schema and its parameters in a test environment. Use the copy mechanism to propagate event definitions between environments.
- Ensure your event is set to Enabled.
Create a matching Event
class in your game
Event
The Analytics SDK is designed to help you match your game code with your event schemas as defined in the Unity Dashboard. While we provide helper classes for all of the standard events that you might encounter, you must make your own helper classes to support the custom events that are unique to your game. This is done through making sub-classes of the abstract
EventEventmyEventThepublic class MyEvent : Unity.Services.Analytics.Event{ public MyEvent() : base("myEvent") { } public string FabulousString { set { SetParameter("fabulousString", value); } } public int SparklingInt { set { SetParameter("sparklingInt", value); } } public float SpectacularFloat { set { SetParameter("spectacularFloat", value); } } public bool PeculiarBool { set { SetParameter("peculiarBool", value); } }}
EventSetParameter(...)
Once you have created your event schema and helper class and activated the SDK, you can use the
AnalyticsService.Instance.Record(...)