@@ -33,22 +33,27 @@ import { SharedState } from '../state';
3333import  {  localStorageAccessible  }  from  '../detectors' ; 
3434import  {  LOG ,  Payload  }  from  '@snowplow/tracker-core' ; 
3535import  {  PAYLOAD_DATA_SCHEMA  }  from  './schemata' ; 
36+ import  {  EventMethod  }  from  './types' ; 
3637
3738export  interface  OutQueue  { 
3839  enqueueRequest : ( request : Payload ,  url : string )  =>  void ; 
3940  executeQueue : ( )  =>  void ; 
4041  setUseLocalStorage : ( localStorage : boolean )  =>  void ; 
4142  setAnonymousTracking : ( anonymous : boolean )  =>  void ; 
4243  setCollectorUrl : ( url : string )  =>  void ; 
43-   setBufferSize : ( bufferSize : number )  =>  void ; 
44+   setBufferSize : ( newBufferSize : number )  =>  void ; 
45+   /** 
46+    * Returns the currently used queue name or if the `eventMethod` argument is provided, the queue name for the eventMethod. 
47+    */ 
48+   getName : ( eventMethod ?: Exclude < EventMethod ,  'beacon' > )  =>  string ; 
4449} 
4550
4651/** 
4752 * Object handling sending events to a collector. 
4853 * Instantiated once per tracker instance. 
4954 * 
5055 * @param  id - The Snowplow function name (used to generate the localStorage key) 
51-  * @param  sharedSate  - Stores reference to the outbound queue so it can unload the page when all queues are empty 
56+  * @param  sharedState  - Stores reference to the outbound queue so it can unload the page when all queues are empty 
5257 * @param  useLocalStorage - Whether to use localStorage at all 
5358 * @param  eventMethod - if null will use 'beacon' otherwise can be set to 'post', 'get', or 'beacon' to force. 
5459 * @param  postPath - The path where events are to be posted 
@@ -67,7 +72,7 @@ export interface OutQueue {
6772 */ 
6873export  function  OutQueueManager ( 
6974  id : string , 
70-   sharedSate : SharedState , 
75+   sharedState : SharedState , 
7176  useLocalStorage : boolean , 
7277  eventMethod : string  |  boolean , 
7378  postPath : string , 
@@ -114,7 +119,7 @@ export function OutQueueManager(
114119    // Resolve all options and capabilities and decide path 
115120    path  =  usePost  ? postPath  : '/i' , 
116121    // Different queue names for GET and POST since they are stored differently 
117-     queueName  =  `snowplowOutQueue_ ${ id } _ ${ usePost  ? 'post2 '  : 'get' } ` ; 
122+     queueName  =  getQueueName ( id ,   usePost  ? 'post '  : 'get' ) ; 
118123
119124  // Ensure we don't set headers when beacon is the requested eventMethod as we might fallback to POST 
120125  // and end up sending them in older browsers which don't support beacon leading to inconsistencies 
@@ -128,7 +133,9 @@ export function OutQueueManager(
128133    try  { 
129134      const  localStorageQueue  =  window . localStorage . getItem ( queueName ) ; 
130135      outQueue  =  localStorageQueue  ? JSON . parse ( localStorageQueue )  : [ ] ; 
131-     }  catch  ( e )  { } 
136+     }  catch  ( e )  { 
137+       LOG . error ( 'Failed to access window.localStorage queue.' ) ; 
138+     } 
132139  } 
133140
134141  // Initialize to and empty array if we didn't get anything out of localStorage 
@@ -137,16 +144,20 @@ export function OutQueueManager(
137144  } 
138145
139146  // Used by pageUnloadGuard 
140-   sharedSate . outQueues . push ( outQueue ) ; 
147+   sharedState . outQueues . push ( outQueue ) ; 
141148
142149  if  ( useXhr  &&  bufferSize  >  1 )  { 
143-     sharedSate . bufferFlushers . push ( function  ( sync )  { 
150+     sharedState . bufferFlushers . push ( function  ( sync )  { 
144151      if  ( ! executingQueue )  { 
145152        executeQueue ( sync ) ; 
146153      } 
147154    } ) ; 
148155  } 
149156
157+   function  getQueueName ( id : string ,  method : Exclude < EventMethod ,  'beacon' > )  { 
158+     return  `snowplowOutQueue_${ id } ${ method  ===  'get'  ? 'get'  : 'post2' }  ; 
159+   } 
160+ 
150161  /* 
151162   * Convert a dictionary to a querystring 
152163   * The context field is the last in the querystring 
@@ -535,6 +546,7 @@ export function OutQueueManager(
535546    setBufferSize : ( newBufferSize : number )  =>  { 
536547      bufferSize  =  newBufferSize ; 
537548    } , 
549+     getName : ( method ?: Exclude < EventMethod ,  'beacon' > )  =>  ( method  ? getQueueName ( id ,  method )  : queueName ) , 
538550  } ; 
539551
540552  function  hasWebKitBeaconBug ( useragent : string )  { 
0 commit comments