Events

The Events component lets you add extra details to your analytics using key-value pairs tied to specific Actions.

Event Types

  1. On Action Perform

    • Records when a specific Action is performed.

  2. On Action Undo

    • Records when a specific Action is undone.

  3. On Collision

    • Records when a specified collision happens between a prefab and a collider. You can set it up to only record collisions under a specific Action and define the collision type.

  4. On Interaction

    • Records when a specified interaction between an interactor and an interactable happens. You can set it up to record these interactions under a specific Action.

  5. On Session Start

    • Records when the session starts.

  6. On Session End

    • Records when the session ends.

  7. Custom Event

    • Lets you create your own event using code. For example, the OnTranslationEvent class records the position of a target every time it moves.

    public class OnTranslationEvent : CustomEventTypeDefinition
    {
        public GameObject Target { get; set; } = null;
    
        private GameObject spawnedPrefab = null;
    
        protected override void OnCreate()
        {
            Target = Resources.Load<GameObject>("TargetCube");
    
            if (Target != null)
            {
                spawnedPrefab = AnalyticsUtilities.Spawn(Target);
    
                spawnedPrefab.AttachCallback(AnalyticsUtilities.Hook.OnTranslation, (other, actions) =>
                {
                    Data.RuntimePayload["PositionX"] = spawnedPrefab.transform.position.x.ToString();
                    Data.RuntimePayload["PositionY"] = spawnedPrefab.transform.position.y.ToString();
                    Data.RuntimePayload["PositionZ"] = spawnedPrefab.transform.position.z.ToString();
    
                    TriggerEvent();
                });
            }
        }
    }
    

How to Setup Events

For this tutorial, let’s set up 3 events to see how the pipeline works. We will create an On Action Perform, a Collision Event and a Session Ended event. Also, we will attach a custom recording to the Action Perform event.

  1. In the MAGES Panel, go to Analytics Editor > Events tab.

    ../../../_images/events_tab.png
  2. Select Action Performed in the Event type dropdown, then click Add New Event. Name it, select the Action and click Add to apply.

    ../../../_images/action_performed_event_setup.png
  3. Repeat for On Collision, setting the Collision type to enter and specifying the prefab and collider, then click Add to apply.

    ../../../_images/on_collision_event_setup.png
  4. Repeat for Session Ended.

    You can add custom key-value pairs to Events by creating a script that implements the IEventDefinition interface.

    public class GetHeartRate : IEventDefinition
    {
        /// <inheritdoc cref="IEventDefinition.Definition"/>
        public object Definition()
        {
            return 90;
        }
    }
    

    Add this script to the list.

    ../../../_images/ievent_definition_heart_rate.png

Event Preview

To view recorded Events, check the Session Overview UI generated at the operation’s conclusion. Click on the Events tab for a list of Events and their information.

../../../_images/operation_end_events.png