mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fix missing session id (#7389)
This commit is contained in:
parent
cc421d1a3c
commit
40db09191b
@ -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<string, any>,
|
||||
) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user