# The ravensight module for Go games and servers

Player analytics for games written in Go, and server events for Go game servers and backends, from one module with no dependencies outside the standard library. A `Client` runs inside your game with its publishable game key. A `Server` runs on your own server with a website's secret server key.

**Preview.** Version 0.1.0 has not yet shipped inside a released game. Read the code before you ship it in a release build, and open an issue on the repository with anything you hit.

Code samples scroll horizontally when needed. Focus a sample and use the arrow keys, or swipe to read a long line.

## Install

The source is [ravensight-go](https://github.com/Reality-Software-Entertainment/ravensight-go), under the MIT license. It needs Go 1.22 or newer.

```
go get github.com/Reality-Software-Entertainment/ravensight-go@v0.1.0
```

```
import "github.com/Reality-Software-Entertainment/ravensight-go"
```

The package name is `ravensight`.

## Quickstart

A game

```
client := ravensight.New(ravensight.Config{
    IngestKey:   "gt_live_your_key", // from your game's page in the dashboard
    GameVersion: "1.0.0",
})
defer client.Close()   // records game_exited and sends what is left
defer client.Recover() // records a panic for the next launch, then panics again

client.Track("level_completed", map[string]any{
    "level":   3,
    "deaths":  2,
    "seconds": 41.7,
})
```

That is the whole setup. The client reads the server's kill switch, opens a session and sends batches from its own goroutine. `Track` copies and serializes your data at once and returns. It never waits on the network or the disk, so it is safe to call from your game loop (an Ebitengine `Update`, for example). The device id is saved in a per-user directory, so the same install counts as the same player across launches.

A game that wants one client and no plumbing can use the package-level functions:

```
ravensight.Init(ravensight.Config{IngestKey: key})
defer ravensight.Close()
ravensight.Track("level_start", map[string]any{"level": "forest_1"})
ravensight.Default().Identify(account.AnalyticsID) // every other call
```

A game server or backend

```
srv := ravensight.NewServer(ravensight.ServerConfig{
    ServerKey: os.Getenv("RAVENSIGHT_SERVER_KEY"), // gt_srv_..., never in a game build
})
defer srv.Close()

// In the background, batched:
err := srv.Track(ravensight.ServerEvent{
    Name:       "match_finished",
    ActorID:    account.AnalyticsID, // your own opaque id, passed explicitly
    Properties: map[string]any{"mode": "ranked", "won": true},
})

// Or now, waiting for the answer:
result, err := srv.Send(ctx, ravensight.ServerEvent{Name: "signup_completed", ActorID: id})
```

See [server mode](https://ravensight.io/docs/go-sdk/#go-server-mode) below.

## The client's calls

| Call | What it does |
| --- | --- |
| `ravensight.New(cfg)` | Makes a client and starts its goroutine. Never fails: without a key it is inert. |
| `client.Track(name, data)` | Queues an event. Returns `false` when it was not queued. Never blocks. |
| `TrackPurchase`, `TrackResource`, `TrackProgression`, `TrackError` | [Typed events](https://ravensight.io/docs/go-sdk/#go-typed-events). |
| `client.Flush(ctx)` | Sends what is queued and waits until the queue is empty, nothing more can be sent for now, or `ctx` ends. |
| `client.Close()` | Records `game_exited`, sends for at most about 1.5 seconds, saves what is left for the next launch, and stops. |
| `client.Shutdown(ctx)` | `Close` with your own time limit. |
| `client.SetTrackingEnabled(on)`, `TrackingEnabled()` | The player's analytics choice, saved and remembered across launches, and whether it allows collecting. |
| `client.ResetDeviceID()` | A fresh random device id from now on. Returns the new id. |
| `client.SetEnabled(on)`, `IsEnabled()` | A runtime switch for your own logic. Not saved. |
| `client.Identify(accountID)`, `ResetIdentity()`, `IsIdentified()` | Links this device to your game's own account, and unlinks it at sign-out (see [players who sign in](https://ravensight.io/docs/go-sdk/#go-identify)). |
| `client.SetCampaignLink(linkID)` | Passes on the [campaign link](https://ravensight.io/docs/go-sdk/#go-campaign-links) the game was opened with. |
| `ConfigBool`, `ConfigNumber`, `ConfigString`, `ConfigJSON`, `FetchConfig()` | [Remote config](https://ravensight.io/docs/go-sdk/#go-remote-config) reads with a fallback, and a fresh fetch now. |
| `client.SubmitFeedback(ctx, fb)` | Sends player feedback and waits for the answer. |
| `client.Recover()`, `LogHandler(next)`, `Log(level, msg)`, `WrapTransport(rt)` | Feed panics, your game's log and its failed HTTP requests to [error capture](https://ravensight.io/docs/go-sdk/#go-errors). |
| `client.SetErrorCapture(on)`, `IsErrorCaptureActive()` | Automatic capture for this run. |
| `client.Status()`, `IsCollecting()` | Why the client is or is not sending. |
| `client.DeviceID()`, `SessionToken()`, `IsPlaytest()`, `Stats()` | Read-only state. |
| `ravensight.SetTrackingEnabled(cfg, on)` | Saves the player's choice before a client exists. |
| `ravensight.DefaultStorageDir(key)` | Where a client keeps its files by default. |

Every method is safe from any goroutine, and safe on a nil `*Client`, where it does nothing.

Event data is a `map[string]any` of strings, numbers, bools, nil or anything `encoding/json` can write. Keys that start with `rs_` are reserved for Ravensight. An event's name must not be empty and is at most 200 characters, and its data is at most 8,192 bytes as JSON. Otherwise `Track` returns `false`, drops the event and logs one warning for the run.

## Configuration

Fields of `ravensight.Config`. The zero value of each is its default.

| Field | Default | Meaning |
| --- | --- | --- |
| `IngestKey` | empty | Your game's `gt_live_` key, or a public `gt_pub_` key. Empty makes the client inert. |
| `Optional` | `false` | Silences the one warning an inert client logs. |
| `APIURL` | `https://api.ravensight.io` | With or without `/api/v1`; trailing slashes are ignored. |
| `GameVersion` | `1.0.0` | Sent on every session. |
| `Platform` | the build's operating system | Such as `windows`, `macos` or `linux`; `web` for a WebAssembly build. |
| `Distribution` | empty | A short label for this build, such as `steam` or `itch-demo`. At most 40 characters, otherwise not sent. |
| `Device` | empty | Optional `Model`, `OSVersion` and `GPU`, sent once on the session. The SDK never probes for them. |
| `DeviceID` | empty | Your own stable per-install id. Empty uses a random saved `dev_` id. |
| `StorageDir` | per-user | Where the SDK keeps its files (see [privacy and storage](https://ravensight.io/docs/go-sdk/#go-privacy)). |
| `Consent` | `ConsentOptOut` | `ConsentOptIn` sends nothing, and makes no device id, until `SetTrackingEnabled(true)`. |
| `StartDisabled` | `false` | Start switched off, as `SetEnabled(false)`. |
| `MaxQueueSize` | `500` | Unsent events kept, oldest dropped first. At most 500. |
| `FlushInterval` | 5 seconds | How long an event may wait to go out with others. A negative value sends only on `Flush`, at 50 waiting events and on `Close`. |
| `RequestTimeout` | 15 seconds | Per request. |
| `NoLifecycleEvents` | `false` | Turns off `game_started` and `game_exited`. |
| `NoErrorCapture` | `false` | Turns off automatic error capture. |
| `MemoryOnlyQueue` | `false` | Keeps unsent events in memory only. |
| `JoinToken` | empty | A session token from the player's client (see [dedicated servers](https://ravensight.io/docs/go-sdk/#go-dedicated-servers)). |
| `CampaignLink` | empty | A campaign link id the game was opened with. |
| `Playtest` | empty | Overrides the playtest values read from the environment and the command line. |
| `HTTPClient` | the SDK's own | Sends the requests. |
| `Logger` | warnings to standard error | A `*slog.Logger` that receives the SDK's own lines, each starting `Ravensight:`. |
| `OnStatus` | none | Called when `Status()` changes, on any goroutine. Keep it quick. |
| `OnConfigReady` | none | Called after each remote config fetch: `true` for a fresh answer or a confirmed cache. |

## Automatic events and status

Two events are sent for you, unless `NoLifecycleEvents` is set: `game_started`, queued once when the client may first collect, so it is the first event and carries the real start time, and `game_exited`, queued once by `Close` or `Shutdown`. The SDK has no engine hooks, so it does not see a mobile app go to the background. Call `client.Flush(ctx)` from your own pause handler.

`client.Status()` returns a `ravensight.Status`, with the codes every Ravensight SDK shares.

| Status | Meaning |
| --- | --- |
| `StatusOK` (empty) | Sending, or about to. |
| `no_key` | Made with no key. Inert for its lifetime. |
| `disabled` | Switched off, opted out, or waiting for an opt-in yes. Nothing touches the network. |
| `invalid_key` | The key was refused. Logged once, and nothing more is sent this run. |
| `tracking_disabled` | The game's kill switch on the server. Nothing more is sent this run. |
| `offline` | No connection, a timeout or a server error. Retried with a backoff. |
| `rate_limited` | Waiting out the server's `Retry-After`. |
| `session_failed` | The session could not be opened, or a playtest token was refused. |
| `playtest_job_closed` | The playtest job finished. Nothing more is sent this run. |

## Delivery

The client follows the Ravensight delivery contract, so an event survives a lost connection, a crash, a kill and a build update.

- **Batching.** `Track` only queues. An event waits at most 5 seconds to go out with others; 50 waiting events go at once, and `Flush` and `Close` send at once. At most 50 events go in one request.
- **Bounded.** At most 500 events wait. At the cap the oldest go first, automatic error captures before gameplay events.
- **Saved queue.** Unsent events are kept in `queue-.json` in the storage directory, one file per key, written through a temporary file and a rename about a second after a change and right after every answer, and deleted when empty. The next launch sends what is left. Events older than 89 days are dropped when the file is read.
- **Origin.** Each session's events are saved with that session's `origin`, so a later launch sends them under the session, build and platform they happened in.
- **Event ids.** Every event carries an `rs_event_id`, kept across resends, so a resend after a lost answer is stored once.
- **Answers.** An event leaves the queue on a `2xx` answer, or a `400` that names it by `index`. A `400 batch_too_large` or a `413` halves the batch, and a single event still too large is dropped. Any other `400` drops the request's events. A `401` opens a new session once and resends the same ids; a second in a row waits for the backoff. A `403` stops sending for the run and keeps the events for the next launch.
- **Backoff.** Any other failure keeps the events and waits 10 seconds, doubling to 5 minutes, each wait multiplied by a random factor from 0.5 up to 1. A `429` or `503` with `Retry-After` waits exactly that long. `Flush` and `Close` cut a backoff short, never a `Retry-After`.
- **Compression and signing.** A body of 1,024 bytes or more is sent gzip compressed; a `415` is sent again uncompressed. When the session answer carries a signing secret ([public keys](https://ravensight.io/docs/public-builds/)), every batch is signed over the uncompressed body, with the device clock corrected by the server's time. The secret is kept in memory only.

## Typed events

```
// Money is whole minor units: 499 is 4.99. Default name: purchase.
client.TrackPurchase(ravensight.Purchase{Amount: 499, Currency: "usd", ItemType: "pack", ItemID: "gems_500"})

// Default name: resource_source or resource_sink.
client.TrackResource(ravensight.Resource{Flow: "sink", Resource: "gold", Amount: 120, ItemType: "weapon"})

// Default name: progression_start, progression_complete or progression_fail.
score := 1250.5
client.TrackProgression(ravensight.Progression{Status: "complete", P1: "world1", P2: "level3", Score: &score})

// Severity is debug, info, warning, error or critical. Default name: error.
client.TrackError(ravensight.ErrorReport{Severity: "error", Message: "save file unreadable"})
```

Each takes `Extra` properties (a reserved key always wins) and a `Name` that replaces the default. The currency is sent upper-cased. To mark a level or death event without a typed helper, set `rs_kind` to `level_start`, `level_complete`, `death` or `none`. What the dashboard reads from each is in [typed events](https://ravensight.io/docs/dashboard/#typed-events).

## Errors

Captured errors appear in the game's [Errors view](https://ravensight.io/docs/error-capture/). An error is an ordinary event on your usage balance, and spend is bounded on the device by the caps below.

| What | How it starts | What is sent |
| --- | --- | --- |
| A panic | `defer client.Recover()` | On the next launch, with source `crash` and severity `critical`: the panic's type, its message and the stack. A panic the program survived is sent at once with source `uncaught`. |
| Your game's log | `client.LogHandler(next)`, or `client.Log(level, msg)` from your own logger | A record at `slog.LevelError` or above, with source `log` and severity `warning`. Every record feeds the trail. |
| Your game's HTTP requests | `client.WrapTransport(rt)` | A network failure or a `5xx` as `error`, a `4xx` as `warning`, with source `request`. |
| `client.TrackError(...)` | Your call | As you wrote it, never held back by the switches below. |

```
func main() {
    client := ravensight.New(cfg)
    defer client.Close()
    defer client.Recover() // here, and at the top of each goroutine you start

    // Your game's log: every record still reaches your own handler.
    slog.SetDefault(slog.New(client.LogHandler(slog.NewTextHandler(os.Stderr, nil))))

    // Your game's own HTTP requests.
    httpClient := &http.Client{Transport: client.WrapTransport(http.DefaultTransport)}
    // ...
}
```

The source and severity are sent as `rs_source` and `rs_severity`. Through `LogHandler`, a record's message also carries its first error-valued attribute, whose type becomes `rs_error_type`. A failed request's message is ` `, with `network` as the status when there was no answer, and path segments that are numbers, long hex or UUIDs become `:id`. The SDK's own requests are never captured, and the answer reaches your code unchanged.

**Recover.** It writes one small file at once, readable by the player's account only, then panics again with the same value, so the game ends exactly as it would have. The next launch sends it, and deletes the file once the event is received, so a failed send never loses it. If the program is still running two seconds after the panic, an outer `recover` caught it (`net/http` does this for its handlers), so it was not a crash: the file is deleted and the panic is sent at once with source `uncaught` and severity `error`. At most 5 records are written a run and 5 kept, and one older than 30 days is deleted unsent. Go cannot recover a fatal runtime error (a concurrent map write, running out of memory), and a panic in a goroutine without its own `defer client.Recover()` is not recorded.

**The gate.** Nothing is captured without a key, before consent, while the game's Errors switch on the server is off, with `NoErrorCapture`, or after `SetErrorCapture(false)`. With a key and consent, capture starts before the first answer: up to 5 captures wait in memory, sent if the server says on and discarded unsent if it says off.

**Caps and scrubbing.** Per run, dropped silently on the device: 30 captures, 3 per local key (the type, the message with its numbers, ids and quoted text templated away, and the first stack line), 6 a minute and 10 trails. Text is scrubbed on the device before it is queued, with the server's rules: emails become `[email]`; `Bearer` tokens, JWT-shaped strings, `gt_` keys, and runs of 32 or more letters, digits and `+ / = _ -` that contain a digit become `[token]` (a run that is a file path is kept); IP addresses become `[ip]`; home folders (`/Users/`, `/home/`, `C:\Users\`) become `~`; a URL loses its query, fragment and `user:password@`. The message is cut to 200 characters, the stack to 2,000 and the type to 100.

**The trail** is an in-memory ring of the last 20 lines (log records at any level, and the names of events you track), each `+ `, scrubbed and cut to 120 characters, at most 1,500 in all. It is sent only with an error, only while the game's trail switch is on (it is off by default), and never written to the queue file. A crash record keeps the trail only while the switch is on.

**Never sent:** request bodies, headers, query strings, the SDK's own log lines (anything starting `Ravensight`) and its own requests, and `rs_fp` (the server computes the fingerprint). Gameplay events always go ahead of captured errors.

## Players who sign in

If your game has its own login, call `Identify` once the player signs in and `ResetIdentity` when they sign out. One person on two devices, or before and after signing in, then counts as one player (see [identify players](https://ravensight.io/docs/identify-players/)).

```
// after your own sign-in: a random id stored with the account
if err := client.Identify(account.AnalyticsID); err != nil {
    // *ravensight.RefusalError: empty, too_long or looks_like_email
}

// on sign-out
client.ResetIdentity()
```

- **What is sent.** A salted hash of the id (`accountHash`, HMAC-SHA256 keyed with your game's own salt from the session answer) and the session token, once per session. The raw account id is never sent and never saved; until the first session answer it is held in memory only.
- **Pass a random, high-entropy id**, such as a random UUID stored with the account, never a sequential database key, an email, a name or a handle. Your game's salt reaches every copy of the game, so anyone could hash 1, 2, 3 and onward and match a guessable id. The hash is still a pseudonymous identifier for the player: declare it in your privacy notice.
- **Refused.** An empty id (`empty`), more than 256 bytes of UTF-8 (`too_long`), or any `@` (`looks_like_email`). The id is used exactly as given, never trimmed. A refusal sends nothing and changes nothing.
- **One event per identified session** on your usage balance. The same account again sends nothing. A failed request is tried again at the next session, never in a loop. When the server does not offer identify, it is off until the next launch.
- **A different account** first runs `ResetIdentity`, which deletes the saved hash and switches to a fresh device id, so the next player is not linked to the last one. `ResetDeviceID` alone keeps the identity.
- **Where it is kept.** The hash is saved as `identity.json` beside the device id. Without a key, before consent, while switched off, or in a playtest run it is held in memory only, and an opt-out deletes it.

## Campaign links

A Ravensight [campaign link](https://ravensight.io/docs/campaign-links/) adds `rs_link=` to the address it sends players to. Pass it on from the address your game was opened with, such as a custom URL scheme or a deep link your game already handles. The SDK never reads the command line for it.

```
if link := openedURL.Query().Get("rs_link"); link != "" {
    _ = client.SetCampaignLink(link)
}
```

`SetCampaignLink` accepts 24 hex characters in any case and returns a `*RefusalError` (`invalid_link`) for anything else. The id goes lowercased, as `campaignLink`, on the next session the client opens for its own player, and is cleared once a session answers with a token. Set it before the first session with `Config.CampaignLink`. It is kept in memory only, and never sent without consent, without a key or in a playtest run.

## Remote config and experiments

Every session start fetches the game's public [remote config](https://ravensight.io/docs/remote-config/). `FetchConfig` asks again, and `OnConfigReady` says when an answer arrived.

```
speed := client.ConfigNumber("enemy_speed", 2.0)
hint := client.ConfigBool("show_hint", true)
label := client.ConfigString("welcome_text", "Welcome")
layout := client.ConfigJSON("layout", json.RawMessage(`{}`))
```

Each read returns the fallback before the first answer, offline, or when the value is another type; values are never converted. The last good answer is cached on disk for the same key, device, platform and build, and its ETag is reused. A fetch alone is not an exposure. The first typed read marks every [experiment](https://ravensight.io/docs/experiments/) the last fetch assigned as exposed and queues one `rs_exposure` event, and every event queued after it carries `rs_exp_` set to the variant. An experiment missing from a later fetch is no longer tagged. Do not log or show the device id beside config values. Config is public game data, never a place for secrets. A fresh fetch costs one ordinary event; a confirmed cache costs none.

## Feedback

```
err := client.SubmitFeedback(ctx, ravensight.Feedback{
    Message:  "The boss fight drags",
    Category: "suggestion", // optional: bug, suggestion, complaint, praise, playtest, other
    Rating:   3,            // 0 to leave it out, or 1 to 5
})
```

Bad input is refused on the spot with no request: `empty_message`, `message_too_long` (over 2,000 characters), `invalid_category` or `invalid_rating`. While the client is not sending, the error's code is the status, such as `disabled`. A refusal from the server comes back as a `*RefusalError` with its code. Feedback is never retried on its own.

## Privacy, storage and the opt-out

The SDK makes a random device id, `dev_` and 32 hex characters from the system's random source, and saves it once the player has not opted out. By default it lives in a per-user directory named after your key:

| Platform | Default storage directory |
| --- | --- |
| Windows | `%APPDATA%\ravensight\` |
| macOS | `~/Library/Application Support/ravensight/` |
| Linux and others | `$XDG_DATA_HOME/ravensight/`, else `~/.local/share/ravensight/` |

`` is the first 12 hex characters of the SHA-256 of the key. Set `StorageDir` where there is no such directory, such as a browser build or a console. If no directory can be used the SDK logs one warning and keeps everything in memory for the run. The directory holds `device_id`, `state.json` (the player's choice), `identity.json`, the queue file, `config.json` (the config cache) and pending crash records. Keep it out of cloud saves and device backups: the queue file holds scrubbed error captures and the origin of earlier sessions.

The SDK itself collects no hardware identifier, no advertising id and no personal data, and never sends a country. Only the events you choose to send leave the machine, plus the optional device fields you set. The store answers are in [what your privacy label can say](https://ravensight.io/docs/platform-support/#privacy-label).

```
client.SetTrackingEnabled(false) // saved at once; nothing more is sent
client.SetTrackingEnabled(true)  // back on, also saved

fresh := client.ResetDeviceID()  // a new identity; the queue is cleared
```

`SetTrackingEnabled(false)` saves the choice before it returns, clears the queue and deletes its file, pending crash records, the stored identity and the config cache, and stops every request. Every later client with the same storage reads it, and a saved opt-out wins: such a client makes no request of any kind. To save the choice before a client exists, call `ravensight.SetTrackingEnabled(cfg, false)` with the config you will use. `ResetDeviceID` makes and saves a new id, clears the queue and drops the session, so nothing links the old id to the new one. `SetEnabled(false)` is a runtime switch for your own logic, and is not saved.

You do not need a permission prompt, but saying what the game sends is good manners. A paragraph your game can show, in a settings screen or on its store page:

This game sends anonymous gameplay events (what happens in the game, never who you are) to Ravensight so we can improve it. You can turn this off in Settings at any time.

If your game calls `Identify`, its events are linked to a pseudonymous hash of the player's account, so say that instead of "anonymous" and declare the hash in your privacy notice.

## Public builds

- **No key, no analytics.** A client made with an empty `IngestKey` is inert: it starts no goroutine, makes no request, and every call is a quiet no-op. So a public repository can ship with no key in it. Set `Optional: true` to silence its one warning.
- **Inject the key at build time, never commit it.** Use a [public `gt_pub_` key](https://ravensight.io/docs/public-builds/) for builds anyone can download, set by your release build (example below).
- **The game key ships in your build.** It is not a secret, and you can rotate it from the dashboard at any time. A `gt_srv_` server key is a secret and never belongs in a game build (see [server mode](https://ravensight.io/docs/go-sdk/#go-server-mode)).
- **`ConsentOptIn`** sends nothing until the player says yes: no device id is made, and not even the kill switch is read before `SetTrackingEnabled(true)`. Events tracked before the yes are dropped, not held.

```
// go build -ldflags "-X main.ravensightKey=gt_pub_..."
var ravensightKey string

client := ravensight.New(ravensight.Config{IngestKey: ravensightKey, Optional: true})
```

## Dedicated servers

A game server written in Go can share the player's session, so its events land in the same session as the player's own instead of counting a second player. The player's client reads its token and sends it to your server however your game talks to it:

```
token := client.SessionToken() // on the player's client; empty until a session opens

// On the game server, one client per player connection:
c := ravensight.New(ravensight.Config{
    IngestKey:         key,
    JoinToken:         token,
    NoLifecycleEvents: true, // the player's client sends those
    MemoryOnlyQueue:   true,
    StorageDir:        perPlayerDir,
})
c.Track("match_result", map[string]any{"won": true})
```

The token is sent once, as `joinToken` (see [the session request](https://ravensight.io/docs/http-api/#post-api-v1-session)). If the server refuses it, the client opens a plain session instead. For events about your backend rather than a player's session, use server mode.

## Server mode

A `Server` sends [server events](https://ravensight.io/docs/server-events/) from your own server into a website's analytics (a title's website or your company website) with that website's secret server key, made in the dashboard. The events show in the website's Server events report.

- **Keep the key on your server.** A request that carries an `Origin` header is refused, so a server key never works from a browser, and the SDK never sends one.
- **Identity is explicit.** `ActorID` is your own opaque id for the person or device, 8 to 128 letters, digits, `_`, `.`, `:` or `-`, so never an email. The server stores only a keyed hash of it. Without it the event belongs to your backend itself. Server mode never reads or sends a player's device id.
- **Checked before sending.** Every event is checked the way the server checks it (the name, the ids, the time, at most 24 short properties, no value that looks like an email, a credential, a JWT or a key), so one bad event never costs a batch. `Send` and `Track` return a `*ValidationError` naming the event and the field.
- **Idempotent.** Each event has an `EventID` (the SDK makes one when you leave it empty) that stays the same across retries. The same id and content again is a duplicate, never counted twice.
- **Answers.** A `429`, a `5xx`, a timeout or a `409 site_changed` is sent again later, after the answer's `Retry-After` when it gives one. A pause for your studio's balance is not an error: the paused ids come back in `RefusedIDs`, cost nothing, and `Track` sends them again later. A refused key, or website analytics being off, stops the `Server` and returns a `*RefusalError`.
- **Memory only.** `Track` keeps at most `MaxQueueSize` events (10,000 by default) in memory and returns `queue_full` past it. `Close` sends for at most about 1.5 seconds; events still waiting after that are dropped.
- **Usage.** One accepted event is one event on your studio's usage, at the usual rate. Duplicates, refusals and paused events are free.

| Call | What it does |
| --- | --- |
| `ravensight.NewServer(cfg)` | Makes a `Server`. Never fails: without a valid `gt_srv_` key it is inert, and `Track` and `Send` return a `*RefusalError`. |
| `srv.Track(ev)` | Validates and queues an event to be sent in the background. Never blocks. |
| `srv.Send(ctx, evs...)` | Validates and sends now, in batches of 50, and returns the server's answer. Retries until `ctx` ends. |
| `srv.Flush(ctx)` | Sends the queued events now and waits. |
| `srv.Close()`, `srv.Shutdown(ctx)` | Sends what is left and stops. |
| `srv.Stats()` | Counters. |

`ServerConfig` takes the `ServerKey`, `Optional`, `APIURL`, `HTTPClient`, `Logger`, `MaxQueueSize`, `FlushInterval` (5 seconds) and `RequestTimeout` (15 seconds).

## Playtest

During a [Ravensight Playtest](https://ravensight.io/docs/playtest/) run the runner gives the build a token. The client reads it from `Config.Playtest`, then the environment (`RAVENSIGHT_PLAYTEST_TOKEN`, `RAVENSIGHT_PLAYTEST_RUN_ID`, `RAVENSIGHT_PLAYTEST_JOB_ID`, `RAVENSIGHT_PLAYTEST_PERSONA`), then the command line (`--ravensight-playtest-token=` and `--ravensight-playtest-run-id=`). With a token the device id is `pt-` in memory only, every request carries the token, events are tagged as the run's, nothing is written to disk, the player's saved opt-out is ignored, and identify and campaign links send nothing. A token without a run id never runs as a real player: nothing is sent.

## Compatibility

| ravensight-go | Go | Notes |
| --- | --- | --- |
| 0.1.0 | 1.22 or newer | Preview. Built and tested on macOS with the race detector, against a fake HTTP server. Windows, mobile and browser builds have not been run, and no released game has shipped with it yet. |

The tests run with `go vet./...` and `go test -race./...`, against a fake HTTP server and temporary directories: no network, and nothing written to your real storage directory. See [where the SDKs run](https://ravensight.io/docs/platform-support/) for every SDK side by side.

Source: https://ravensight.io/docs/go-sdk/
Last updated: 2026-11-20
