Skip to content

Commit

Permalink
fix: polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Jan 20, 2025
1 parent c72edef commit 1cc38ad
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/ga4.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Browser from 'webextension-polyfill';
import { appIsDev } from './env';

const GA_ENDPOINT = 'https://www.google-analytics.com/mp/collect';
Expand All @@ -22,11 +23,11 @@ class Analytics {
// Stores client id in local storage to keep the same client id as long as
// the extension is installed.
async getOrCreateClientId() {
let { clientId } = await chrome.storage.local.get('clientId');
let { clientId } = await Browser.storage.local.get('clientId');
if (!clientId) {
// Generate a unique client ID, the actual value is not relevant
clientId = self.crypto.randomUUID();
await chrome.storage.local.set({ clientId });
await Browser.storage.local.set({ clientId });
}
return clientId;
}
Expand All @@ -35,7 +36,7 @@ class Analytics {
// the previous one has expired.
async getOrCreateSessionId() {
// Use storage.session because it is only in memory
let { sessionData } = await chrome.storage.session.get('sessionData');
let { sessionData } = await Browser.storage.session.get('sessionData');
const currentTimeInMs = Date.now();
// Check if session exists and is still valid
if (sessionData && sessionData.timestamp) {
Expand All @@ -48,7 +49,7 @@ class Analytics {
} else {
// Update timestamp to keep session alive
sessionData.timestamp = currentTimeInMs;
await chrome.storage.session.set({ sessionData });
await Browser.storage.session.set({ sessionData });
}
}
if (!sessionData) {
Expand All @@ -57,7 +58,7 @@ class Analytics {
session_id: currentTimeInMs.toString(),
timestamp: currentTimeInMs.toString(),
};
await chrome.storage.session.set({ sessionData });
await Browser.storage.session.set({ sessionData });
}
return sessionData.session_id;
}
Expand Down

0 comments on commit 1cc38ad

Please sign in to comment.