{"id":"senorlawyer/roinsights","name":"roinsights","scope":"senorlawyer","platform":"roblox","description":"Server-side Roblox SDK for RoInsights, near-real-time analytics for Roblox experiences","version":"1.6.1","latest":"1.6.1","versions":["1.1.0","1.3.0","1.4.0","1.5.0","1.6.0","1.6.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"bd938e7ffb36d0188ade720e8e852b3c9d5aa6d5b6e3184d7bd040d54166be7b","likes":0,"downloads":0,"install":"forest install senorlawyer/roinsights","url":"https://forest.dev/p/roblox/senorlawyer/roinsights","files":"https://api.forest.dev/ai/package/roblox/senorlawyer/roinsights/files","readme":"# RoInsights Roblox SDK\n\nServer-side Luau SDK for [RoInsights](https://roinsights.dev), near-real-time analytics for Roblox\ngames. Install it once on your game's servers and the dashboard shows live sessions,\nretention, funnels, economy, revenue, progression, custom events, version comparison, server\nhealth and script errors within 30 to 60 seconds.\n\n- Runs on the server. Requiring it from a client errors, and the credential never replicates. The\n  only client code is an optional LocalScript that reports the player's device type (see\n  [Device info](#device-info)).\n- Every tracking call validates its input, appends to an in-memory queue and returns. Calls never\n  yield and never throw into your game code.\n- One background thread does all network work, with one request in flight at a time.\n\n## Contents\n\n- [Install](#install)\n- [Set up the credential](#set-up-the-credential)\n- [Quick start](#quick-start)\n- [API reference](#api-reference)\n- [Automatic tracking](#automatic-tracking)\n- [Experiments](#experiments)\n- [Mirroring to Roblox Analytics](#mirroring-to-roblox-analytics)\n- [Limits](#limits)\n- [Delivery, retries and shutdown](#delivery-retries-and-shutdown)\n- [Troubleshooting](#troubleshooting)\n- [Design notes](#design-notes)\n- [Development](#development)\n\n## Branching journeys\n\nAdd a `Journeys` field to the options in your existing `RoInsights:Init()` call. A connected server registers its stages under Behavior > Journeys in Studio or Live.\n\n```luau\nJourneys = {\n    StoreCheckout = { { \"Opened store\" }, { \"Viewed sword\", \"Viewed armor\" }, { \"Bought item\" } },\n},\n```\n\nAfter the server verifies a node's action, call `RoInsights:Journey(player, \"StoreCheckout\", \"Viewed sword\")`. For repeatable flows, pass one attempt ID as the fourth argument for all nodes of that visit.\n\n\n## Install\n\nPick one:\n\n- **Creator Store (easiest).** Insert the\n  [RoInsights Analytics SDK](https://create.roblox.com/store/asset/93228935911036) model from the\n  Toolbox in Studio and move the `RoInsights` module into ServerScriptService.\n- **Wally (for Rojo users).** The package is server-only, so add it under `[server-dependencies]`\n  and run `wally install`:\n\n  ```toml\n  [server-dependencies]\n  RoInsights = \"senorlawyer/roinsights@1.6.1\"\n  ```\n\n  Map `ServerPackages` into ServerScriptService in your Rojo project. Use a Roblox secret for the\n  credential, because a `Config` module inside the package is lost on the next install.\n- **Download the .rbxm.** Get [RoInsights.rbxm](https://roinsights.dev/downloads/RoInsights-1.6.1.rbxm)\n  and drag it into ServerScriptService in Studio.\n\nKeep the `RoInsights` ModuleScript in **ServerScriptService** or **ServerStorage**. Anywhere else\nreplicates to clients.\n\nRoInsights supports SDK 1.4.0 and later. Update an older copy the same way you installed it.\n\n### Enable HTTP\n\nIn Studio, open **Home › Game Settings › Security**, turn on **Allow HTTP Requests**, then publish.\nWithout it, the SDK warns once and keeps retrying.\n\n## Set up the credential\n\nCreate a project in the RoInsights dashboard and copy its project credential. It starts with\n`ri_live_`. Whoever has it can send data to your project, so keep it on the server.\n\n`Init` looks for the credential in this order:\n\n1. **A Roblox secret (recommended).** Add a secret named `ROINSIGHTS_TOKEN` on your game's\n   Secrets page in Creator Hub, with the credential as the value and `ingest.roinsights.dev` as the\n   allowed domain. The SDK reads it with `HttpService:GetSecret` and sends it as `Bearer <secret>`.\n   It never prints or stores the value. To test in Studio, add the same secret as a local secret under\n   **Home › Game Settings › Security**. Use the `SecretName` option to pick a different name.\n2. **The `Token` option** passed to `Init`.\n3. **A `Config` ModuleScript** parented to the `RoInsights` ModuleScript that returns\n   `{ Token = \"ri_live_...\" }`. See [`examples/Config.luau`](examples/Config.luau).\n\nOptions 2 and 3 put the credential in plain text, so the SDK refuses them unless `RoInsights` (and\nits `Config` child) are descendants of ServerScriptService or ServerStorage. If they replicate to\nclients, `Init` warns and stays off.\n\n## Quick start\n\nCall `Init` once from a Script in ServerScriptService:\n\n```lua\nlocal ServerScriptService = game:GetService(\"ServerScriptService\")\nlocal RoInsights = require(ServerScriptService.RoInsights)\n\nRoInsights:Init()\n```\n\nThen track from any server code:\n\n```lua\nRoInsights:Event(Player, \"OpenedShop\", { Tab = \"Gems\" })\nRoInsights:Economy(Player, \"Sink\", \"Coins\", 250, 1200, \"Shop\", \"SpeedBoots\")\nRoInsights:Progression(Player, \"Campaign\", \"Complete\", 3, \"Desert\")\n```\n\n### Examples\n\n- [`Bootstrap.server.luau`](examples/Bootstrap.server.luau) is a Script for ServerScriptService. It\n  initializes the SDK and, on `PlayerAdded`, assigns an experiment, records the starting coins as an\n  economy source, logs the first onboarding funnel step and sets session context. It expects the\n  `RoInsights` ModuleScript in ServerScriptService and the credential in the `ROINSIGHTS_TOKEN`\n  secret (or a `Config` module).\n- [`Config.luau`](examples/Config.luau) is the optional `Config` ModuleScript. Parent it to the\n  `RoInsights` ModuleScript and use it only when you cannot use a secret. Both modules must sit in\n  ServerScriptService or ServerStorage, and a real credential must never be committed to a public\n  repository.\n- [`Purchase.server.luau`](examples/Purchase.server.luau) holds the handlers from the\n  [purchases guide](https://roinsights.dev/docs/purchases). `ProcessReceipt` grants a developer\n  product and records its `PurchaseId` in one `UpdateAsync` on the player's saved data, never trims\n  that receipt list, and reports the purchase only after the save succeeded, so a retried receipt\n  never grants twice. Game passes report a configured list price that a catalog lookup refreshes,\n  never 0. `tests/PurchaseDocs.spec.luau` runs this file through retries and failed lookups.\n\n## API reference\n\nAll methods use colon syntax. `Properties` is an optional flat table of up to 24 keys whose values\nare strings, finite numbers from -1e15 to 1e15 or booleans (see [Limits](#limits)).\n\n### `RoInsights:Init(Config?)`\n\nStarts the SDK. Safe to call more than once; only the first call counts. Call it from one server\nScript before other scripts start tracking. Calls made before `Init` are ignored.\n\n| Option | Type | Default | Meaning |\n| --- | --- | --- | --- |\n| `Token` | `string?` | `nil` | Project credential, if you do not use a secret |\n| `SecretName` | `string` | `\"ROINSIGHTS_TOKEN\"` | Name of the Roblox secret to read |\n| `Endpoint` | `string` | `\"https://ingest.roinsights.dev\"` | Ingest API base URL. Must be `https://`; plain `http://` is accepted only for `localhost`, `127.0.0.1` and `[::1]` |\n| `MirrorToRobloxAnalytics` | `boolean` | `false` | Also log to Roblox `AnalyticsService` |\n| `TrackStudio` | `boolean` | `true` | Send data from Studio tests (tagged `studio`) |\n| `AutoTrackSessions` | `boolean` | `true` | Track player sessions automatically |\n| `Debug` | `boolean` | `false` | Print `[RoInsights]` logs, including dropped input |\n| `MaxQueueSize` | `number` | `5000` | Events held in memory before the oldest are dropped (100 to 100000) |\n| `CaptureErrors` | `boolean` | `true` | Report server script errors (see [Script errors](#script-errors)) |\n| `ClientReporter` | `boolean` | `true` | Give each player a small LocalScript that reports device info (see [Device info](#device-info)). Needs `AutoTrackSessions` |\n\nUnknown options and wrong types warn once and fall back to the default.\n\n### `RoInsights:Event(Player?, Name, Properties?)`\n\nA named event. Pass `nil` as the player for a server-level event.\n\n### `RoInsights:Custom(Player?, Name, Value?, Properties?)`\n\nA named event with a numeric value, for sums and averages. Mirrors to\n`AnalyticsService:LogCustomEvent` when mirroring is on.\n\n### `RoInsights:SetOnboarding(Steps)`\n\nDeclares your onboarding steps once, in order, for example\n`RoInsights:SetOnboarding({ \"Planted a seed\", \"Harvested\", \"Opened the shop\" })`. Up to 99 names.\nThe SDK then reports a `Joined` step for every player automatically.\n\n### `RoInsights:Step(Player, StepName, Properties?)`\n\nReports that a player reached one of the declared onboarding steps. Each step is sent once per\nplayer per server, in any order. Call it for every player; the dashboard counts only each player's\nfirst session. It is sent as the `Onboarding` funnel, so it mirrors like `Funnel`.\n\n### `RoInsights:Funnel(Player, FunnelName, FunnelSessionId?, Step, StepName, Properties?)`\n\nOne step of a funnel. `Step` is an integer from 1 to 100. Pass a `FunnelSessionId` to tell apart\nrepeated runs of the same funnel, such as several shop visits. Mirrors to\n`AnalyticsService:LogFunnelStepEvent`.\n\n### `RoInsights:Economy(Player, FlowType, Currency, Amount, EndingBalance?, TransactionType, ItemSku?, Properties?)`\n\nA currency source or sink. `FlowType` is `\"Source\"` or `\"Sink\"`, `Amount` must be greater than 0\nand `EndingBalance` is the player's balance afterwards. Mirrors to `AnalyticsService:LogEconomyEvent`\nwhen `EndingBalance` is given, because Roblox requires it.\n\n### `RoInsights:Progression(Player, PathName, Status, Level, LevelName?, Properties?)`\n\n`Status` is `\"Start\"`, `\"Complete\"` or `\"Fail\"`; `Level` is an integer from 0 to 1000000. Mirrors to\n`AnalyticsService:LogProgressionEvent`.\n\n### `RoInsights:Purchase(Player, Info, Properties?)`\n\nA Robux purchase. Call it from your own `ProcessReceipt` after you grant the item; the SDK never\ntouches `MarketplaceService.ProcessReceipt`.\n\n```lua\nRoInsights:Purchase(Player, {\n\tType = \"DeveloperProduct\",\n\tName = \"100 Gems\",\n\tRobux = ReceiptInfo.CurrencySpent,\n\tProductId = ReceiptInfo.ProductId,\n\tReceiptId = ReceiptInfo.PurchaseId,\n})\n```\n\n| Field | Type | Notes |\n| --- | --- | --- |\n| `Type` | `string` | `\"DeveloperProduct\"`, `\"GamePass\"`, `\"Subscription\"` or `\"Other\"` |\n| `Name` | `string` | Item name, 1 to 64 characters |\n| `Robux` | `number` | Robux spent, an integer from 0 to 100000000 |\n| `ProductId` | `(number \\| string)?` | Developer product or game pass id, a positive integer. For `Type = \"Subscription\"`, the subscription id string such as `\"EXP-1234567890\"` (`EXP-` and 1 to 20 digits) |\n| `ReceiptId` | `string?` | Receipt or purchase id, up to 64 characters |\n\n### `RoInsights:SetPlayerContext(Player, Context)`\n\nAttaches flat key/value data (segments, cohorts, settings) to the player's current session. Only\nkeys whose value changed are sent. If the event carrying a value is lost (evicted from a full\nqueue, discarded or dropped by the ingest API), the SDK forgets that value, so the next call with\nthe same value sends it again.\n\nA session's context holds at most 64 keys and about 16384 bytes (the sum of each key's length and\nits value's text length), the same cap the ingest API applies. Changed values of keys the session\nalready has are always sent; new keys beyond the cap are ignored, logged with `Debug` and warned\nabout once. `Experiment` assignments count towards the same cap. Context belongs to one session: set it again after the player\nrejoins. Needs an active session, so it does nothing when `AutoTrackSessions` is off.\n\n### `RoInsights:Experiment(Player, ExperimentName, Variants) -> string`\n\nReturns the player's variant and records it as session context. See [Experiments](#experiments).\n\n### `RoInsights:Flush()`\n\nAsks the background thread to send on its next tick (within about a second). Does not yield.\n\n### `RoInsights:GetStatus()`\n\nReturns a table for debugging:\n\n| Field | Meaning |\n| --- | --- |\n| `Connected` | The server holds a valid server token |\n| `ServerId` | Server session id from the ingest API |\n| `QueueSize` | Events waiting to be sent, including an unacknowledged batch |\n| `Dropped` | Events lost to a full queue, rejected batches or events that cannot be encoded |\n| `DroppedErrors` | Script error occurrences not reported because 50 distinct errors were already waiting within about a second |\n| `Rejected` | Events in a delivered batch that the ingest API rejected one by one (they failed its schema or fell outside its time window), as counted in its 2xx answer. The first rejection warns once and sets `LastError` |\n| `Duplicates` | Events in a delivered batch that the ingest API had already stored (an event resent after a lost answer), as counted in its 2xx answer. Normal after retries; nothing is lost. Always 0 against ingest APIs that do not report it |\n| `LastError` | Last delivery error, or why the SDK is inactive |\n\n## Automatic tracking\n\nWithout any tracking calls, the SDK collects the following.\n\n### Player sessions\n\nWith `AutoTrackSessions` on (the default):\n\n- Players already in the server at `Init`, and every later `Players.PlayerAdded`, get a\n  `session_start` with a new session id and the player traits below.\n- `country` is the two-letter ISO 3166-1 code returned by\n  `LocalizationService:GetCountryRegionForPlayerAsync`, and `friendsInServer` counts the other\n  players in the server the player is friends with (`Player:IsFriendsWith`, at most 10 checks, so\n  the value is 0 to 10). Both lookups run in their own threads and the start waits at most 3\n  seconds for them; the session starts with the time the player joined either way, and leaves out a\n  value whose lookup failed or was too slow.\n\n| Trait | Source |\n| --- | --- |\n| `premium` | `Player.MembershipType` is Premium |\n| `accountAgeDays` | `Player.AccountAge`, 0 to 100000 |\n| `country` | `GetCountryRegionForPlayerAsync` |\n| `locale` | The language part of `Player.LocaleId`, such as `en` or `pt` (2 or 3 letters) |\n| `joinSource` | `teleport` when `Player:GetJoinData()` has a `SourcePlaceId`, else `friend` when `Player.FollowUserId` is set, else `referral` when the join data has a `ReferredByPlayerId`, else `direct`. Left out when `GetJoinData` fails and the player did not follow anyone |\n| `friendsInServer` | Friends already in the server, 0 to 10 |\n- `Players.PlayerRemoving` sends `session_end`. Duration is computed by the server.\n- Every event for a player carries that player's session id, including events tracked while the\n  country lookup is still running. If your code tracks a player before the SDK's `PlayerAdded`\n  listener runs, the session starts on that first event.\n- Events for a player who already left are still sent, without a session id.\n- Every batch lists the ids of the sessions open at the moment it is sent (`activeSessions`). The\n  server ends sessions missing from the list at their last heartbeat, so a lost `session_end` cannot\n  keep a session open, and reopens listed sessions it had ended because the ingest API was\n  unreachable for more than 10 minutes, so players who stayed through an outage keep their session.\n\n### Server health\n\nEvery batch reports the server's player count and doubles as a heartbeat, which keeps live player\ncounts accurate even when no events happen. It also carries a `server` object measured since the\nprevious request, retries included:\n\n| Field | Source |\n| --- | --- |\n| `fps` | Heartbeat frames divided by the time they covered |\n| `fpsMin` | Lowest heartbeat rate of any full second in that period |\n| `memoryMb` | `Stats:GetTotalMemoryUsageMb()` |\n| `dataReceiveKbps`, `dataSendKbps` | `Stats.DataReceiveKbps`, `Stats.DataSendKbps` |\n| `pingMs`, `pingP90Ms` | Mean and 90th percentile of `Player:GetNetworkPing()` across current players, sampled when the batch is built |\n| `instances` | `Stats.InstanceCount` |\n\nEach value is clamped to the protocol's range, and a value that cannot be read is left out. Without\na heartbeat rate or a memory reading the whole `server` object is left out.\n\n### Script errors\n\nWith `CaptureErrors` on (the default), errors from server scripts (`ScriptContext.Error`) are\ngrouped by message and script between batches. Each group becomes one `error` event with the\nnumber of occurrences, the time of the first one and its stack trace. Messages are cut t","readmeTruncated":true,"readmeFull":"https://api.forest.dev/v1/package/senorlawyer/roblox/roinsights/1.6.1/readme"}