文档

​
​

Development

User Acquisition

Monetization

工业

Analytics API

v1

受支持
​

Analytics API

v1

受支持
​

此页面不支持所选语言。
Unity Services Web APIs
​
​
Analytics
  • Overview
  • Useful Links
mdx:openapi:endpoints
  • Analytics

Analytics

Overview

The Unity Analytics Collect API allows you to submit events related to your game for analysis.
Unity offers support for Analytics within the Unity Editor version 2019.4 and above. This is done through our SDK package (see the Useful Links section below). Using the SDK provides you with some benefits like automatic batching of events and automatic retries of event submissions which fail due to network issues. If you use the SDK to send events, you do not need to use this API.
In some cases you may not be able to use the SDK, for example:
  • Sending events from a game server
  • Sending events from a non-Unity game
In these cases you can use this API.
You can send either Standard Events or Custom Events, which are configured per environment. To see a list of Event types (Standard or Custom) or to define new Custom event types, you can use the Event Manager.
In the request body, specify a JSON document corresponding to the event type.
To verify whether the event has been processed by our service, check the Event Browser to see events coming in from your game.
For requests originating in China, to comply with China's Personal Information Protection Law (PIPL) you are required to set headers to indicate whether the user has consented to have their personal information processed. Requests made from China which do not have these headers set will result in no data being recorded by Unity Analytics.

Useful Links

  • SDK Documentation
  • Event Manager Documentation
  • Event Browser Documentation
  • PIPL Consent Documentation
Download OpenAPI specification:

Submit event(s)


You may submit either a single event or a list of events to this endpoint. When possible, sending a list of events is preferable due to efficiencies in connection pooling. Keep the POST length below 5MB; anything above might be rejected.

Path parameters for "{title}"

projectId

string
必填
ID for Unity project

environmentName

string
必填
Name of an environment. To get the Environment name, go to the project Dashboard > Projects > Project Settings > Environments.

Header parameters for "{title}"

PIPL_CONSENT

string
The presence of this header will indicate the player has granted consent to data collection. Players who do not consent should not have this header set on requests. The value of the header does not matter. This header is only required if the request originates in China.

PIPL_EXPORT

string
The presence of this header will indicate the player has granted consent to their data being sent out of China for processing. Players who do not consent should not have this header set on requests. The value of the header does not matter. This header is only required if the request originates in China.

Request body for "{title}"

Media Type:
application/json

eventName

string
example: gameStarted
The name of the event.

userID

string
必填
example: ABCD1-4321a879b185fcb9c6ca27abc5387e914
A unique string that identifies the player and is consistent across their subsequent play sessions.

unityInstallationID

string
example: Optional-Installation-ID
The installation ID is provided by the Unity package and used internally by Unity services. It can be safely omitted. The primary use case is identifying where multiple distinct users share a device.

unityPlayerID

string
example: Optional-Authenticated-Player-ID
The authenticated playerID, provided by the Unity authentication service. This can be useful to link analytics data to player accounts if you're using other Unity services (such as Cloud Save). If you're not using the Unity authentication service, this field should be omitted.

sessionID

string
example: 4879bf37-8566-46ce-9f3b-bd18d6ac614e
A unique string value that’s persisted for the duration of each player gameplay session and regenerated with each new gameplay session. The sessionID should be sent with every event the player triggers in their session. There might be occasions when you want to send events containing valuable player information outside a player session and don’t have access to a sessionID. These are called GHOST events and you should omit the sessionID parameter and value on these events to ensure that they're not included in any player session calculations.

eventUUID

string
必填
example: 374cc674-9785-4772-8cca-d7cdf517a590
Adding eventUUID to an event will prevent the event being inserted twice within a 24 hour period. This may happen when e.g. a network time-out occurs, even if the event has already been processed by Unity Analytics. Should be unique per event.

eventTimestamp

