minimal-analytics icon indicating copy to clipboard operation
minimal-analytics copied to clipboard

Support Web Worker and ServiceWorker scope

Open Tombarr opened this issue 2 years ago • 1 comments

Add support for Web Worker and ServiceWorker contexts with the following changes

  • When navigator.sendBeacon isn't available, default to XMLHttpRequest (Worker) or fetch (ServiceWorker)
  • When sessionStorage or localStorage isn't available (i.e. Worker/ ServiceWorker), use an in-memory Map and warn that clientId is not persisted
  • Allow use of global self or window, depending on context
  • Don't set window or document scoped events when not available
  • Because localStorage isn't available in a Worker scope, per #43, allow param overrides, i.e. to pull clientId from IndexedDB

Tombarr avatar Apr 16 '23 03:04 Tombarr

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |   96.58 |    77.25 |     100 |   96.49 |                   
 index.ts |   96.46 |    77.25 |     100 |   96.39 | 283,305,393,403   
 model.ts |     100 |      100 |     100 |     100 |                   
----------|---------|----------|---------|---------|-------------------
Jest: "global" coverage threshold for branches (78%) not met: 77.25%

Looks like CI ran well this time, but failed due to test coverage. I'll take a look at covering additional branches within ga4

Tombarr avatar Apr 19 '23 17:04 Tombarr