glitchless-mcp 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -91,7 +91,7 @@ above go in its environment.
91
91
  | `glitchless_bug_reports` | Bug reports players sent from inside the game: their notes, levels, positions and sessions, and one report's screenshot when asked |
92
92
  | `glitchless_store_reviews` | For a game connected to a store (Glitchless Cloud: Steam, Google Play, the App Store): what players wrote there, by store, build or version, sentiment, topic (stutter, lag, fps, freeze, crash), device and, on Steam, Steam Deck, each build with the frame-time p95 and crash-free sessions measured on it |
93
93
  | `glitchless_store_vitals` | What Google Play (slow rendering, crash and ANR rates, the slowest devices and GPUs) or the App Store (hang rate, launch time, animation hitches, hang signatures) measured of each version, next to what Glitchless measured, and where the two disagree |
94
- | `glitchless_revenue` | For a game connected to RevenueCat (Glitchless Cloud): its real revenue (production purchases only) by day, installs (new customers) and active users, MRR, active subscriptions and trials, revenue per player measured, and revenue by version where RevenueCat splits it, next to the sessions, players and new players Glitchless measured and what the game's own purchase events add up to |
94
+ | `glitchless_revenue` | For a game connected to RevenueCat or to its own Stripe account (Glitchless Cloud; `source` picks one, else both): its real revenue by day and revenue per player measured. RevenueCat's (production purchases only): installs (new customers) and active users, MRR, active subscriptions and trials, and revenue by version where RevenueCat splits it. Stripe's: refunds, disputes, fees and net, new paying customers, revenue by product, and by version and platform for purchases the game tied to a session. All next to the sessions, players and new players Glitchless measured and what the game's own purchase events add up to |
95
95
  | `glitchless_playtest` | Autoplay bots play the game and compare with a saved baseline ([glitchless-playtest](https://www.npmjs.com/package/glitchless-playtest); needs Playwright in the game project) |
96
96
  | `glitchless_deck_send` | Build the game, send it to the paired Steam Deck, add it to the Deck's library and optionally start it ([glitchless-deck](https://www.npmjs.com/package/glitchless-deck); pair once with `npx glitchless-deck pair`) |
97
97
  | `glitchless_deck_measure` | Measure a Unity, Godot or Unreal build on the Steam Deck and compare it with a saved run |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitchless-mcp",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "mcpName": "io.github.glitchless-gg/glitchless",
5
5
  "description": "Game observability and analytics MCP server for Unity, Godot, Unreal, Three.js, Phaser and GameMaker games. Coding agents (Claude Code, Codex, Cursor and others) read your players' stutters, crashes, custom metrics and ranked findings, build the game's own dashboard, and run playtest bots.",
6
6
  "keywords": [
package/src/context.js CHANGED
@@ -34,10 +34,10 @@ export function useCredentials({ url, token }) {
34
34
  }
35
35
 
36
36
  export const server = new McpServer(
37
- { name: 'glitchless', version: '0.7.1' },
37
+ { name: 'glitchless', version: '0.8.0' },
38
38
  {
39
39
  instructions:
40
- 'Glitchless is observability for games made with Three.js, Phaser, Babylon.js, PlayCanvas, Unity, Godot, Unreal or GameMaker. On Glitchless Cloud, glitchless_sign_in connects you to the person\'s whole workspace (they approve a code in the browser): then glitchless_list_games lists every game, glitchless_create_game makes one and hands back its client token, every tool takes game (by name), and glitchless_share_board makes a read-only link to a board. Start with glitchless_triage to get ranked, evidence-backed findings for a game, then drill in with glitchless_performance, glitchless_get_error, glitchless_death_hotspots or glitchless_session. When players or playtesters send bug reports from inside the game (an F8 form or a button), glitchless_bug_reports lists them with what they wrote, the level and where they stood, and opens one with its screenshot. For metrics the game defines itself (what it sends with track(): plays, purchases, paywall views and so on) and funnels between them, use glitchless_events. For a game connected to a store (Steam, Google Play, the App Store), glitchless_store_reviews reads what players wrote there by build, with the hardware and Steam Deck playtime reviewers show, next to what Glitchless measured on that build, and glitchless_store_vitals what the store itself measured (slow rendering, crashes, ANRs, hangs) next to Glitchless, version by version. For a game connected to RevenueCat, glitchless_revenue reads its real revenue (production purchases only) by day and by version, installs and active users, next to the sessions, players and new players Glitchless measured and what the game\'s own purchase events add up to. Each game has its own dashboard, a list of pages (boards of panels, and built-in views such as Errors, Sessions and Live Tail): read it with glitchless_dashboard, and after instrumenting a game, design one that fits it with glitchless_set_dashboard. Before changing game code, run glitchless_playtest with save_as "baseline"; after the change, run glitchless_playtest again to compare, and treat a FAIL as unfinished work. After shipping a fix (bump the version passed to Glitchless.init), use glitchless_compare_versions to confirm it with real players. If the game is running in a browser with WebMCP connected, its live tools (glitchless_live_performance, glitchless_measure, glitchless_inspect_scene, and game tools such as zoomies_load_level) let you reproduce and measure issues directly. Unity, Godot, Unreal and GameMaker builds measure themselves when run with --glitchless-measure=SECONDS (-glitchless-measure in Unreal and GameMaker); in the Unreal editor, Unreal MCP with the Glitchless Toolset has a Measure tool.',
40
+ 'Glitchless is observability for games made with Three.js, Phaser, Babylon.js, PlayCanvas, Unity, Godot, Unreal or GameMaker. On Glitchless Cloud, glitchless_sign_in connects you to the person\'s whole workspace (they approve a code in the browser): then glitchless_list_games lists every game, glitchless_create_game makes one and hands back its client token, every tool takes game (by name), and glitchless_share_board makes a read-only link to a board. Start with glitchless_triage to get ranked, evidence-backed findings for a game, then drill in with glitchless_performance, glitchless_get_error, glitchless_death_hotspots or glitchless_session. When players or playtesters send bug reports from inside the game (an F8 form or a button), glitchless_bug_reports lists them with what they wrote, the level and where they stood, and opens one with its screenshot. For metrics the game defines itself (what it sends with track(): plays, purchases, paywall views and so on) and funnels between them, use glitchless_events. For a game connected to a store (Steam, Google Play, the App Store), glitchless_store_reviews reads what players wrote there by build, with the hardware and Steam Deck playtime reviewers show, next to what Glitchless measured on that build, and glitchless_store_vitals what the store itself measured (slow rendering, crashes, ANRs, hangs) next to Glitchless, version by version. For a game connected to RevenueCat or to its own Stripe account, glitchless_revenue reads its real revenue by day, version and country (RevenueCat: production purchases only, by store too, installs and active users; Stripe: refunds, fees, net, new paying customers and revenue by product), next to the sessions, players and new players Glitchless measured and what the game\'s own purchase events add up to. Each game has its own dashboard, a list of pages (boards of panels, and built-in views such as Errors, Sessions and Live Tail): read it with glitchless_dashboard, and after instrumenting a game, design one that fits it with glitchless_set_dashboard. Before changing game code, run glitchless_playtest with save_as "baseline"; after the change, run glitchless_playtest again to compare, and treat a FAIL as unfinished work. After shipping a fix (bump the version passed to Glitchless.init), use glitchless_compare_versions to confirm it with real players. If the game is running in a browser with WebMCP connected, its live tools (glitchless_live_performance, glitchless_measure, glitchless_inspect_scene, and game tools such as zoomies_load_level) let you reproduce and measure issues directly. Unity, Godot, Unreal and GameMaker builds measure themselves when run with --glitchless-measure=SECONDS (-glitchless-measure in Unreal and GameMaker); in the Unreal editor, Unreal MCP with the Glitchless Toolset has a Measure tool.',
41
41
  },
42
42
  );
43
43
 
@@ -26,17 +26,17 @@ const panelSchema = z
26
26
  note: z.string().optional().describe('One line on why this panel matters'),
27
27
  size: z.enum(['s', 'm', 'l']).optional().describe('s = a quarter row (stats), m = half, l = full width'),
28
28
  metric: z.string().optional().describe('stat: sessions, players, avg_session_s, crash_free_pct, error_free_pct, frame_p95, avg_fps, hitches_per_min, errors, deaths, rage_quit_pct or players_now (sessions playing in the last two minutes, whatever the range)'),
29
- event: z.string().optional().describe('stat, series, breakdown: one event, "name", "name=value" or "name:key=value"'),
29
+ event: z.string().optional().describe('stat, series, breakdown: one event, "name", "name=value" or "name:key=value". A series or breakdown by $platform, $browser or $device_tier can leave it out: then it counts sessions (and players, with player IDs) in each'),
30
30
  sum: z.string().optional().describe('stat, series, breakdown: add up this numeric attribute instead of counting events, e.g. "amount" of "purchase" for revenue. Money (events with a currency) shows in the game\'s currency; amounts in another currency are named, not added'),
31
31
  per: z.string().optional().describe('stat: divide by this event to get a percentage (event "buy=done" per "paywall"); or "$players" / "$sessions": the share of them that sent the event (conversion), or with sum, the sum per player or session (revenue per player)'),
32
- by: z.string().optional().describe('series, breakdown: the attribute to split by, e.g. "mode" or "what", or $version / $level. With sum and an attribute, event is a name only. A breakdown (by count) can also split by a Steam fact of the sessions that sent the event: $steam_branch, $steam_build, $steam_hardware, $steam_controller, $steam_language, $proton, $big_picture, $family_shared, $timed_trial. versions: $steam_branch or $steam_build compares Steam branches or builds on this page\'s stats instead of versions (the beta against "public"); needs a game that uses Steamworks'),
32
+ by: z.string().optional().describe('series, breakdown: the attribute to split by, e.g. "mode" or "what", or $version / $level, or a split of the sessions that sent the event: $platform (Windows, macOS, Linux, Steam Deck, iOS, Android, Web…), $browser (Chrome, Safari, Firefox, Edge…; a native build is "Godot app", "Unity app" and so on, a web build "Unity web build"), $device_tier (High-end, Mid-range, Low-end GPU, Software rendering: the tiers the Performance view uses, high to low); counts only, no sum, over 31 days or less. With sum and an attribute, event is a name only. A breakdown (by count) can also split by a Steam fact of the sessions that sent the event: $steam_branch, $steam_build, $steam_hardware, $steam_controller, $steam_language, $proton, $big_picture, $family_shared, $timed_trial. versions: $steam_branch or $steam_build compares Steam branches or builds on this page\'s stats instead of versions (the beta against "public"); needs a game that uses Steamworks'),
33
33
  limit: z.number().int().optional().describe('How many: errors, findings, reports and breakdown rows up to 20, sessions up to 50, series lines up to 8, retention days up to 90 (default 14)'),
34
34
  steps: z.string().optional().describe('funnel: events in order, comma-separated, e.g. "paywall,buy=tapped,buy=done"'),
35
35
  label: z.string().optional().describe('levels: what the game calls a level, e.g. "Stop" or "Puzzle"'),
36
36
  sent: z.string().optional().describe('sessions: only sessions that sent this event, e.g. "buy=done"'),
37
37
  events: z.array(z.string()).optional().describe('live: only these event names or types, e.g. ["buy", "paywall", "error"]'),
38
38
  level: z.string().optional().describe('positions (required): the level id, as the game passes it to levelStart'),
39
- show: z.enum(['deaths', 'path', 'both']).optional().describe('positions: deaths (default), path (where players went, on a coarser grid) or both'),
39
+ show: z.enum(['deaths', 'path', 'both', 'installs', 'revenue']).optional().describe('positions: deaths (default), path (where players went, on a coarser grid) or both. store_revenue by_country: installs (default) or revenue, what its map shows first (people can switch)'),
40
40
  bin: z.number().positive().optional().describe("positions: a bin's width in world units (default about a hundredth of the level). Fix it when a game draws the panel, so bins don't move as the level fills in"),
41
41
  })
42
42
  .describe('One panel');
@@ -47,14 +47,15 @@ const STORE_PANELS = {
47
47
  store_vitals: "the store's own vitals by version (Google Play: slow rendering, crashes, ANRs; the App Store: hangs, launch, hitches) next to what Glitchless measured, with where they disagree",
48
48
  store_players: 'players online next to the sessions measured: telemetry coverage',
49
49
  store_sales: 'units, returns and wishlists by day; on Steam needs the Financial API key',
50
- store_revenue: "real revenue from RevenueCat (store revenuecat; give measure): revenue in the window, revenue per player measured, installs (RevenueCat's new customers) next to Glitchless's new players, active users a day, MRR, active subscriptions, active trials, revenue per day next to the game's own purchase events, installs and active users per day, or revenue by version next to what Glitchless measured",
50
+ store_score: "a store's rating, small (size s): the average stars of the written reviews synced in the window and how many, next to the store's own overall rating where it has one (the App Store: Apple's rating and rating count; Steam: its review summary). Google Play has no API for its overall rating, so it shows the synced reviews' average and says so. One panel per store",
51
+ store_revenue: "real revenue from RevenueCat (store revenuecat) or the game's own Stripe account (store stripe); give measure: revenue in the window, revenue per player measured, revenue per day next to the game's own purchase events, revenue by version next to what Glitchless measured, or a world map of revenue by country with a ranked list (by_country, size l); RevenueCat also installs (its new customers) next to Glitchless's new players, active users a day, MRR, active subscriptions, active trials, installs and active users per day, installs on the map, and revenue by store (App Store, Google Play) next to the iOS and Android sessions Glitchless measured (by_store); Stripe also refunds (and disputes), new paying customers and revenue by product (by version from the purchases the game tied to a session)",
51
52
  };
52
53
  const withStores = (panel) =>
53
54
  panel
54
55
  .extend({
55
56
  type: z.enum([...panel.shape.type.options, ...Object.keys(STORE_PANELS)]).describe(`${panel.shape.type.description} For a game connected to a store (Steam; give store): ${Object.entries(STORE_PANELS).map(([t, d]) => `${t} (${d})`).join(', ')}`),
56
- store: z.enum(['steam', 'app_store', 'google_play', 'revenuecat']).optional().describe("store_reviews, store_players, store_sales, store_vitals: the store (default: the game's first connected one); store_revenue: revenuecat"),
57
- measure: z.enum(['revenue', 'per_player', 'installs', 'active_users', 'mrr', 'actives', 'trials', 'by_day', 'players_by_day', 'by_version']).optional().describe('store_revenue (required): revenue (in the window), per_player (over the players Glitchless measured), installs (new customers, next to Glitchless\'s new players), active_users (a day), mrr, actives (active subscriptions), trials (active trials), by_day (revenue), players_by_day (installs and active users), by_version'),
57
+ store: z.enum(['steam', 'app_store', 'google_play', 'revenuecat', 'stripe']).optional().describe("store_reviews, store_players, store_sales, store_vitals, store_score: the store (default: the game's first connected one); store_revenue: revenuecat or stripe"),
58
+ measure: z.enum(['revenue', 'per_player', 'installs', 'active_users', 'mrr', 'actives', 'trials', 'by_day', 'players_by_day', 'by_version', 'by_country', 'by_store', 'refunds', 'customers', 'by_product']).optional().describe('store_revenue (required): revenue (in the window), per_player (over the players Glitchless measured), by_day (revenue), by_version, by_country (a world map of installs and revenue, and a list: country, installs, revenue, purchases; RevenueCat\'s countries are read once a day, Stripe\'s have revenue only); RevenueCat only: installs (new customers, next to Glitchless\'s new players), active_users (a day), mrr, actives (active subscriptions), trials (active trials), players_by_day (installs and active users), by_store (revenue by store next to the sessions on its platform); Stripe only: refunds (and disputes), customers (new paying customers), by_product'),
58
59
  })
59
60
  .describe('One panel');
60
61
 
@@ -73,7 +74,7 @@ server.registerTool(
73
74
  'glitchless_set_dashboard',
74
75
  {
75
76
  description:
76
- "Save the game's dashboard: its pages, in the order the sidebar shows them. Each page is a board of panels in the game's own words, or a built-in view (events, performance, errors, players, heatmaps, sessions, versions, live, reports) the game keeps, renames or drops. Design it for this game, not for a genre it isn't: a puzzle game cares about solve time and hints, a mobile game about opens, modes, the paywall and purchases (revenue: a stat with sum \"amount\" of \"purchase\"; revenue per player: per \"$players\"; conversion: event \"purchase\" per \"$players\"; revenue by item: a breakdown with sum), a platformer about deaths per level (and a positions panel for where on a level they die). The first page opens first. Use the events the game sends (glitchless_events lists them, with their attributes); on a board, stats first, then the game's own events and funnels, then levels, frame_time and errors. Leave out what the game has no data for (no Heatmaps page for a game without positions, no reports page for a game that doesn't turn bug reports on). Send every page: read the current ones with glitchless_dashboard (its spec), change them, send them all back. Pass reset: true to go back to the automatic dashboard. Needs a secret key with the dashboard scope.",
77
+ "Save the game's dashboard: its pages, in the order the sidebar shows them. Each page is a board of panels in the game's own words, or a built-in view (events, performance, errors, players, heatmaps, sessions, versions, live, reports) the game keeps, renames or drops. Design it for this game, not for a genre it isn't: a puzzle game cares about solve time and hints, a mobile game about opens, modes, the paywall and purchases (revenue: a stat with sum \"amount\" of \"purchase\"; revenue per player: per \"$players\"; conversion: event \"purchase\" per \"$players\"; revenue by item: a breakdown with sum), a platformer about deaths per level (and a positions panel for where on a level they die). For a game on several platforms, a breakdown by $platform splits players or an event between them (iOS vs Android, PC vs Mac vs Steam Deck); a web game splits by $browser, and any game by $device_tier. The first page opens first. Use the events the game sends (glitchless_events lists them, with their attributes); on a board, stats first, then the game's own events and funnels, then levels, frame_time and errors. Leave out what the game has no data for (no Heatmaps page for a game without positions, no reports page for a game that doesn't turn bug reports on). Send every page: read the current ones with glitchless_dashboard (its spec), change them, send them all back. Pass reset: true to go back to the automatic dashboard. Needs a secret key with the dashboard scope.",
77
78
  inputSchema: {
78
79
  service: z.string().optional().describe('Game service name (defaults to the most recently active game)'),
79
80
  pages: z.array(pageSchema).optional(),
@@ -1,40 +1,74 @@
1
- // A game's real revenue from RevenueCat (Glitchless Cloud: Settings → Integrations → RevenueCat), by day and by app
2
- // version where RevenueCat splits it, next to the sessions and players Glitchless measured and what the game's own
3
- // purchase events add up to.
1
+ // A game's real revenue from RevenueCat or Stripe (Glitchless Cloud: Settings → Integrations), by day, and by app
2
+ // version, country and store where the source splits it (RevenueCat) or by version where the game tied its purchases
3
+ // to sessions and by country (Stripe), next to the sessions and players Glitchless measured and what the game's own
4
+ // purchase events add up to. A game connected to both gets both, one after the other, unless `source` picks one.
4
5
  import { z } from 'zod';
5
6
  import { query, resolveService, range, reply, common, filters, tool } from '../context.js';
6
7
 
7
8
  tool(
8
9
  'glitchless_revenue',
9
- "The game's real revenue, installs and active users as RevenueCat counts them, for a game connected to RevenueCat in Glitchless Cloud (Settings → Integrations). RevenueCat counts production purchases only, never sandbox, TestFlight or licence-tester ones. It gives, for the window, revenue and transactions by UTC day, MRR, active subscriptions and trials, and revenue per player Glitchless measured. It also gives installs (RevenueCat's new customers: the first time its SDK starts on a device) next to the new players Glitchless saw, and active users a day next to Glitchless's players a day. Where RevenueCat splits revenue by the app version purchases were made on, it gives revenue by version too. Each day sits next to its sessions and players, and each version next to its players, crash-free sessions and frame-time p95. It also says what the game's own purchase events (track('purchase', { amount, currency })) add up to and how much of RevenueCat's revenue that is: the gap is purchases that never reach Glitchless. Use it for money questions, e.g. whether 1.4.2 earns more per player than 1.4.1. Use glitchless_events for purchases by item, level or player.",
10
+ "The game's real revenue as RevenueCat or Stripe counts it, for a game connected to either in Glitchless Cloud (Settings → Integrations); a game with both gets both unless source picks one. RevenueCat counts production purchases only (never sandbox, TestFlight or licence-tester ones): revenue and transactions by UTC day, MRR, active subscriptions and trials, installs (its new customers: the first time its SDK starts on a device) next to the new players Glitchless saw, active users a day next to Glitchless's players a day, and, where RevenueCat splits them, revenue by the app version purchases were made on, installs, revenue and purchases by country, and revenue by store (App Store, Google Play) next to the sessions Glitchless measured on iOS and Android. Stripe is the game's own account (a web or PC game's unlock, DLC, supporter packs; a test-mode key says so): revenue by UTC day with refunds, disputes, Stripe's fees and net, new paying customers, revenue by product and by country, and revenue by version and platform for the purchases the game tied to a Glitchless session or player (client_reference_id, or glitchless_session / glitchless_player metadata), with how many players paid. Both give revenue per player Glitchless measured, each day next to its sessions and players, each version next to its players, crash-free sessions and frame-time p95, and what the game's own purchase events (track('purchase', { amount, currency })) add up to: the gap is purchases that never reach Glitchless. Use it for money questions, e.g. whether 1.4.2 earns more per player than 1.4.1, or which DLC gets refunded. Use glitchless_events for purchases by item, level or player.",
10
11
  {
11
12
  service: common.service,
13
+ source: z.enum(['revenuecat', 'stripe']).optional().describe('Only this revenue source (default: every one the game is connected to)'),
12
14
  hours: z.number().min(24).max(9600).optional().describe('Look-back window in hours (default 720, 30 days), read as whole UTC days'),
13
- version: z.string().optional().describe("Only this version: its revenue (where RevenueCat splits revenue by version) over its players. MRR, subscriptions and trials stay the whole game's"),
15
+ version: z.string().optional().describe("Only this version: its revenue (where RevenueCat splits revenue by version, or Stripe's purchases joined to that version's sessions) over its players. MRR, subscriptions and trials, and Stripe's refunds and fees, stay the whole game's"),
14
16
  env: common.env,
15
17
  session_type: common.session_type,
16
18
  },
17
- async ({ service, hours, version, env, session_type }) => {
19
+ async ({ service, source, hours, version, env, session_type }) => {
18
20
  const svc = await resolveService(service);
19
- const r = await query('store_revenue', { service: svc, ...filters({ version, env, session_type }), ...range(hours || 720) });
20
- if (r.connected === false) return reply(`${svc}: ${r.why}`, {});
21
- if (r.empty) return reply(`${r.store_name} revenue of ${svc}: ${r.why}`, { overview: r.overview?.metrics ?? null });
22
- const money = (v) => (v == null ? '–' : r.currency ? new Intl.NumberFormat('en-US', { style: 'currency', currency: r.currency }).format(v) : String(v));
23
- const n = (v) => (v == null ? '–' : v.toLocaleString('en-US'));
24
- const t = r.totals;
25
- const stock = (x, label, isMoney = false) => (x ? `${isMoney ? money(x.value) : n(x.value)} ${label}${x.change != null ? ` (${x.change >= 0 ? '+' : '−'}${isMoney ? money(Math.abs(x.change)) : n(Math.abs(x.change))} since ${x.since})` : ''}` : null);
26
- const g = r.glitchless;
27
- const lines = [
28
- `${r.store_name} revenue of ${svc} (project ${r.app_id}), ${r.from_day} to ${r.to_day} (UTC days)${r.version ? `, version ${r.version}` : ''}: ${money(t.revenue)}${t.transactions != null ? ` from ${n(t.transactions)} transactions` : ''}${t.incomplete ? ' (today so far included)' : ''}.`,
29
- r.per_player != null ? `Revenue per player: ${money(r.per_player)} over ${n(r.players)} ${r.players_are_sessions ? 'sessions (no player IDs)' : 'players'} Glitchless measured (${n(r.sessions)} sessions).` : `Glitchless measured no players in this window.`,
30
- `Installs (${r.store_name}'s new customers): ${n(t.installs)}${r.new_players != null ? `; Glitchless saw ${n(r.new_players)} new players (${r.new_players_pct ?? '–'}%)` : '; Glitchless counts new players only with player IDs'}. Active users: ${t.active_users_per_day != null ? `${n(t.active_users_per_day)} a day` : '–'}${r.players_per_day != null ? `; Glitchless measured ${n(r.players_per_day)} players a day` : ''}.`,
31
- `Now: ${[stock(r.latest.mrr, 'MRR', true), stock(r.latest.actives, 'active subscriptions'), stock(r.latest.trials, 'active trials')].filter(Boolean).join(', ') || 'no MRR, subscriptions or trials yet'}.`,
32
- g ? `The game's own purchase events: ${g.comparable ? money(g.purchases) : `${g.purchases} ${g.currency ?? ''}`.trim()} from ${n(g.events)} events${g.coverage_pct != null ? ` (${g.coverage_pct}% of ${r.store_name}'s)` : ''}${g.sandbox ? `; ${n(g.sandbox)} sandbox purchases left out` : ''}.` : 'The game sends no purchase events with an amount.',
33
- r.versions?.length
34
- ? `By version:\n${r.versions.map((v) => `- ${v.version}: ${money(v.revenue)} (${v.share_pct}%), ${n(v.transactions)} transactions; ${v.players != null ? `${n(v.players)} players, ${money(v.per_player)} per player, crash-free ${v.crash_free_pct ?? '–'}%, frame p95 ${v.frame_p95 ?? '–'}ms` : 'no sessions of it in the window'}${v.purchases != null ? `; purchase events ${money(v.purchases)}` : ''}`).join('\n')}`
35
- : `By version: ${r.versions_why ?? 'none in this window'}`,
36
- ...(r.notes?.length ? [`Notes:\n${r.notes.map((x) => `- ${x}`).join('\n')}`] : []),
37
- ];
38
- return reply(lines.join('\n'), { days: r.days, versions: r.versions, overview: r.overview?.metrics ?? null });
21
+ const ask = (store) => query('store_revenue', { service: svc, ...(store ? { store } : {}), ...filters({ version, env, session_type }), ...range(hours || 720) });
22
+ const first = await ask(source);
23
+ if (first.connected === false) return reply(`${svc}: ${first.why}`, {});
24
+ const rest = source ? [] : await Promise.all((first.sources ?? []).filter((s) => s !== first.store).map((s) => ask(s)));
25
+ const all = [first, ...rest].filter((r) => r.connected !== false);
26
+ const parts = all.map((r) => describe(svc, r));
27
+ return reply(parts.map((p) => p.text).join('\n\n'), all.length === 1 ? parts[0].data : Object.fromEntries(all.map((r, i) => [r.store, parts[i].data])));
39
28
  },
40
29
  );
30
+
31
+ function describe(svc, r) {
32
+ if (r.empty) return { text: `${r.store_name} revenue of ${svc}: ${r.why}`, data: { overview: r.overview?.metrics ?? null } };
33
+ const money = (v) => (v == null ? '–' : r.currency ? new Intl.NumberFormat('en-US', { style: 'currency', currency: r.currency }).format(v) : String(v));
34
+ const n = (v) => (v == null ? '–' : v.toLocaleString('en-US'));
35
+ const t = r.totals;
36
+ const g = r.glitchless;
37
+ const perPlayer = r.per_player != null ? `Revenue per player: ${money(r.per_player)} over ${n(r.players)} ${r.players_are_sessions ? 'sessions (no player IDs)' : 'players'} Glitchless measured (${n(r.sessions)} sessions).` : `Glitchless measured no players in this window.`;
38
+ const own = g ? `The game's own purchase events: ${g.comparable ? money(g.purchases) : `${g.purchases} ${g.currency ?? ''}`.trim()} from ${n(g.events)} events${g.coverage_pct != null ? ` (${g.coverage_pct}% of ${r.store_name}'s)` : ''}${g.sandbox ? `; ${n(g.sandbox)} sandbox purchases left out` : ''}.` : 'The game sends no purchase events with an amount.';
39
+ const versionLine = (v) => `- ${v.version}: ${money(v.revenue)} (${v.share_pct}%), ${n(v.transactions)} ${r.store === 'stripe' ? 'payments' : 'transactions'}; ${v.players != null ? `${n(v.players)} players, ${money(v.per_player)} per player, crash-free ${v.crash_free_pct ?? '–'}%, frame p95 ${v.frame_p95 ?? '–'}ms` : 'no sessions of it in the window'}${v.purchases != null ? `; purchase events ${money(v.purchases)}` : ''}`;
40
+ const versions = r.versions?.length ? `By version:\n${r.versions.map(versionLine).join('\n')}` : `By version: ${r.versions_why ?? 'none in this window'}`;
41
+ const notes = r.notes?.length ? [`Notes:\n${r.notes.map((x) => `- ${x}`).join('\n')}`] : [];
42
+ const countries = r.countries?.length
43
+ ? `By country${r.countries_as_of && r.countries_as_of < r.to_day ? ` (to ${r.countries_as_of})` : ''}: ${r.countries.slice(0, 10).map((c) => `${c.name} ${c.installs != null ? `${n(c.installs)} installs, ` : ''}${money(c.revenue)} from ${n(c.purchases)} ${r.store === 'stripe' ? 'payments' : 'purchases'}`).join('; ')}${r.countries.length > 10 ? `; ${r.countries.length - 10} more in the data` : ''}.`
44
+ : `By country: ${r.countries_why ?? 'none in this window'}`;
45
+ if (r.store === 'stripe') {
46
+ const lines = [
47
+ `${r.store_name} revenue of ${svc}${r.products_picked ? ` (products: ${r.products_picked})` : ''}, ${r.from_day} to ${r.to_day} (UTC days)${r.version ? `, version ${r.version}` : ''}: ${money(t.revenue)} from ${n(t.transactions)} payments${t.incomplete ? ' (today so far included)' : ''}; refunds ${money(t.refunds)} (${n(t.refund_count)}), disputes ${money(t.disputes)}, Stripe's fees ${money(t.fees)}, net ${money(t.net)}.`,
48
+ perPlayer,
49
+ `New paying customers: ${n(t.new_customers)}${r.new_players != null ? `; Glitchless saw ${n(r.new_players)} new players` : ''}${r.payers != null ? `. Players who paid, among those measured: ${n(r.payers)}${r.payers_pct != null ? ` (${r.payers_pct}%)` : ''}` : ''}.`,
50
+ own,
51
+ r.products?.length ? `By product:\n${r.products.map((p) => `- ${p.name}${p.product !== '(none)' ? ` (${p.product})` : ''}: ${money(p.revenue)} (${p.share_pct}%), ${n(p.transactions)} payments${p.refunds ? `; refunded ${money(p.refunds)} (${n(p.refund_count)})` : ''}`).join('\n')}` : `By product: ${r.products_why ?? 'none in this window'}`,
52
+ versions,
53
+ ...(r.platforms?.length ? [`By platform (tied purchases): ${r.platforms.map((p) => `${p.platform} ${money(p.revenue)} (${n(p.purchases)})`).join(', ')}`] : []),
54
+ countries,
55
+ ...notes,
56
+ ];
57
+ return { text: lines.join('\n'), data: { days: r.days, products: r.products, versions: r.versions, platforms: r.platforms ?? null, countries: r.countries ?? null, overview: r.overview?.metrics ?? null } };
58
+ }
59
+ const stock = (x, label, isMoney = false) => (x ? `${isMoney ? money(x.value) : n(x.value)} ${label}${x.change != null ? ` (${x.change >= 0 ? '+' : '−'}${isMoney ? money(Math.abs(x.change)) : n(Math.abs(x.change))} since ${x.since})` : ''}` : null);
60
+ const lines = [
61
+ `${r.store_name} revenue of ${svc} (project ${r.app_id}), ${r.from_day} to ${r.to_day} (UTC days)${r.version ? `, version ${r.version}` : ''}: ${money(t.revenue)}${t.transactions != null ? ` from ${n(t.transactions)} transactions` : ''}${t.incomplete ? ' (today so far included)' : ''}.`,
62
+ perPlayer,
63
+ `Installs (${r.store_name}'s new customers): ${n(t.installs)}${r.new_players != null ? `; Glitchless saw ${n(r.new_players)} new players (${r.new_players_pct ?? '–'}%)` : '; Glitchless counts new players only with player IDs'}. Active users: ${t.active_users_per_day != null ? `${n(t.active_users_per_day)} a day` : '–'}${r.players_per_day != null ? `; Glitchless measured ${n(r.players_per_day)} players a day` : ''}.`,
64
+ `Now: ${[stock(r.latest.mrr, 'MRR', true), stock(r.latest.actives, 'active subscriptions'), stock(r.latest.trials, 'active trials')].filter(Boolean).join(', ') || 'no MRR, subscriptions or trials yet'}.`,
65
+ own,
66
+ versions,
67
+ countries,
68
+ r.stores?.length
69
+ ? `By store: ${r.stores.map((x) => `${x.name} ${money(x.revenue)} (${x.share_pct}%), ${n(x.purchases)} purchases${x.platform ? `; ${x.sessions != null ? `${n(x.sessions)} ${x.platform} sessions` : `${x.platform} sessions not counted over 31 days`}${x.per_player != null ? `, ${money(x.per_player)} per ${r.players_are_sessions ? 'session' : 'player'}` : ''}` : ''}`).join('; ')}.`
70
+ : `By store: ${r.stores_why ?? 'none in this window'}`,
71
+ ...notes,
72
+ ];
73
+ return { text: lines.join('\n'), data: { days: r.days, versions: r.versions, countries: r.countries, stores: r.stores, overview: r.overview?.metrics ?? null } };
74
+ }