As an alternative to using the AnalyticsTracker component, you can send custom events directly via script by calling Analytics.CustomEvent. See the following example:
// Reference the Unity Analytics namespace
using UnityEngine.Analytics;
// Use this call for wherever a player triggers a custom event
Analytics.CustomEvent(string customEventName,
IDictionary<string, object> eventData);
Analytics.CustomEvent Input Parameters | ||
---|---|---|
Name | Type | Description |
customEventName | string | Name of custom event. Name cannot include the prefix “unity.” — This is a reserved keyword. |
eventData | dictionary | Additional parameters sent to Unity Analytics at the time the custom event was triggered. eventData key cannot include the prefix “unity.” — This is a reserved keyword. |
关于自定义事件的一些注意事项:
在以下示例中,我们希望了解游戏结束时用户在库存中拥有的商品。
// Reference the Collections Generic namespace
using System.Collections.Generic;
int totalPotions = 5;
int totalCoins = 100;
string weaponID = "Weapon_102";
Analytics.CustomEvent("gameOver", new Dictionary<string, object>
{
{ "potions", totalPotions },
{ "coins", totalCoins },
{ "activeWeapon", weaponID }
});
To send test Custom Event data to our servers and validate your integration, trigger your Custom Event during Editor Play mode.
If integration is successful, your test data will display in the table below.