diff --git a/packages/insomnia-app/app/common/analytics.ts b/packages/insomnia-app/app/common/analytics.ts index f9ca95dc5..740e868e1 100644 --- a/packages/insomnia-app/app/common/analytics.ts +++ b/packages/insomnia-app/app/common/analytics.ts @@ -1,4 +1,5 @@ import Analytics from 'analytics-node'; +import { AxiosRequestConfig } from 'axios'; import * as uuid from 'uuid'; import { getAccountId } from '../account/session'; @@ -12,14 +13,18 @@ import { getSegmentWriteKey, } from './constants'; +const axiosConfig: AxiosRequestConfig = { + // This is needed to ensure that we use the NodeJS adapter in the render process + ...(global?.require ? { + adapter: global.require('axios/lib/adapters/http'), + } : {}), +}; + const segmentClient = new Analytics(getSegmentWriteKey(), { - // @ts-expect-error -- TSCONVERSION - axiosConfig: { - // This is needed to ensure that we use the NodeJS adapter in the render process - ...(global?.require && { - adapter: global.require('axios/lib/adapters/http'), - }), - }, + // @ts-expect-error this is missing from the analytics-node types (and docs) but is present in the source code + // https://github.com/segmentio/analytics-node/blob/0a6aa0d9d865b56f799f9d014b4d7b98ae5d2f2e/index.js#L28 + // as for the types: since (as of @types/analytics-node v3.1.7) this is hardcoded into a class constructor, it makes it hard to fix with module augmentation + axiosConfig, }); const getDeviceId = async () => {