The Analytics API automatically sends events to the Analytics Service under certain circumstances. However, custom events can also be sent using user-defined triggers. These can be configured and implemented entirely in the Editor as well as from script.
Attach an Analytics Tracker component to any GameObject to send a custom event via the Analytics API.
|Event Name||Set a name for the custom event.|
|Trigger||Specify the immediate cause of the event being sent. See notes on Triggers below for more information.|
|Parameters||Set a list of keys/values. Parameter data can be either static, where you specify set strings to send as the parameter data, or it can be arbitrary fields of arbitrary components attached to a provided GameObject. See notes on Parameters below for more information.|
The Trigger specifies the immediate cause of the event being sent.
An event can leverage most standard methods in the MonoBehaviour life cycle, but it can also be triggered from an external source. For example, the External event trigger can be tied (entirely through the Editor) to a UI Button component’s click event:
In this example, a GameObject called MyAnalyticsTracker has an Analytics Tracker component with its Trigger type set to External. This button component can trigger the event by invoking AnalyticsTracker.TriggerEvent in its OnClick event.
Use this field to set a list of keys/values. Parameter data can be either static, where you specify set strings to send as the parameter data, or arbitrary fields of arbitrary components attached to a provided GameObject.
Here, the parameter is marked as Static. In this example, the key is named “name” and the value is named “value”. You can change these to whatever you like. The data sent with the event for this parameter will always be the same.
This image shows a list of parameters registered as event data. The value is set to the boolParameter field of the user-defined class TestAnalyticsDataObject, and attached to a GameObject named ExampleGameObject. The event contains the contents of this field at the time when the event is sent. This could be set to any public field that resolves to a string, number or boolean.