Record an event

Whether you are recording a standard event provided by UGS Analytics or a custom event that you have created especially for your game, the way to send data to Analytics is the same. Events must conform to a schema that exists on the dashboard or else they will be rejected as invalid. You can view your configured events, and create new custom events, in the Event Manager.

To make it easy to record events that are correctly structured, the SDK provides helper classes for standard events and a base class you can extend for custom events.

Events are recorded by building an instance of an Event class and passing it into the AnalyticsService.Instance.RecordEvent(...) method as in this example:

MyEvent myEvent = new MyEvent
{
	FabulousString = "hello there",
	SparklingInt = 1337,
	SpectacularFloat = 0.451f,
	PeculiarBool = true
};

AnalyticsService.Instance.RecordEvent(myEvent);

You can also record a custom event that has no parameters by using its name alone:

AnalyticsService.Instance.RecordEvent("myEvent");

Note: these API methods changed in version 5.1.0 of the SDK. Please ensure you have the latest version of the SDK installed!

Events recorded by the UGS Analytics SDK are batched and uploaded automatically every 60 seconds.

Once your events have been uploaded, you can view them in the Event Browser.

Note: The Analytics backend rejects events as invalid under the following scenarios:

  • The timestamp the event was collected on the user's device is greater than 30 days earlier than the timestamp of when the event is ingested into the backend service.
  • The timestamp the event was collected on the user's device is greater than 24 hours ahead of the timestamp of when the event is ingested into the backend service.

Note: If you are using the REST API instead of the SDK, you are responsible for populating, recording and uploading events. For more information, see the REST API page.

Automatic events

The SDK automatically populates every event with common parameters, such as userID, sessionID, eventTimestamp, eventUUID and platform, so you don't need to worry about these.

The SDK also automatically records a number of standard events for you.

EventDetails
gameStartedRecorded the first time StartDataCollection() is called in a session.
clientDeviceRecorded the first time StartDataCollection() is called in a session.
newPlayerRecorded the first time StartDataCollection() is ever called for the given user ID.
gameRunningRecorded every 60 seconds if no other events have been recorded in that time.
gameEndedRecorded when the game is closed. Note that if Unity is not allowed to shut down gracefully by the operating system, this may not occur, or may be cached to disk for upload at the start of the next session.

For more information about the standard event classes, including ones that you must record manually, see the list of standard events page.