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

# Unreal SDK

> Track sessions, launches, game events, and errors from an Unreal Engine 5 game, in C++ or Blueprint.

The Unreal SDK is an Unreal Engine 5 plugin in C++. It uses only engine modules (HTTP and Json). It is built and tested on macOS with Unreal Engine 5.8. The code for Windows, Linux, Android, and iOS is written, but those builds are not tested yet. It sends [app events](https://docs.manalens.dev/sdks/app-events.md) with your [Publishable key](https://docs.manalens.dev/api/authentication.md#publishable-key), the same events as the [Unity SDK](https://docs.manalens.dev/sdks/unity.md) and the [Godot SDK](https://docs.manalens.dev/sdks/godot.md).

## Installation

> [!NOTE]
>
> The source is public on [GitHub](https://github.com/manalens/manalens-unreal) (MIT). The plugin is not on Fab yet.

1. Download the [latest release](https://github.com/manalens/manalens-unreal/releases/latest). Copy its `Manalens` folder into the `Plugins/` folder of your project. Create `Plugins/` if it does not exist.
2. Open the project. The editor builds the plugin. A Blueprint-only project needs one C++ class first: use **Tools > New C++ Class**, then open the project again.
3. Open **Edit > Plugins** and check that **Manalens** is enabled.
4. Copy the **Publishable key** (`mana_pk_`) from **Settings**. The plugin refuses a Secret key or an API key.

## Settings

Open **Edit > Project Settings > Plugins > Manalens** and set the Publishable key and the endpoint. The engine starts the SDK with the game instance, so there is no init call. At start, the SDK sends `session_start` and `game_open` with `is_first_open` and `first_open_at`.

The settings are saved in `Config/DefaultGame.ini`:

```ini theme={null}
[/Script/Manalens.ManalensSettings]
PublishableKey=YOUR_PUBLISHABLE_KEY
Endpoint=https://events.manalens.dev
Build=571
Storefront=Steam
```

| Setting | Default | Meaning |
| - | - | - |
| Publishable Key | required | The project's Publishable key. |
| Endpoint | required | The Manalens ingest URL, without `/v0/events`. |
| Enabled | `true` | `false`: the SDK sends nothing, writes no files, and keeps no ID. |
| Enabled In Editor | `true` | Send events from Play in Editor. See [Editor runs](#editor-runs). |
| App Version | Project Version | Up to 32 characters, for example `1.4.0`. Empty: **Project Settings > Description > Project Version**. |
| Build | none | Up to 64 characters, for example a build number. |
| Editor Build | `dev` | The build label of Play in Editor runs. Empty: use **Build**. See [Editor runs](#editor-runs). |
| Storefront | not set | Steam, itch.io, Epic Games Store, GOG, App Store, Google Play, or Other. |
| Consent Required | `false` | No events and no stored ID until **Set Consent** (`true`). |
| Capture Log Errors | `true` | Send `Error` lines of the engine log as `error` events. |
| Capture Log Warnings | `false` | Also send `Warning` lines. |
| Max Auto Errors Per Session | `50` | Most captured log errors in one session. |
| Flush Interval Seconds | `10` | Seconds between sends. |
| Flush At | `20` | Send when this many events are queued. Also the batch size (at most 50). |
| Max Queue | `1000` | Most events kept on disk. The oldest are dropped first. |
| Quit Timeout Seconds | `2` | Longest wait on quit to send the last events. |
| Debug | `false` | Log each queued event and each failed send to `LogManalens`. |

If the key or the endpoint is wrong, the SDK logs why to `LogManalens` and stays off.

## Track events

In Blueprint, use the **Get ManalensSubsystem** node, then **Track**. Track takes the event name and three maps: text, numbers, and true or false values. Leave a map empty when you do not need it.

In C++, get the subsystem from the game instance:

```cpp theme={null}
#include "ManalensSubsystem.h"

if (UManalensSubsystem* Manalens = GetGameInstance()->GetSubsystem<UManalensSubsystem>())
{
    Manalens->Track(TEXT("level_complete"), { { TEXT("mode"), TEXT("story") } }, { { TEXT("level"), 3 }, { TEXT("score"), 1200 } }, {});
}
```

Add `"Manalens"` to `PublicDependencyModuleNames` in the `Build.cs` file of your game module. To send a JSON object, use `TrackJson()`. Values are strings, numbers, booleans, or null. Other values are dropped with a warning. Use the [event conventions](https://docs.manalens.dev/sdks/app-events.md#event-conventions).

From any object with a world, `UManalensSubsystem::Get(this)` returns the subsystem. Call the SDK on the game thread. A Track or Track Error call from another thread runs on the game thread later.

## Identify players

On sign-in, call **Identify** with your user ID to join this install's history to the player. On sign out, call **Reset**.

```cpp theme={null}
Manalens->Identify(TEXT("player_42"), { { TEXT("plan"), TEXT("supporter") } }, {}, {});
Manalens->Reset(); // on sign out
```

To join the player on your website without sign-in, use [Link URL](#open-your-website-from-the-game). See [identify users](https://docs.manalens.dev/guides/identify-users.md).

## Open your website from the game

Use **Link URL** when the game opens your website. The website then joins this player, without Identify:

```cpp theme={null}
FPlatformProcess::LaunchURL(*Manalens->LinkUrl(TEXT("https://example.com/wiki")), nullptr, nullptr);
```

It adds `mana_hid=<anonymous ID>.<unix seconds>` to the URL. The website needs the [Web SDK](https://docs.manalens.dev/sdks/web.md#players-who-come-from-your-game). The link works for 10 minutes. Before consent, the URL is unchanged.

## Error tracking

```cpp theme={null}
FManalensErrorOptions Options;
Options.ErrorType = TEXT("SaveFailed");
Options.Severity = EManalensSeverity::Critical;
Options.bHandled = false;
Manalens->TrackError(TEXT("Save failed"), Options);

// Return nullptr to drop an error, for example one with personal data.
Manalens->SetBeforeSend([](TSharedPtr<FJsonObject> Props) { return Props; });
```

In Blueprint, use **Track Error** and **Make ManalensErrorOptions**.

The SDK also sends `Error` lines of the engine log (`UE_LOG`) as `error` events, with the log category as `error_type`. Shipping builds compile the log out, unless your target sets `bUseLoggingInShipping`. After a crash, the next launch sends `app_unclean_exit`. See [Error tracking](https://docs.manalens.dev/features/error-tracking.md).

Before the SDK queues a log line, it removes personal data:

* Home folders, such as `/Users/<name>`, `/home/<name>`, and `C:\Users\<name>`, become `~`.
* URLs lose the user name and password, the query string, and the fragment.
* Email addresses become `[email]`.
* Values after `key=`, `token=`, `secret=`, `password=`, `Authorization:`, and `Bearer`, and runs of 24 or more letters, digits, `_`, or `-`, become `[redacted]`.

The fingerprint uses the cleaned text, so the same error on two computers is one group. The SDK never captures lines from `LogOnline*`, `LogEOS*`, `LogSteamShared`, `LogSlate`, `LogHttp`, or `LogManalens`. In the editor (Play In Editor), it also skips the categories of editor modules, because the editor logs in the same process as your game: `LogBlueprint` (the Blueprint compiler), `LogEditor*`, `LogUnrealEd`, `LogShaderCompilers`, `LogDerivedDataCache`, `LogSourceControl`, `LogCook*`, `LogAutomation*`, and other editor tools. Errors of your Blueprints at run time (`LogScript`, Print String) are still sent. A packaged game skips none of them. The text of a Track Error call is sent as you give it.

The limits are the same as in the other SDKs: one fingerprint at most once a second, at most 20 errors in 10 seconds, and at most **Max Auto Errors Per Session** log errors in one session.

## Editor runs

Play in Editor sends events like a live game, so you can watch your integration in [Activity](https://docs.manalens.dev/features/activity.md) and [Live View](https://docs.manalens.dev/features/live-view.md) while you play. A packaged build and a `-game` run always send. To send nothing from the editor, turn off **Enabled In Editor**.

Dev and live data go to the same project. Play in Editor runs send **Editor Build** (default `dev`) in place of **Build**, so you can filter them out. To tell other test builds apart, set **Build** (for example `dev`) and filter by it. Each developer machine counts as one player, and your game's errors in Play in Editor appear in [error tracking](https://docs.manalens.dev/features/error-tracking.md). The editor's own errors are not sent (see [Error tracking](#error-tracking)).

Unsent events stay on disk (`Saved/Manalens/`) and go out at the next launch with that launch's publishable key. If the key changes between launches (for example a dev key, then a release key), the queued events go to the new key's project. They keep the **Build** they were sent with, so you can still filter them out.

## Events

| Event | When |
| - | - |
| **On Flushed** (`Sent`, `bOk`) | After each send. `bOk` is `false` for a network error or a `5xx`, `408`, or `429` response; those events stay queued. |
| **On Send Failed** (`Status`, `Dropped`) | Events were dropped and will never be sent. `Status` is the HTTP status when Manalens refused a batch (another `4xx`) or some events of an accepted batch (`202`), or `0` when the SDK dropped events itself (the queue was over Max Queue, or events were older than 7 days). |

Both are Blueprint events on the subsystem. In C++, use `OnSendFailed.AddDynamic()`.

## Sessions

A session ends after 30 minutes without focus or events, and at **24 hours**. Then the SDK sends `session_end` (`duration_s`) and starts a new one. After a crash with focus, the next launch ends the old session and sends `app_unclean_exit`. A mobile game that the OS closes in the background is not a crash. Focus loss and the move to the background save the state and send the queue.

To put a [server event](https://docs.manalens.dev/sdks/server.md#session-id-of-the-client) (for example a purchase) in the player's session, send **Get Session Id** and **Get Anonymous Id** to your backend.

## Offline queue and retries

* Events are saved in `Saved/Manalens`. They are sent every 10 seconds, at 20 events, on focus loss, and on quit.
* Network errors, `5xx`, `408`, and `429` are retried with backoff (2, 4, 8 ... seconds, at most 5 minutes). A `Retry-After` header asks for a longer wait, up to 1 hour. Other `4xx` drop the batch and log the reason. A `202` can list refused events: the collector stored the others, and the SDK drops the refused ones, logs the reason codes, and raises **On Send Failed** with their count.
* Events older than 7 days are dropped.
* A retry never counts twice, because each event keeps its `message_id`.

## Quit

When the game instance shuts down, the SDK sends `session_end` and waits at most **Quit Timeout Seconds** for the last send. Unsent events stay on disk for the next launch.

## Consent

Turn on **Consent Required**. Then, from your consent screen:

```cpp theme={null}
Manalens->SetConsent(true);   // starts tracking; sends game_open
Manalens->SetConsent(false);  // deletes the ID, the session, and the queue
```

The SDK saves the choice for the next launch. An Identify before consent is sent after consent.

An opt-out fails closed: **Set Consent** (`false`) writes a marker file (`Saved/Manalens/manalens_optout`), and the SDK stays off while it exists. If the saved state cannot be read, the SDK stays off until **Set Consent** (`true`).

## Data the SDK sends

Each event carries `anonymous_id` (a random UUID kept in `Saved/Manalens`), `session_id`, `user_id` after Identify, `context.locale`, `context.utc_offset`, and `context.app`:

* `platform`: `windows`, `macos`, `linux`, `android`, `ios`, or `other` (consoles, tvOS, visionOS).
* `engine`: `unreal`.
* `app_version`, `build`, and `storefront`.

No device ID, no hardware details, no IP. Manalens gets the country from the request IP and does not store it.

## Test locally

From the repository, build the plugin with the engine and run its automation tests headless:

```bash theme={null}
UE_ROOT="/Users/Shared/Epic Games/UE_5.8" sdks/unreal/Tests/run-tests.sh
```

The script runs `RunUAT BuildPlugin`, copies the plugin into `sdks/unreal/HostProject`, and runs `Automation RunTests Manalens`.

## FAQ

> [accordion] Can I use it from Blueprint only?
>
> Yes. Every call is a Blueprint node on the Manalens subsystem. The project needs one C++ class so that the editor can build the plugin.

> [accordion] How do I keep editor and test runs out of my reports?
>
> Dev and live data go to the same project. Set **Build** (for example `dev`) for those runs and filter by it. See [Editor runs](#editor-runs).

> [accordion] What happens when the player is offline?
>
> Events wait on disk and are sent later. See [offline queue and retries](#offline-queue-and-retries).

> [accordion] Can I ask for consent before I track?
>
> Yes, with Consent Required. See [consent](#consent).

> [accordion] Does it run on a dedicated server?
>
> No. The SDK stays off on a dedicated server, because a server is not a player. Send [server events](https://docs.manalens.dev/sdks/server.md) from your backend instead.


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