@@ -82,123 +82,93 @@ interface QSymbolDetail {
82
82
83
83
// We use a self-invoking function to minify the code, renaming long globals and attributes
84
84
// the qwik optimizer only minifies somewhat, so put all var declarations in the same line
85
- const insightsPing = sync$ ( ( ) =>
86
- ( (
87
- window : QwikSymbolTrackerWindow ,
88
- document ,
89
- location ,
90
- navigator ,
91
- performance ,
92
- round ,
93
- JSON_stringify
94
- ) => {
85
+ /** @internal */
86
+ export const insightsPing = sync$ ( ( ) =>
87
+ ( ( w : QwikSymbolTrackerWindow , d , l , n , p , r , S ) => {
95
88
/* eslint-disable no-var -- better minification */
96
89
var publicApiKey = __QI_KEY__ ,
97
90
postUrl = __QI_URL__ ,
98
- getAttribute_s = 'getAttribute' as const ,
99
- querySelector_s = 'querySelector' as const ,
100
- manifest_s = 'manifest' as const ,
101
- manifest_hash_s = `${ manifest_s } -hash` as const ,
102
- manifestHash_s = `${ manifest_s } Hash` as const ,
103
- version_s = 'version' as const ,
104
- publicApiKey_s = 'publicApiKey' as const ,
105
- sendBeacon_s = 'sendBeacon' as const ,
106
- symbol_s = 'symbol' as const ,
107
- length_s = 'length' as const ,
108
- addEventListener_s = 'addEventListener' as const ,
109
- route_s = 'route' as const ,
110
- error_s = 'error' as const ,
111
- stack_s = 'stack' as const ,
112
- message_s = 'message' as const ,
113
- symbols_s = `${ symbol_s } s` as const ,
114
- qVersion =
115
- document [ querySelector_s ] ( `[q\\:${ version_s } ]` ) ?. [ getAttribute_s ] ( `q:${ version_s } ` ) ||
116
- 'unknown' ,
91
+ qVersion = d . querySelector ( `[q\\:version]` ) ?. getAttribute ( `q:version` ) || 'unknown' ,
117
92
manifestHash =
118
- document [ querySelector_s ] ( `[q\\:${ manifest_hash_s } ]` ) ?. [ getAttribute_s ] (
119
- `q:${ manifest_hash_s } `
120
- ) || 'dev' ,
93
+ d . querySelector ( `[q\\:manifest-hash]` ) ?. getAttribute ( `q:manifest-hash` ) || 'dev' ,
121
94
qSymbols : InsightSymbol [ ] = [ ] ,
122
95
existingSymbols : Set < string > = new Set ( ) ,
123
96
flushSymbolIndex : number = 0 ,
124
97
lastReqTime : number = 0 ,
125
98
timeoutID : ReturnType < typeof setTimeout > | undefined ,
126
- qRouteChangeTime = performance . now ( ) ,
127
- qRouteEl = document [ querySelector_s ] ( `[q\\:${ route_s } ]` ) ,
99
+ qRouteChangeTime = p . now ( ) ,
100
+ qRouteEl = d . querySelector ( `[q\\:route ]` ) ,
128
101
flush = ( ) => {
129
102
timeoutID = undefined ;
130
- if ( qSymbols [ length_s ] > flushSymbolIndex ) {
103
+ if ( qSymbols . length > flushSymbolIndex ) {
131
104
var payload = {
132
105
qVersion,
133
- [ publicApiKey_s ] : publicApiKey ,
134
- [ manifestHash_s ] : manifestHash ,
106
+ publicApiKey,
107
+ manifestHash,
135
108
previousSymbol :
136
- flushSymbolIndex == 0 ? undefined : qSymbols [ flushSymbolIndex - 1 ] [ symbol_s ] ,
137
- [ symbols_s ] : qSymbols . slice ( flushSymbolIndex ) ,
109
+ flushSymbolIndex == 0 ? undefined : qSymbols [ flushSymbolIndex - 1 ] . symbol ,
110
+ symbols : qSymbols . slice ( flushSymbolIndex ) ,
138
111
} satisfies InsightsPayload ;
139
- navigator [ sendBeacon_s ] ( postUrl , JSON_stringify ( payload ) ) ;
140
- flushSymbolIndex = qSymbols [ length_s ] ;
112
+ n . sendBeacon ( postUrl , S ( payload ) ) ;
113
+ flushSymbolIndex = qSymbols . length ;
141
114
}
142
115
} ,
143
116
debounceFlush = ( ) => {
144
117
timeoutID != undefined && clearTimeout ( timeoutID ) ;
145
118
timeoutID = setTimeout ( flush , 1000 ) ;
146
119
} ;
147
120
148
- window . qSymbolTracker = {
149
- [ symbols_s ] : qSymbols ,
150
- [ publicApiKey_s ] : publicApiKey ,
121
+ w . qSymbolTracker = {
122
+ symbols : qSymbols ,
123
+ publicApiKey,
151
124
} ;
152
125
if ( qRouteEl ) {
153
126
new MutationObserver ( ( mutations ) => {
154
- var mutation = mutations . find ( ( m ) => m . attributeName === `q:${ route_s } ` ) ;
127
+ var mutation = mutations . find ( ( m ) => m . attributeName === `q:route ` ) ;
155
128
if ( mutation ) {
156
- qRouteChangeTime = performance . now ( ) ;
129
+ qRouteChangeTime = p . now ( ) ;
157
130
}
158
131
} ) . observe ( qRouteEl , { attributes : true } ) ;
159
132
}
160
- document [ addEventListener_s ] (
161
- 'visibilitychange' ,
162
- ( ) => document . visibilityState === 'hidden' && flush ( )
163
- ) ;
164
- document [ addEventListener_s ] ( `q${ symbol_s } ` , ( _event ) => {
133
+ d . addEventListener ( 'visibilitychange' , ( ) => d . visibilityState === 'hidden' && flush ( ) ) ;
134
+ d . addEventListener ( `qsymbol` , ( _event ) => {
165
135
var event = _event as CustomEvent < QSymbolDetail > ,
166
136
detail = event . detail ,
167
137
symbolRequestTime = detail . reqTime ,
168
138
symbolDeliveredTime = event . timeStamp ,
169
- symbol = detail [ symbol_s ] ;
139
+ symbol = detail . symbol ;
170
140
if ( ! existingSymbols . has ( symbol ) ) {
171
141
existingSymbols . add ( symbol ) ;
172
- var route = qRouteEl ?. [ getAttribute_s ] ( `q:${ route_s } ` ) || '/' ;
142
+ var route = qRouteEl ?. getAttribute ( `q:route ` ) || '/' ;
173
143
qSymbols . push ( {
174
- [ symbol_s ] : symbol ,
175
- [ route_s ] : route ,
176
- delay : round ( 0 - lastReqTime + symbolRequestTime ) ,
177
- latency : round ( symbolDeliveredTime - symbolRequestTime ) ,
178
- timeline : round ( 0 - qRouteChangeTime + symbolRequestTime ) ,
144
+ symbol,
145
+ route,
146
+ delay : r ( 0 - lastReqTime + symbolRequestTime ) ,
147
+ latency : r ( symbolDeliveredTime - symbolRequestTime ) ,
148
+ timeline : r ( 0 - qRouteChangeTime + symbolRequestTime ) ,
179
149
interaction : ! ! detail . element ,
180
150
} ) ;
181
151
lastReqTime = symbolDeliveredTime ;
182
152
debounceFlush ( ) ;
183
153
}
184
154
} ) ;
185
- window [ addEventListener_s ] ( error_s , ( event : ErrorEvent ) => {
186
- var error = event [ error_s ] ;
155
+ w . addEventListener ( 'error' , ( event : ErrorEvent ) => {
156
+ var error = event . error ;
187
157
if ( ! ( error && typeof error === 'object' ) ) {
188
158
return ;
189
159
}
190
160
var payload = {
191
- url : `${ location } ` ,
192
- [ manifestHash_s ] : manifestHash ,
161
+ url : `${ l } ` ,
162
+ manifestHash,
193
163
timestamp : new Date ( ) . getTime ( ) ,
194
164
source : event . filename ,
195
165
line : event . lineno ,
196
166
column : event . colno ,
197
- [ message_s ] : event [ message_s ] ,
198
- [ error_s ] : message_s in error ? ( error as Error ) [ message_s ] : `${ error } ` ,
199
- [ stack_s ] : stack_s in error ? ( error as Error ) [ stack_s ] || '' : '' ,
167
+ message : event . message ,
168
+ error : 'message' in error ? ( error as Error ) . message : `${ error } ` ,
169
+ stack : 'stack' in error ? ( error as Error ) . stack || '' : '' ,
200
170
} satisfies InsightsError ;
201
- navigator [ sendBeacon_s ] ( `${ postUrl } ${ error_s } /` , JSON_stringify ( payload ) ) ;
171
+ n . sendBeacon ( `${ postUrl } error /` , S ( payload ) ) ;
202
172
} ) ;
203
173
} ) ( window as any , document , location , navigator , performance , Math . round , JSON . stringify )
204
174
) ;
0 commit comments