WorkerGlobalScope (which ServiceWorkerGlobalScope inherits from) does not include localStorage or sessionStorage, but using @minimal-analytics@gav4 in a ServiceWorker context throws a ReferenceError because of this hard dependency. It also throws a QuotaExceededError in a Safari Private tab when attempting to call setItem.
Instead, using a wrapper like storage-factory would prevent these runtime errors. Developers in a Worker context would then need to manually set the Client ID cid value, i.e. by copying the clientId value on the main thread between localStorage and indexedDB.