@@ -10,8 +10,8 @@ export class BaseTracker {
1010 api : HttpClient ;
1111
1212 // State
13- anonymousId : string | null = null ;
14- sessionId : string | null = null ;
13+ anonymousId ? : string ;
14+ sessionId ? : string ;
1515 sessionStartTime = 0 ;
1616 lastActivityTime : number = Date . now ( ) ;
1717
@@ -253,13 +253,13 @@ export class BaseTracker {
253253 protected getConnectionInfo ( ) {
254254 const connection = navigator . connection || navigator . mozConnection || navigator . webkitConnection ;
255255 if ( ! connection ) {
256- return { connection_type : null , rtt : null , downlink : null } ;
256+ return { } ;
257257 }
258258
259259 return {
260- connection_type : connection . effectiveType || connection . type || null ,
261- rtt : connection . rtt || null ,
262- downlink : connection . downlink || null ,
260+ connection_type : connection . effectiveType || connection . type || undefined ,
261+ rtt : connection . rtt || undefined ,
262+ downlink : connection . downlink || undefined ,
263263 } ;
264264 }
265265
@@ -269,11 +269,11 @@ export class BaseTracker {
269269 }
270270 const urlParams = new URLSearchParams ( window . location . search ) ;
271271 return {
272- utm_source : urlParams . get ( "utm_source" ) ,
273- utm_medium : urlParams . get ( "utm_medium" ) ,
274- utm_campaign : urlParams . get ( "utm_campaign" ) ,
275- utm_term : urlParams . get ( "utm_term" ) ,
276- utm_content : urlParams . get ( "utm_content" ) ,
272+ utm_source : urlParams . get ( "utm_source" ) || undefined ,
273+ utm_medium : urlParams . get ( "utm_medium" ) || undefined ,
274+ utm_campaign : urlParams . get ( "utm_campaign" ) || undefined ,
275+ utm_term : urlParams . get ( "utm_term" ) || undefined ,
276+ utm_content : urlParams . get ( "utm_content" ) || undefined ,
277277 } ;
278278 }
279279
@@ -285,27 +285,27 @@ export class BaseTracker {
285285 const utmParams = this . getUtmParams ( ) ;
286286 const connectionInfo = this . getConnectionInfo ( ) ;
287287
288- let width : number | null = window . innerWidth ;
289- let height : number | null = window . innerHeight ;
288+ let width : number | undefined = window . innerWidth ;
289+ let height : number | undefined = window . innerHeight ;
290290 if ( width < 240 || width > 10_000 || height < 240 || height > 10_000 ) {
291- width = null ;
292- height = null ;
291+ width = undefined ;
292+ height = undefined ;
293293 }
294- const viewport_size = width && height ? `${ width } x${ height } ` : null ;
294+ const viewport_size = width && height ? `${ width } x${ height } ` : undefined ;
295295
296- let screenWidth : number | null = window . screen . width ;
297- let screenHeight : number | null = window . screen . height ;
296+ let screenWidth : number | undefined = window . screen . width ;
297+ let screenHeight : number | undefined = window . screen . height ;
298298 if (
299299 screenWidth < 240 ||
300300 screenWidth > 10_000 ||
301301 screenHeight < 240 ||
302302 screenHeight > 10_000
303303 ) {
304- screenWidth = null ;
305- screenHeight = null ;
304+ screenWidth = undefined ;
305+ screenHeight = undefined ;
306306 }
307307 const screen_resolution =
308- screenWidth && screenHeight ? `${ screenWidth } x${ screenHeight } ` : null ;
308+ screenWidth && screenHeight ? `${ screenWidth } x${ screenHeight } ` : undefined ;
309309
310310 const maskedPathname = this . getMaskedPath ( ) ;
311311 const path =
@@ -314,7 +314,7 @@ export class BaseTracker {
314314 window . location . search +
315315 window . location . hash ;
316316
317- let timezone : string | null = null ;
317+ let timezone : string | undefined ;
318318 try {
319319 timezone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
320320 } catch { }
@@ -335,24 +335,22 @@ export class BaseTracker {
335335 }
336336
337337 send ( event : any ) : Promise < any > {
338- const eventData =
339- event . type === "track" && event . payload ? event . payload : event ;
340338
341339 if ( this . shouldSkipTracking ( ) ) {
342340 return Promise . resolve ( ) ;
343341 }
344- if ( this . options . filter && ! this . options . filter ( eventData ) ) {
345- logger . log ( "Event filtered" , eventData ) ;
342+ if ( this . options . filter && ! this . options . filter ( event ) ) {
343+ logger . log ( "Event filtered" , event ) ;
346344 return Promise . resolve ( ) ;
347345 }
348346
349347 if ( this . options . enableBatching && ! event . isForceSend ) {
350- logger . log ( "Queueing event for batch" , eventData ) ;
351- return this . addToBatch ( eventData ) ;
348+ logger . log ( "Queueing event for batch" , event ) ;
349+ return this . addToBatch ( event ) ;
352350 }
353351
354- logger . log ( "Sending event" , eventData ) ;
355- return this . api . fetch ( "/" , eventData , { keepalive : true } ) ;
352+ logger . log ( "Sending event" , event ) ;
353+ return this . api . fetch ( "/" , event , { keepalive : true } ) ;
356354 }
357355
358356 addToBatch ( event : any ) : Promise < void > {
@@ -396,7 +394,7 @@ export class BaseTracker {
396394 } catch ( _error ) {
397395 logger . error ( "Batch failed, retrying individually" , _error ) ;
398396 for ( const evt of batchEvents ) {
399- this . send ( { type : "track" , payload : evt , isForceSend : true } ) ;
397+ this . send ( { ... evt , isForceSend : true } ) ;
400398 }
401399 return null ;
402400 }
@@ -425,8 +423,7 @@ export class BaseTracker {
425423 return null ;
426424 }
427425 try {
428- const eventData =
429- event . type === "track" && event . payload ? event . payload : event ;
426+ const eventData = event ;
430427 if ( this . shouldSkipTracking ( ) ) {
431428 return null ;
432429 }
0 commit comments