> ## Documentation Index
> Fetch the complete documentation index at: https://docs.playtolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PlaytoliaAnalytics

> Custom event tracking and analytics session state

Enable analytics under **Playtolia → Data & Diagnostics** in Project Settings. **Auto-Track Events** also records key events (login, logout, purchases, friend activity, and profile changes) without calls from your game. Analytics works on Android, iOS, and Windows.

```c# theme={null}
using System.Collections.Generic;
using PlaytoliaSDK.Runtime;

PlaytoliaAnalytics.Track("level_complete", new Dictionary<string, object>
{
    { "level", 12 },
    { "stars", 3 },
});
```

### Methods

| Method | Parameters | Returns | Notes |
| - | - | - | - |
| `Track(eventName, properties)` | `string`, `Dictionary<string, object>` (optional) | `void` | Records a custom event. The SDK sends the properties as JSON. |
| `Flush()` | (none) | `void` | Sends all queued events now. |
| `GetDeviceId()` | (none) | `string?` | Returns the stable device ID, or `null` if analytics is not initialized. |
| `GetSessionId()` | (none) | `string?` | Returns the current session ID, or `null` if analytics is not initialized. |
| `GetState()` | (none) | `AnalyticsState` | Returns the current analytics state. |
| `AddListener(listener)` | `Action` | `void` | Calls the listener on each change of the state. |
| `RemoveListener(listener)` | `Action` | `void` | Deletes the listener. |

### AnalyticsState

| Field | Type | Notes |
| - | - | - |
| `Initialized` | `bool` | `true` after analytics starts |
| `UserId` | `string` | The signed-in player, or `null` |
| `DeviceId` | `string` | |
| `SessionId` | `string` | |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.