From 40db09191b21d3c025a1e53a26cd326221c2d9a0 Mon Sep 17 00:00:00 2001 From: James Gatz Date: Wed, 8 May 2024 13:06:37 +0200 Subject: [PATCH] fix missing session id (#7389) --- packages/insomnia/src/main/analytics.ts | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/packages/insomnia/src/main/analytics.ts b/packages/insomnia/src/main/analytics.ts index 8c25200fd..dc3ec44a4 100644 --- a/packages/insomnia/src/main/analytics.ts +++ b/packages/insomnia/src/main/analytics.ts @@ -1,5 +1,5 @@ import { Analytics } from '@segment/analytics-node'; -import { BrowserWindow, net } from 'electron'; +import { net } from 'electron'; import { v4 as uuidv4 } from 'uuid'; import { @@ -43,28 +43,13 @@ export enum SegmentEvent { vcsAction = 'VCS Action Executed', buttonClick = 'Button Clicked', } -// TODO: migrating session state to main would be more suitable than doing this. -const getAccountIdFromRenderer = async () => { - let sessionId = ''; - let accountId = ''; - try { - const windows = BrowserWindow.getAllWindows(); - const mainWindow = windows[0]; - sessionId = await mainWindow.webContents.executeJavaScript('localStorage.getItem("currentSessionId");'); - const sessionJSON = await mainWindow.webContents.executeJavaScript(`localStorage.getItem("session__${(sessionId).slice(0, 10)}");`); - const sessionData = JSON.parse(sessionJSON); - accountId = sessionData?.accountId ?? ''; - } catch (e) { - return { sessionId, accountId }; - } - return { sessionId, accountId }; -}; + export async function trackSegmentEvent( event: SegmentEvent, properties?: Record, ) { const settings = await models.settings.get(); - const { accountId } = await getAccountIdFromRenderer(); + const { accountId } = await models.userSession.get(); const allowAnalytics = settings.enableAnalytics || accountId; if (allowAnalytics) { @@ -93,7 +78,7 @@ export async function trackSegmentEvent( export async function trackPageView(name: string) { const settings = await models.settings.get(); - const { sessionId, accountId } = await getAccountIdFromRenderer(); + const { id: sessionId, accountId } = await models.userSession.get(); const allowAnalytics = settings.enableAnalytics || accountId; if (allowAnalytics) { try {