Skip to content

Commit 091e877

Browse files
phasenullclaude
andcommitted
Analytics: the player policy (pol_*) on the join row, Player.DeviceTrustLevel (trust) on the join and leave rows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 50ec39e commit 091e877

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ const variant = analytics.experiment("onboarding", ["short", "long"]); // same a
490490
economy are server-authoritative): on the client they warn once and send nothing, and the server refuses them from
491491
clients.
492492
- **Options** (all on by default): `sessions` (joins, leaves, device, join source, account age bucket, Premium,
493-
country, friends in the server, first-ever vs returning, days since the last visit), `tech` (FPS, ping, memory, load
493+
country, the player policy, device trust, friends in the server, first-ever vs returning, days since the last visit), `tech` (FPS, ping, memory, load
494494
time, client and server errors, swaps and rollbacks, leaves within 60 s of a swap), `zones` (parts or models tagged
495495
`TTZone`, named by a `Name` attribute or the instance name), `screens` (ScreenGuis in PlayerGui, GuiObjects tagged
496496
`TTScreen`), `recording` (the first-ever session in detail), `fleet` (kernel 0.3.2 heartbeats and deploy reports),

‎src/analytics/SCHEMA.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ First-ever-session detail, one row per packed chunk.
5757

5858
| kind | name | props |
5959
|---|---|---|
60-
| session | `join` | `from`: `direct` (Home, search, sorts: Roblox doesn't say), `teleport` (same game), `teleport_game` (another game), `referral` (invite/referral link), `notification` (a TypeTorch notification's launch data verified), `share` (other launch data), `follow` (followed someone); join metadata (plans/29): `src_place?`, `src_game?` (SourcePlaceId / SourceGameId), `ref?` / `follow?` (the referrer / followed user as their pid when this game knows them, else `"other"`: never a UserId; players in the server are free, others cost one DataStore read each, at most 2 per join and only with read budget to spare), `party?` (players teleported along) + `party_pids?` (the pids of those this game knows, at most 10), `ctx?`, `ctx_item?`, `ctx_asset?`, `ctx_outfit?`, `ctx_asset_type?` (GameJoinContext JoinSource / ItemType / AssetId / OutfitId / AssetType), `launch?` (`notification` + `nid`, `nk` (kind); `tt_bad` + `launch_bad` (`format`, `sig`, `user`, `old`); or the game's own launch data: `launch_len`, plus its first 32 chars in `launch` only with the settings' `joinLaunchPrefix`), `tp?` + `tp_bytes?` (TeleportData present, its JSON size; never the content), `age_days` (exact account age), `locale?`, `verified?` (HasVerifiedBadge), `membership` (MembershipType name); `age` (account age: `<1d`, `1-7d`, `7-30d`, `30-90d`, `90-365d`, `1-3y`, `3y+`); `prem` (Premium); `country?` (ISO code); `friends` (how many of the player's friends are in the server: one friend-list lookup per join, at most 10 pages, `0` when it fails); `ret` (days since the last visit, `-1` first visit or unknown); `late?` (the engine started over 60 s after the join); `jd?` (plans/30, with the settings' `joinData` `"full"`, the default: the raw join data, below). With `joinData` `"off"` only `from`, `ctx`, `tp`, `party`, `age`, `prem`, `country`, `friends`, `ret`, `late` are written. `t` is the join time |
60+
| session | `join` | `from`: `direct` (Home, search, sorts: Roblox doesn't say), `teleport` (same game), `teleport_game` (another game), `referral` (invite/referral link), `notification` (a TypeTorch notification's launch data verified), `share` (other launch data), `follow` (followed someone); join metadata (plans/29): `src_place?`, `src_game?` (SourcePlaceId / SourceGameId), `ref?` / `follow?` (the referrer / followed user as their pid when this game knows them, else `"other"`: never a UserId; players in the server are free, others cost one DataStore read each, at most 2 per join and only with read budget to spare), `party?` (players teleported along) + `party_pids?` (the pids of those this game knows, at most 10), `ctx?`, `ctx_item?`, `ctx_asset?`, `ctx_outfit?`, `ctx_asset_type?` (GameJoinContext JoinSource / ItemType / AssetId / OutfitId / AssetType), `launch?` (`notification` + `nid`, `nk` (kind); `tt_bad` + `launch_bad` (`format`, `sig`, `user`, `old`); or the game's own launch data: `launch_len`, plus its first 32 chars in `launch` only with the settings' `joinLaunchPrefix`), `tp?` + `tp_bytes?` (TeleportData present, its JSON size; never the content), `age_days` (exact account age), `locale?`, `verified?` (HasVerifiedBadge), `membership` (MembershipType name); `age` (account age: `<1d`, `1-7d`, `7-30d`, `30-90d`, `90-365d`, `1-3y`, `3y+`); `prem` (Premium); `country?` (ISO code); `pol` (the player policy, PolicyService:GetPolicyInfoForPlayerAsync with a 5 s deadline: `ok`, `failed`, `timeout`) and with `ok` `pol_ads`, `pol_rand` (ArePaidRandomItemsRestricted), `pol_trade` (IsPaidItemTradingAllowed), `pol_share` (IsContentSharingAllowed), `pol_subs` (IsEligibleToPurchaseSubscription), `pol_cn` (IsSubjectToChinaPolicies), `pol_links` (AllowedExternalLinkReferences, comma separated); `trust?` (Player.DeviceTrustLevel at the join, usually `Pending`: the leave row has the settled level); `friends` (how many of the player's friends are in the server: one friend-list lookup per join, at most 10 pages, `0` when it fails); `ret` (days since the last visit, `-1` first visit or unknown); `late?` (the engine started over 60 s after the join); `jd?` (plans/30, with the settings' `joinData` `"full"`, the default: the raw join data, below). With `joinData` `"off"` only `from`, `ctx`, `tp`, `party`, `age`, `prem`, `country`, `friends`, `ret`, `late` are written. `t` is the join time |
6161
| session | `device` (src client) | `dev?` (the device class, as the `dev` column; frameworks after 0.4.2, older ones leave it out), `input` (`kbm`, `touch`, `gamepad`, `vr`, `unknown`), `w`, `h` (viewport points), `touch`, `kb`, `mouse`, `pad`, `vr`. Once per session. The class (Roblox gives game scripts no OS): `vr` when VRService.VREnabled; `console` when GuiService:IsTenFootInterface(); touch without a keyboard: `tablet` when the viewport's short side is 600 points or more, else `phone` (the first hello waits up to 2 s for a real viewport); a keyboard or mouse: `desktop` (touch laptops, tablets with a keyboard); else `unknown` |
6262
| notify | `want`, `drop` | Notifications (plans/29), written by the game server: `k` (kind), `key?` (first 12 hex of SHA-256 of the intent's key; never the key), `at?`, `until?`, `offline` (want: the user isn't in this server; the row then has no pid), `why?` (drop) |
6363
| notify | `optin_check`, `optin_shown`, `optin_closed` | The client's opt-in prompt, checked and written by the server (at most 3 of each per session): `where`, `can` (check), `err?` (`timeout`, `swap` or the error's first 64 chars), `secs` (closed: how long it was up) |
6464
| notify | `open`, `open_bad`, `played` | A join from a notification: `open` (`nid`, `k`, `age` (secs since sent), `first`), `open_bad` (`why`: `format`, `sig`, `user`, `old`), `played` (`nid`, `k`, `secs`: the opened session's length, at its end). Backend rows of the same kind (`planned`, `sent`, ...) come from `src = "backend"` |
65-
| session | `leave` | `secs` (session length), `why`: `left`, `shutdown`, `gone` (left while no generation ran the engine), `swap60?` (left within 60 s of a hot swap) |
65+
| session | `leave` | `secs` (session length), `why`: `left`, `shutdown`, `gone` (left while no generation ran the engine), `swap60?` (left within 60 s of a hot swap), `trust?` (Player.DeviceTrustLevel at the leave: `Pending` (never settled; always in Studio), `Unknown`, `None`, `Standard`, `Full`; missing on engines without it) |
6666
| tech | `server` | Every `techEvery` s: `fps` (physics), `hb` (Heartbeat rate), `mem` (MB, 10s), `players`, `ping50?`, `ping90?` (ms), `q`, `qr` (queued events, recordings), `dropped`, `sent`, `fails`, `health?`, `errors?` (kernel 0.3.2 health) |
6767
| tech | `client` (src client) | Every `techEvery` s: `fps`, `mem` (MB, 10s), `ping?` (ms) |
6868
| tech | `load` (src client) | `secs`: from the client starting to the engine starting (first client generation only) |

‎src/analytics/server.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
HttpService,
55
LocalizationService,
66
Players,
7+
PolicyService,
78
RunService,
89
Stats,
910
Workspace,
@@ -112,9 +113,20 @@ const RECORDING_MAX_CHUNKS = 80;
112113
const RECORDING_MAX_SECONDS = 900;
113114
/** The join event waits this long for the client's device info. */
114115
const DEVICE_WAIT = 8;
116+
/** The join event waits this long for PolicyService's answer (GetPolicyInfoForPlayerAsync has no timeout of its own). */
117+
const POLICY_WAIT = 5;
115118
const ZONE_INTERVAL = 0.5;
116119
const ZONE_TAG = "TTZone";
117120

121+
/**
122+
* Player.DeviceTrustLevel's name (Pending, Unknown, None, Standard, Full; Roblox sets it once, some time after the join,
123+
* and Studio never does), or undefined on an engine without the property. Roblox acts on none of it: data only.
124+
*/
125+
function deviceTrust(player: Player): string | undefined {
126+
const [ok, level] = pcall(() => (player as unknown as { DeviceTrustLevel: EnumItem }).DeviceTrustLevel);
127+
return ok && typeIs(level, "EnumItem") ? level.Name : undefined;
128+
}
129+
118130
interface RecordingState {
119131
/** Decided: recorded or not. */
120132
decided: boolean;
@@ -901,6 +913,38 @@ export class ServerAnalytics {
901913
return count;
902914
}
903915

916+
/**
917+
* The join's player policy (PolicyService:GetPolicyInfoForPlayerAsync): `pol` = `ok`, `failed` or `timeout` (no answer in
918+
* POLICY_WAIT s), and with `ok` the answer: `pol_ads`, `pol_rand` (paid random items restricted), `pol_trade` (paid
919+
* item trading allowed), `pol_share` (content sharing allowed), `pol_subs` (eligible to buy a subscription), `pol_cn`
920+
* (China policies), `pol_links` (the allowed external link references, comma separated, "" = none).
921+
*/
922+
private policyProps(player: Player, props: Record<string, unknown>) {
923+
let info: Record<string, unknown> | undefined;
924+
let failed = false;
925+
task.spawn(() => {
926+
const [ok, result] = pcall(() => PolicyService.GetPolicyInfoForPlayerAsync(player));
927+
if (ok && typeIs(result, "table")) info = result as unknown as Record<string, unknown>;
928+
else failed = true;
929+
});
930+
const deadline = os.clock() + POLICY_WAIT;
931+
while (info === undefined && !failed && os.clock() < deadline && player.Parent !== undefined && !this.stopped) task.wait(0.1);
932+
const answer = info as Record<string, unknown> | undefined;
933+
if (answer === undefined) {
934+
props.pol = failed ? "failed" : "timeout";
935+
return;
936+
}
937+
props.pol = "ok";
938+
props.pol_ads = answer.AreAdsAllowed === true;
939+
props.pol_rand = answer.ArePaidRandomItemsRestricted === true;
940+
props.pol_trade = answer.IsPaidItemTradingAllowed === true;
941+
props.pol_share = answer.IsContentSharingAllowed === true;
942+
props.pol_subs = answer.IsEligibleToPurchaseSubscription === true;
943+
props.pol_cn = answer.IsSubjectToChinaPolicies === true;
944+
const links = typeIs(answer.AllowedExternalLinkReferences, "table") ? (answer.AllowedExternalLinkReferences as string[]) : [];
945+
props.pol_links = links.join(",").sub(1, 120);
946+
}
947+
904948
private emitJoin(player: Player, session: PlayerSession) {
905949
const deadline = os.clock() + DEVICE_WAIT;
906950
while (session.device === undefined && os.clock() < deadline && player.Parent !== undefined && !this.stopped) task.wait(0.25);
@@ -911,6 +955,8 @@ export class ServerAnalytics {
911955
props.prem = player.MembershipType === Enum.MembershipType.Premium;
912956
const [countryOk, country] = pcall(() => LocalizationService.GetCountryRegionForPlayerAsync(player));
913957
if (countryOk) props.country = country;
958+
this.policyProps(player, props);
959+
props.trust = deviceTrust(player);
914960
props.friends = this.friendsHere(player);
915961
props.ret = session.ret;
916962
// The engine started after this player joined (created later, or added by a deploy).
@@ -956,6 +1002,7 @@ export class ServerAnalytics {
9561002
encodeProps({
9571003
secs: math.floor((now - session.joinedAt) / 1000),
9581004
why,
1005+
trust: deviceTrust(player),
9591006
swap60: lastSwap !== undefined && os.time() - lastSwap <= 60 ? true : undefined,
9601007
}),
9611008
);

0 commit comments

Comments
 (0)