string
example: 2022-12-30 16:55:00.321 -08:00
If eventTimestamp is missing, the server will infer the timestamp based on the time the event was received. The date format should be as follows:
yyyy-MM-dd HH:mm:ss.SSS ±[hh]:[mm]
where
±[hh]:[mm]
can be included to indicate offset from UTC.

eventVersion

integer
example: 1
The version of the standard event only.

eventParams

object
example: {"platform":"WEB","param1":"stringParam","param2":true,"param3":123}
A JSON object containing information about the event that conforms to the event schema (Event Parameters).

eventList

array[object]
No description

eventName

string
example: gameStarted
The name of the event.

userID

string
必填
example: ABCD1-4321a879b185fcb9c6ca27abc5387e914
A unique string that identifies the player and is consistent across their subsequent play sessions.

unityInstallationID

string
example: Optional-Installation-ID
The installation ID is provided by the Unity package and used internally by Unity services. It can be safely omitted. The primary use case is identifying where multiple distinct users share a device.

unityPlayerID

string
example: Optional-Authenticated-Player-ID
The authenticated playerID, provided by the Unity authentication service. This can be useful to link analytics data to player accounts if you're using other Unity services (such as Cloud Save). If you're not using the Unity authentication service, this field should be omitted.

sessionID

string
example: 4879bf37-8566-46ce-9f3b-bd18d6ac614e
A unique string value that’s persisted for the duration of each player gameplay session and regenerated with each new gameplay session. The sessionID should be sent with every event the player triggers in their session. There might be occasions when you want to send events containing valuable player information outside a player session and don’t have access to a sessionID. These are called GHOST events and you should omit the sessionID parameter and value on these events to ensure that they're not included in any player session calculations.

eventUUID

string
必填
example: 374cc674-9785-4772-8cca-d7cdf517a590
Adding eventUUID to an event will prevent the event being inserted twice within a 24 hour period. This may happen when e.g. a network time-out occurs, even if the event has already been processed by Unity Analytics. Should be unique per event.

eventTimestamp

string
example: 2022-12-30 16:55:00.321 -08:00
If eventTimestamp is missing, the server will infer the timestamp based on the time the event was received. The date format should be as follows:
yyyy-MM-dd HH:mm:ss.SSS ±[hh]:[mm]
where
±[hh]:[mm]
can be included to indicate offset from UTC.

eventVersion

integer
example: 1
The version of the standard event only.

eventParams

object
example: {"platform":"WEB","param1":"stringParam","param2":true,"param3":123}
A JSON object containing information about the event that conforms to the event schema (Event Parameters).

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X POST \ -H "PIPL_CONSENT: <PIPL_CONSENT>" \ -H "PIPL_EXPORT: <PIPL_EXPORT>" \ -H "Content-Type: application/json" \ -d '{ "eventName": "gameStarted", "userID": "ABCD1-4321a879b185fcb9c6ca27abc5387e914", "unityInstallationID": "Optional-Installation-ID", "unityPlayerID": "Optional-Authenticated-Player-ID", "sessionID": "4879bf37-8566-46ce-9f3b-bd18d6ac614e", "eventUUID": "374cc674-9785-4772-8cca-d7cdf517a590", "eventTimestamp": "2022-12-30 16:55:00.321 -08:00", "eventVersion": 1, "eventParams": { "platform": "WEB", "param1": "stringParam", "param2": true, "param3": 123 }}' \ "https://collect.analytics.unity3d.com/api/analytics/collect/v1/projects/{projectId}/environments/{environmentName}"

Response example

Generate a random unique userID


Generates a random unique userID. Subsequent requests will return a different value.
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.

HTTP response status codes for "{title}":

Code samples for "{title}":

Request example

curl -X GET \ "https://collect.analytics.unity3d.com/api/analytics/collect/v1/uuid"

Response example

{ "userID": "0a71d2c8-fb93-4b8d-8d4d-8cbbd2425dc9"}

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。