diff --git a/packages/checkout/sdk/package.json b/packages/checkout/sdk/package.json index a031f80cb1..0c3084bc3a 100644 --- a/packages/checkout/sdk/package.json +++ b/packages/checkout/sdk/package.json @@ -10,6 +10,7 @@ "@imtbl/bridge-sdk": "0.0.0", "@imtbl/config": "0.0.0", "@imtbl/dex-sdk": "0.0.0", + "@imtbl/metrics": "0.0.0", "@imtbl/orderbook": "0.0.0", "@imtbl/passport": "0.0.0", "@metamask/detect-provider": "^2.0.0", diff --git a/packages/checkout/sdk/src/sdk.ts b/packages/checkout/sdk/src/sdk.ts index 3142ef849b..efcffa5fc2 100644 --- a/packages/checkout/sdk/src/sdk.ts +++ b/packages/checkout/sdk/src/sdk.ts @@ -3,6 +3,7 @@ import { Web3Provider } from '@ethersproject/providers'; import { ethers } from 'ethers'; import { Environment } from '@imtbl/config'; import { Passport } from '@imtbl/passport'; +import { track } from '@imtbl/metrics'; import * as balances from './balances'; import * as tokens from './tokens'; import * as connect from './connect'; @@ -104,6 +105,8 @@ export class Checkout { this.readOnlyProviders = new Map(); this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction); this.passport = config.passport; + + track('checkout_sdk', 'initialised'); } /** diff --git a/packages/internal/metrics/src/index.ts b/packages/internal/metrics/src/index.ts index a601fba1dd..76a74778cd 100644 --- a/packages/internal/metrics/src/index.ts +++ b/packages/internal/metrics/src/index.ts @@ -1,14 +1,7 @@ -import { track } from './track'; - +export { track } from './track'; export { identify } from './identify'; export { setEnvironment, setPassportClientId, setPublishableApiKey, } from './details'; - -track('metrics', 'sdk_version', { - version: '__SDK_VERSION__', -}); - -export { track }; diff --git a/packages/internal/metrics/src/initialise.ts b/packages/internal/metrics/src/initialise.ts index 9173a33106..6d753b37f1 100644 --- a/packages/internal/metrics/src/initialise.ts +++ b/packages/internal/metrics/src/initialise.ts @@ -4,7 +4,7 @@ import { post } from './utils/request'; import { flattenProperties, getDetail, storeDetail } from './utils/state'; // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME. -export const SDK_VERSION = '__SDK_VERSION__'; +const SDK_VERSION = '__SDK_VERSION__'; let initialised = false; export const isInitialised = () => initialised; @@ -35,6 +35,7 @@ const runtimeHost = () => { }; type RuntimeDetails = { + sdkVersion: string; browser: string; domain?: string; tz?: string; @@ -42,8 +43,10 @@ type RuntimeDetails = { }; const getRuntimeDetails = (): RuntimeDetails => { + storeDetail(Detail.SDK_VERSION, SDK_VERSION); + if (isNode()) { - return { browser: 'nodejs' }; + return { browser: 'nodejs', sdkVersion: SDK_VERSION }; } const domain = runtimeHost(); @@ -52,6 +55,7 @@ const getRuntimeDetails = (): RuntimeDetails => { } return { + sdkVersion: SDK_VERSION, browser: window.navigator.userAgent, domain, tz: Intl.DateTimeFormat().resolvedOptions().timeZone, @@ -65,7 +69,6 @@ type InitialiseResponse = { export const initialise = async () => { const runtimeDetails = flattenProperties(getRuntimeDetails()); - // Get any existing runtimeId and send it along with the initialise const existingRuntimeId = getDetail(Detail.RUNTIME_ID); const body = { diff --git a/packages/internal/metrics/src/utils/checkEnv.ts b/packages/internal/metrics/src/utils/checkEnv.ts index ef56c67c4a..7421abae62 100644 --- a/packages/internal/metrics/src/utils/checkEnv.ts +++ b/packages/internal/metrics/src/utils/checkEnv.ts @@ -2,5 +2,8 @@ export function isTestEnvironment() { if (typeof process === 'undefined') { return false; } + + // Consider using `ci-info` package for better results, though might fail as not browser safe. + // Just use process.env.CI for now. return process.env.JEST_WORKER_ID !== undefined; } diff --git a/packages/internal/metrics/src/utils/constants.ts b/packages/internal/metrics/src/utils/constants.ts index ad0dd30c6b..a152b47911 100644 --- a/packages/internal/metrics/src/utils/constants.ts +++ b/packages/internal/metrics/src/utils/constants.ts @@ -5,6 +5,7 @@ export enum Detail { PUBLISHABLE_API_KEY = 'pak', IDENTITY = 'uid', DOMAIN = 'domain', + SDK_VERSION = 'sdkVersion', } export enum Store { diff --git a/yarn.lock b/yarn.lock index bc0e67d56e..0066914fbe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3347,6 +3347,7 @@ __metadata: "@imtbl/bridge-sdk": 0.0.0 "@imtbl/config": 0.0.0 "@imtbl/dex-sdk": 0.0.0 + "@imtbl/metrics": 0.0.0 "@imtbl/orderbook": 0.0.0 "@imtbl/passport": 0.0.0 "@metamask/detect-provider": ^2.0.0