文档

​
​

Development

User Acquisition

Monetization

工业

Analytics

Unity SDK

Client API

Analytics

此页面不支持所选语言。
LiveOps
​
​
Analytics
  • Overview
  • Get started
  • Pricing
  • Concepts
  • Tutorials
    • Create a custom event
    • Record an event
    • Record events with a custom user ID
    • Record transaction events
    • Record ad impression events
    • Copy custom events to another environment
    • Create a custom dashboard
    • Edit a custom dashboard
    • Create a funnel
    • Track user acquisition
    • Create a custom audience
    • Run a query with SQL Data Explorer
    • Query parameter values with SQL Data Explorer
    • Optimize SQL Data Explorer queries
    • Set up Data Access
    • Record an event with the REST API
    • Generate a unique user ID with the REST API
    • Request data deletion with the REST API
    • Debug event reporting
    • SDK 5.0.0 migration
    • Migrate to Unity 6.2 with Analytics SDK 6.1.0
    • Request game data deletion
  • Reference
  • Privacy and consent
  • FAQ
  1. Unity Analytics

Record an event

Record and send events from your game to Analytics to track player behavior and game activity.
阅读时间3 分钟
最后更新于 9 个月前

Whether you are recording a standard event provided by Unity 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 are 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");
注意
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 Analytics SDK are batched and uploaded automatically every 60 seconds.
Once your events have been uploaded, you can view them in the Event Browser.
注意
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.
注意
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.

Unity 6.2 and later with Analytics SDK 6.1 and later

Event

Description

gameStarted
Recorded when consent is granted or during
InitializeAsync()
if consent is already granted.
clientDevice
Recorded when consent is granted or during
InitializeAsync()
if consent is already granted.
newPlayer
Recorded if the user ID has changed. This recording occurs either when consent is newly granted, or during
InitializeAsync()
if consent was already granted at that time.
gameRunning
Recorded every 60 seconds if no other events have been recorded in that time.
gameEnded
Recorded 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.
To learn about the standard event classes, including ones that you must record manually, refer to the list of standard events page.

Unity 6.1 and earlier, or Analytics SDK 6.0 and earlier

Event

Details

gameStarted
Recorded the first time
StartDataCollection()
is called in a session.
clientDevice
Recorded the first time
StartDataCollection()
is called in a session.
newPlayer
Recorded the first time
StartDataCollection()
is ever called for the given user ID.
gameRunning
Recorded every 60 seconds if no other events have been recorded in that time.
gameEnded
Recorded 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.

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

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

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

  • 在本页上
    • Automatic events

      • Unity 6.2 and later with Analytics SDK 6.1 and later

      • Unity 6.1 and earlier, or Analytics SDK 6.0 and earlier


报告此页面的问题