Analytics REST API guide

Use the Analytics REST API to send events without using the SDK on the player's device, for example, secondary events from a game server.

Generating a Unique User ID

A userID is an ID that’s unique to a user. If you’re using Unity Gaming Services or another solution that generates a userID at the start of the user's lifecycle, you should use that userID to send to the Analytics REST API. If you don’t have your own userID in your game, generating a Universally Unique Identifier (UUID) is the recommended way to create one. You’ll need to store the returned value locally on the client and reuse it for all future Collect calls from that specific client. Do not change what you’re using.

REST API endpoints

The API offers two operations: one generates the Unique User ID and the other records all the events triggered from the game.

UUID API endpoint

The REST API offers the following method for generating a random unique userID that can be used for this purpose:

https://collect.analytics.unity3d.com/collect/api/uuid

For example:

Copy
>curl https://collect.analytics.unity3d.com/collect/api/uuid

{"userID":"283ab242-0a37-459e-a5db-62773435b}

When you have an ID, the user can be identified by this value. However, there might be legal restrictions or limitations due to licensing restrictions that prevent storing the apparent userID at third-party. Creating a hash of this ID and using it as a userID for the integration will generally be a workaround to this problem; this prevents having to store the userID again.

Collect API endpoint

If you have Events that can’t be sent through the SDK (for example, from a game server or for a non-Unity game), the Collect REST API records and sends Events directly to Unity.

To record an Event, make a HTTP POST to the Collect API to record an Event. Your POST should be UTF-8 encoded. Set the HTTP request header to “Content-Type: application/json” and use one of the following URL formats:

https://collect.analytics.unity3d.com/collect/api/project/<Unity ProjectID>/<EnvironmentName>

To get the Environment name, go to the project Dashboard > Projects > Project Settings > Environments.

A set of Custom Events can be configured per environment. In the request body, specify a JSON document corresponding to the event type, as described later.

If the status code is 204 No Content, the Event has been successfully received by the server and there’s nothing that the server wants to send back.

If the status code is anything other than 204 No Content, there was an error serving the request. The status code and the message will describe the problem encountered. For example: 400 Bad Request – “Custom Event Code not recognized”.

To verify whether the event has been processed by our service, check the Event Browser to see events coming in from your game.