---
title: "Record user actions with Analytics events"
content_type: tutorial
url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events?language=en"
language: en
container_type: course
container_title: "Unity Analytics"
container_url: "https://learn.unity.com/course/unity-analytics.md?language=en&version=6.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/record-user-actions-with-analytics-events.md?language=en&version=6.3"
previous_title: "Get started with Unity Analytics"
previous_url: "https://learn.unity.com/course/unity-analytics/tutorial/get-started-with-unity-analytics?language=en&version=6.3"
previous_markdown_url: "https://learn.unity.com/course/unity-analytics/tutorial/get-started-with-unity-analytics.md?language=en&version=6.3"
next_title: "Create and interpret basic Analytics reports"
next_url: "https://learn.unity.com/course/unity-analytics/tutorial/create-and-interpret-basic-analytics-reports?language=en&version=6.3"
next_markdown_url: "https://learn.unity.com/course/unity-analytics/tutorial/create-and-interpret-basic-analytics-reports.md?language=en&version=6.3"
difficulty: beginner
duration_minutes: 30
unity_version:
  - "6.3"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2021.3"
  - name: "2021.2"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2021.2"
  - name: "2021.1"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2021.1"
  - name: "2020.3"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2020.3"
  - name: "2020.2"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2020.2"
  - name: "2020.1"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2020.1"
  - name: "2019.4"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=2019.4"
  - name: "6.0"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=6.0"
  - name: "6.3"
    url: "https://learn.unity.com/course/unity-analytics/tutorial/record-user-actions-with-analytics-events.md?language=en&version=6.3"
last_updated: "2026-08-04T14:23:36.000Z"
---

# Record user actions with Analytics events

Use standard and custom events to track user actions and analyze their data in the Unity Dashboard.

In this tutorial, you’ll learn how to use standard and custom events to record user actions and view the data of those actions on the Unity Dashboard.

## 1. Overview

