Skip to content

Commit f1fd3a5

Browse files
PepperLolarutmanz
andauthored
Analytics Testing & Exploration [AARD-1937] (#1237)
Co-authored-by: Zach Rutman <92497727+rutmanz@users.noreply.github.com>
2 parents d0d95b1 + fd963e0 commit f1fd3a5

File tree

20 files changed

+1108
-885
lines changed

20 files changed

+1108
-885
lines changed

fission/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ dist-ssr
2828
*.sw?
2929

3030
yarn.lock
31+
32+
test-results
33+
src/test/**/__screenshots__

fission/biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.1.3/schema.json",
33
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
44
"files": { "ignoreUnknown": false },
55
"formatter": {

fission/bun.lock

Lines changed: 863 additions & 822 deletions
Large diffs are not rendered by default.

fission/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"colord": "^2.9.3",
3838
"framer-motion": "^10.18.0",
3939
"lygia": "^1.3.3",
40+
"msw": "^2.10.4",
4041
"notistack": "^3.0.2",
4142
"playwright": "^1.54.2",
4243
"postprocessing": "^6.37.6",

fission/src/GA.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ declare module "@haensl/google-analytics" {
77
function event(e: GaEvent)
88
function exception(e: GaException)
99
function setUserId({ id }: { id: string })
10-
function setUserProperty({ name, value }: { name: string; value: string })
10+
function setUserProperty({ name, value }: { name: string; value: unknown })
11+
function install()
1112
}

fission/src/Window.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
declare interface Window {
22
convertAuthToken(code: string): void
3-
gtag: () => void
3+
gtag?: (command: "config" | "set" | "get" | "event" | "consent", ...args: unknown[]) => void
4+
dataLayer?: unknown[][]
45
}

fission/src/mirabuf/MirabufLoader.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class MirabufCachingService {
143143
const miraBuff = await resp.arrayBuffer()
144144

145145
World.analyticsSystem?.event("Remote Download", {
146+
assemblyName: name ?? fetchLocation,
146147
type: miraType === MiraType.ROBOT ? "robot" : "field",
147148
fileSize: miraBuff.byteLength,
148149
})
@@ -283,6 +284,13 @@ class MirabufCachingService {
283284
}
284285
}
285286

287+
World.analyticsSystem?.event("Local Upload", {
288+
assemblyName: displayName,
289+
fileSize: buffer.byteLength,
290+
key,
291+
type: miraType == MiraType.ROBOT ? "robot" : "field",
292+
})
293+
286294
if (!target) {
287295
const cacheInfo = await MirabufCachingService.storeInCache(key, buffer, miraType, displayName)
288296
if (cacheInfo) {
@@ -517,7 +525,7 @@ class MirabufCachingService {
517525
window.localStorage.setItem(miraType == MiraType.ROBOT ? robotsDirName : fieldsDirName, JSON.stringify(map))
518526

519527
World.analyticsSystem?.event("Cache Store", {
520-
name: name ?? "-",
528+
assemblyName: name ?? "-",
521529
key: key,
522530
type: miraType == MiraType.ROBOT ? "robot" : "field",
523531
fileSize: miraBuff.byteLength,

fission/src/systems/analytics/AnalyticsSystem.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const SAMPLE_INTERVAL = 60000 // 1 minute
88
const BETA_CODE_COOKIE_REGEX = /access_code=.*(;|$)/
99
const MOBILE_USER_AGENT_REGEX = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
1010

11+
declare const GIT_COMMIT: string
12+
1113
export interface AccumTimes {
1214
frames: number
1315
physicsTime: number
@@ -16,6 +18,42 @@ export interface AccumTimes {
1618
simulationTime: number
1719
totalTime: number
1820
}
21+
type MiraEvent = {
22+
key?: string
23+
type?: "robot" | "field"
24+
assemblyName?: string
25+
/**
26+
* Size (in bytes) of the mirabuf file
27+
*/
28+
fileSize?: number
29+
}
30+
export interface AnalyticsEvents {
31+
"Performance Sample": {
32+
frames: number
33+
avgTotal: number
34+
avgPhysics: number
35+
avgScene: number
36+
avgInput: number
37+
avgSimulation: number
38+
}
39+
"APS Calls per Minute": unknown
40+
"APS Login": unknown
41+
"APS Download": MiraEvent
42+
43+
"Cache Get": MiraEvent
44+
"Cache Store": MiraEvent
45+
"Cache Remove": MiraEvent
46+
47+
"Remote Download": MiraEvent
48+
"Local Upload": MiraEvent
49+
50+
"Devtool Cache Persist": MiraEvent
51+
52+
"Scheme Applied": {
53+
isCustomized: boolean
54+
schemeName: string
55+
}
56+
}
1957

2058
class AnalyticsSystem extends WorldSystem {
2159
private _lastSampleTime = Date.now()
@@ -38,7 +76,7 @@ class AnalyticsSystem extends WorldSystem {
3876
this.sendMetaData()
3977
}
4078

41-
public event(name: string, params?: { [key: string]: string | number }) {
79+
public event<K extends keyof AnalyticsEvents>(name: K, params?: AnalyticsEvents[K]) {
4280
event({ name: name, params: params ?? {} })
4381
}
4482

@@ -50,7 +88,11 @@ class AnalyticsSystem extends WorldSystem {
5088
setUserId({ id: id })
5189
}
5290

53-
public setUserProperty(name: string, value: string) {
91+
public setUserProperty(name: string, value: unknown) {
92+
if (name.includes(" ")) {
93+
console.warn("GA user property names must not contain spaces")
94+
return
95+
}
5496
setUserProperty({ name: name, value: value })
5597
}
5698

@@ -62,9 +104,8 @@ class AnalyticsSystem extends WorldSystem {
62104
}
63105

64106
private sendMetaData() {
65-
if (import.meta.env.DEV) {
66-
this.setUserProperty("Internal Traffic", "true")
67-
}
107+
this.setUserProperty("isInternal", import.meta.env.DEV)
108+
this.setUserProperty("commit", GIT_COMMIT)
68109

69110
if (!this._consent) {
70111
return
@@ -73,15 +114,9 @@ class AnalyticsSystem extends WorldSystem {
73114
let betaCode = document.cookie.match(BETA_CODE_COOKIE_REGEX)?.[0]
74115
if (betaCode) {
75116
betaCode = betaCode.substring(betaCode.indexOf("=") + 1, betaCode.indexOf(";"))
76-
77-
this.setUserProperty("Beta Code", betaCode)
78-
}
79-
80-
if (MOBILE_USER_AGENT_REGEX.test(navigator.userAgent)) {
81-
this.setUserProperty("Is Mobile", "true")
82-
} else {
83-
this.setUserProperty("Is Mobile", "false")
117+
this.setUserProperty("betaCode", betaCode)
84118
}
119+
this.setUserProperty("isMobile", MOBILE_USER_AGENT_REGEX.test(navigator.userAgent))
85120
}
86121

87122
private currentSampleInterval() {

fission/src/systems/input/InputSchemeManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class InputSchemeManager {
131131
result[scheme.schemeName] ??= {
132132
scheme,
133133
status: InputSchemeUseType.CONFLICT,
134-
conflicts_with_names: [...new Set(conflictingSchemes)].join(", "),
134+
conflictingSchemeNames: [...new Set(conflictingSchemes)].join(", "),
135135
}
136136
} else {
137137
result[scheme.schemeName] = {

fission/src/systems/input/InputSystem.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { KeyCode } from "@/systems/input/KeyboardTypes.ts"
22
import { TouchControlsAxes } from "@/ui/components/TouchControls"
33
import Joystick from "../scene/Joystick"
4+
import World from "../World"
45
import WorldSystem from "../WorldSystem"
56
import type { InputName, InputScheme, ModifierState } from "./InputTypes"
67
import type Input from "./inputs/Input"
@@ -26,6 +27,14 @@ class InputSystem extends WorldSystem {
2627
/** Maps a brain index to an input scheme. */
2728
public static brainIndexSchemeMap: Map<number, InputScheme> = new Map()
2829

30+
public static setBrainIndexSchemeMapping(index: number, scheme: InputScheme) {
31+
InputSystem.brainIndexSchemeMap.set(index, scheme)
32+
World.analyticsSystem?.event("Scheme Applied", {
33+
isCustomized: scheme.customized,
34+
schemeName: scheme.schemeName,
35+
})
36+
}
37+
2938
constructor() {
3039
super()
3140

0 commit comments

Comments
 (0)