@@ -8,6 +8,8 @@ const SAMPLE_INTERVAL = 60000 // 1 minute
88const BETA_CODE_COOKIE_REGEX = / a c c e s s _ c o d e = .* ( ; | $ ) /
99const MOBILE_USER_AGENT_REGEX = / A n d r o i d | w e b O S | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i / i
1010
11+ declare const GIT_COMMIT : string
12+
1113export 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
2058class 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 ( ) {
0 commit comments