The Analytics package collects data about **events**, which are notifications triggered by user actions within your games. [**Standard events**](https://docs.unity.com/ugs/en-us/manual/analytics/manual/standard-events), including launching the game or watching an ad, are generated automatically by the Analytics package. [**Custom events**](https://docs.unity.com/ugs/en-us/manual/analytics/manual/custom-event), such as the player completing a level, must be implemented in code. Custom events are great for answering specific questions about your game and seeing how a design decision plays out.

**Important**: You must define custom events and their parameters before sending them from your game because Analytics validates every event as it’s received. Any events that don’t meet the definition in your Event Manager will be rejected, which ensures that your dataset isn’t polluted with rogue events.

In this tutorial, you’ll prepare a simple scene so you can start sending events, and you’ll configure your own custom event.

## 2. Initialize the Analytics SDK

The Analytics software development kit (SDK) needs to be initialized before your app will send any events to the Dashboard.

To add a script to initialize the Analytics SDK when your scene loads, follow these instructions :

**1.** Open the project you previously linked to the Analytics Dashboard.

**2.** Create a new scene or use an existing one.

**3.** Right-click in the **Hierarchy** window and select **Create Empty** to create an empty GameObject that will act as a container for your analytics script.

**4.** Rename the GameObject “UGS_Analytics”.

**5.** Create a new script and add it to the **UGS_Analytics** GameObject.

**6.** Open the script and replace the contents with the following lines of code:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Services.Analytics;
using Unity.Services.Core;
using Unity.Services.Core.Analytics;
using UnityEngine.UnityConsent;




public class UGS_Analytics : MonoBehaviour
{
    async void Start()
    {
            await UnityServices.InitializeAsync();
            GiveConsent(); //Get user consent according to various legislations
    }


    public void GiveConsent()
    {
        // Call if consent has been given by the user
        EndUserConsent.SetConsentState(new ConsentState
        {
             AnalyticsIntent = ConsentStatus.Granted,
        });
        Debug.Log($"Consent has been provided. The SDK is now collecting data!");
    }


}
```

This script will use an asynchronous task to attempt to initialize the Analytics SDK and wait for a response.

**Important**: The example in the code above is only meant to be used to provide consent and test sending a custom event, quickly. You might need to seek player consent before recording Analytics events. The Analytics SDK documentation contains more information on [Data Privacy and Consent](https://docs.unity.com/en-us/analytics/privacy-and-consent/manage-data-privacy).

You’re now ready to run the game and send your first Analytics events.

For more information on using Analytics in code, check out the [Analytics documentation](https://docs.unity.com/en-us/analytics) and [Unity Gaming Services Sample Project](https://github.com/Unity-Technologies/com.unity.services.samples.use-cases).

## 3. Enable Debug event reporting

By default, the Analytics SDK doesn’t log information about Analytics Events in the Editor’s **Console** window, to ensure that the SDK runs as efficiently as possible. However, you might want to enable logging for extra visibility while you experiment.

To view the debug messages for every event sent in the **Console** window, follow these instructions:

**1.** In the Unity Editor, from the main menu, select **Edit** > **Project Settings**.

**2.** In the **Project Settings** window, select the **Player** section.

**3.** In the **Player** section, use the foldout (triangle) to expand the **Other Settings** section.

**4.** In the **Script Compilation** section, select **Scripting Define Symbols**.

**5.** Select the **Add to the list** (**+**) button.

6**.** Add the keyword “UNITY_ANALYTICS_EVENT_LOGS”**.**

**7.** Select the **Apply** button.

![Define debug Symbols](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%220b26fa4203c2%22%5D.body%5B_key==%22df67d72c229b%22%5D.image/DebugSymbol_U6_20260210_122050.png)

**Note**: It’s advisable to remove logging before you build your app for release.

## 4. Send a standard Analytics event

Some[ standard events](https://docs.unity3d.com/Manual/UnityAnalyticsStandardEvents.html) like **gameStarted** and **clientDevice** are automatically sent just by installing and initializing the SDK then running your game. Even though your app doesn’t do anything yet, you can generate these events.

To send a standard Analytics event, follow this instruction:

**1.** In the Unity Editor, enter Play mode.

Since you have enabled debugging in the previous step, you’ll see some log messages in the **Console** window.

![Unity Editor console log showing standard events recorded.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2230d8b70c05dc%22%5D.body%5B_key==%22e22c561e6574%22%5D.image/image21_20260210_122244.png)

Standard events provide information to help you to determine the number of players in your game, session counts, duration, retention, demographics, and device information. For a complete list of standard events, check out the [Events list](https://docs.unity.com/ugs/en-us/manual/analytics/manual/standard-events) in the Unity Manual.

## 5. Validate your events

Validating your events confirms that they’re being sent correctly from your project and received by Unity Analytics before you rely on them for reporting or decision-making. To validate your events and see how these events appear in Analytics, follow these instructions:**1.** Return to the Unity Dashboard and select your project.

**1.** Select **Products** > **Analytics**, then select **Launch**.

**2.** In the Analytics view, select **Event Browser**.

**Note**: It can take up to 15 minutes before events appear in the Event Browser.

If your events don't appear here, make sure that you have consented to collecting analytics for the device you’re using.

![Event browser with standard events listed.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2216c53a82f581%22%5D.body%5B_key==%2273966726d492%22%5D.image/Event_Browser_U6_20260210_122753.png)

The **Event Browser** provides a quick way to check that your events are recorded and passing validation. If for any reason your events fail validation, you’ll be able to see the precise reasons on the **Invalid Events** tab. You’ll learn more about debugging and handling invalid events in the next tutorial.

For more information about the Event Browser, check out the [Event Browser](https://docs.unity.com/analytics/EventBrowser.html) page of the Unity Manual.

## 6. Create a custom event

While standard events provide you with some important basic information, we recommend using custom events to further understand how players experience your game.

**Custom events** record specific player actions that you identify in your game. A custom event should describe a meaningful player action in the game and reveal details of the action and player state at that time.

In the following steps, you’ll create a custom event named **levelCompleted**. When a player completes a certain level of your game, this event will capture their progress.

To create a custom event, follow these instructions:

**1.** Go to the [Unity Dashboard](https://cloud.unity.com/), then select **Analytics** > **Event Manager**.

**2.** Select **Add New** > **Custom Event**.

![Event Manager, showing menu to add a new custom event.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2206877014cff7%22%5D.body%5B_key==%227740845f0a93%22%5D.image/Event_Manager_Add_Event_U6_20260210_123019.png)

**3.** Name the custom event “levelCompleted”.

**4.** Enter “The levelCompleted event is triggered if a player successfully completed a level” in the **Event** **description** box.

**5.** Enable **Enable event (optional)**.

![The Add Custom Event window with the levelCompleted Event name and Event description field filled in.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2206877014cff7%22%5D.body%5B_key==%22d626ea7709cd%22%5D.image/Add_Custom_Event_U6_20260210_123230.png)

**6.** Select the **Confirm** button.

You’ve successfully created the **levelCompleted** custom event, which defines a clear, meaningful player action and establishes the foundation for tracking player progress in Analytics.

## 7. Create a custom parameter

**Parameters** are attached to events to reveal details of the action and player state at that time the event occurs.

Next, you’ll add the **levelName** parameter to the **levelCompleted** event to record which level is completed. From that information, you can see if there are particular levels that users are struggling with.

You can also create your own parameters in this **levelCompleted** event to provide more context about the player’s state at that time, such as **timeOnLevel**, **coinBalance**, **powerLevel**, **levelDuration**, and **bulletsFired**.

**Tip**: It’s better to record occasional, richly detailed, and meaningful events than a stream of sparse events.

To add a **levelName** parameter to the **levelCompleted** event, follow these instructions:

**1.** In the Event Manager, select the **levelCompleted** event.

**2.** Select the **Assign Parameter** button.

**3.** Select the **Parameter** box, select **Add New Parameter**, name it “levelName”, and add “This parameter identifies which level was completed, allowing you to analyze player progression and difficulty across levels” in the **Parameter description** box..

**4.** Open the **Parameter type** dropdown and select **String**.

**Note**: **levelName** is stored as a **String** because level identifiers are typically text-based (for example, "Level_1" or "DungeonBoss"), rather than numeric values.

**5.** Select the **Create** button.

![The Add Custom Parameter window with details filled in.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%221545c2585c0d%22%5D.body%5B_key==%221348ba6e8520%22%5D.image/Add_Custom_Parameter_Details_U6_20260210_123314.png)

**Important**: You can’t change a parameter’s data type once it has started to receive data. Be sure to choose the parameter type most appropriate to the data you are sending. Parameters may have String, Integer, Float, or Boolean data types.

**Note**: You can [reach out to our support team](https://support.unity.com/hc/en-us/requests/new?ticket_form_id=360001936712&serviceName=analytics) to request a change to the parameter data type.

## 8. Assign a custom parameter to a custom event

You **must** assign the parameter to a custom event so that the event will pass validation.

To assign your custom parameter to your custom event, follow these instructions:

**1.** While still viewing the **levelCompleted** custom event schema from the previous steps, select **Assign Parameter** and locate the newly created **levelName** parameter in the dropdown menu.

**2.** Select **levelName**.

![Assign Parameter list showing the levelName parameter checkbox enabled.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2287b0e46e7a36%22%5D.body%5B_key==%2258c5f2dc566f%22%5D.image/image3_20260408_202424.png)

**3.** Select **Assign** to finalize the Custom Parameter assignment.

![The Add Custom Event  view of the Dashboard.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2287b0e46e7a36%22%5D.body%5B_key==%222ed9a2eaea6e%22%5D.image/image2_20260408_202439.png)

Once you’ve assigned your parameter, your event Schema will open. It will now include your custom parameter in the **eventParams** list.

![Event Schema for level.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%2287b0e46e7a36%22%5D.body%5B_key==%22f0757edb9db0%22%5D.image/image1_20260408_202450.png)

**Note**: Parameter creation and assignment can alternatively be completed within the **Event** **Creation** menu.

## 9. Send a custom event

To start sending in the newly created custom event with its respective parameters, you must update the script added to the **UGS_Analytics** GameObject.

To demonstrate the **levelCompleted** event with the **levelName** parameter, you’ll need to update your script to call the custom event when you load the scene. For now, a random level will be registered on each load to mimic the user playing different levels.

To update and test the script, follow these instructions:

**1.** Open the script attached to the **UGS_Analytics** GameObject.

**2.** Update the script to match the following script:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Services.Analytics;
using Unity.Services.Core;
using Unity.Services.Core.Analytics;
using UnityEngine.UnityConsent;


public class UGS_Analytics : MonoBehaviour
{
    async void Start()
    {
            await UnityServices.InitializeAsync();
            GiveConsent(); //Get user consent according to various legislations
            LevelCompletedCustomEvent();
    }


    private void LevelCompletedCustomEvent()
    {
        int currentLevel = Random.Range(1, 4); //Gets a random number from 1-3


        //Define Custom Parameters
        CustomEvent myEvent = new CustomEvent("levelCompleted")
        	{
            	{ "levelName", "level" + currentLevel.ToString()}
        	};


        //The ‘levelCompleted’ event will get cached locally
        //and sent during the next scheduled upload, within 1 minute
        AnalyticsService.Instance.RecordEvent(myEvent);


        // You can call Events.Flush() to send the event immediately
        AnalyticsService.Instance.Flush();
    }


    public void GiveConsent()
    {
        // Call if consent has been given by the user
        EndUserConsent.SetConsentState(new ConsentState
        {
             AnalyticsIntent = ConsentStatus.Granted,
        });
        Debug.Log($"Consent has been provided. The SDK is now collecting data!");
    }


}
```

**3.** In the Unity Editor, enter Play mode.

**4.** Observe the **Console** window logs and see your events uploaded to the servers.

![Console logs for levelCompleted.](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%22b0e0cd0d4bda%22%5D.body%5B_key==%229582b6d92a54%22%5D.image/image20_20260210_123631.png)

**Note:** A “Dispatcher is already flushing” warning message may appear; however, for the purpose of this tutorial that’s okay. Remove the **AnalyticsService.Instance.Flush();** line if the events are being recorded and uploaded appropriately.

**5.** On the Dashboard, go to the **Event browser** to see those events listed.

![Event Schema for levelCompleted](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/a32d4400-8838-5e2b-89ab-b355476d7f86/versions%5B_key==%220ade849a133c%22%5D.sections%5B_key==%22b0e0cd0d4bda%22%5D.body%5B_key==%22f630e410ef75%22%5D.image/Event_Browser_Custom_U6_20260210_123728.png)

**6.** Expand the event by selecting the **\<>** button and see the value passed for the **levelName** parameter.

For more information about recording custom events, check out the [Create Custom Events](https://docs.unity.com/en-us/analytics/events/custom-event) page and [The CustomEvent Class](https://docs.unity.com/ugs/en-us/manual/analytics/manual/customevent-class) page of the Unity Manual.

## 10. Next steps

You’ve created your own custom event that now appears on your Unity Dashboard. Next, you’ll learn more about how to access, manage, and visualize this data on the Unity Dashboard and set up your own data reports.
