Skip to content

Commit

Permalink
note SDK version as a detail (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
cajames authored Jan 29, 2024
1 parent bf67f11 commit 43119f5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/checkout/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/checkout/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -104,6 +105,8 @@ export class Checkout {
this.readOnlyProviders = new Map<ChainId, ethers.providers.JsonRpcProvider>();
this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
this.passport = config.passport;

track('checkout_sdk', 'initialised');
}

/**
Expand Down
9 changes: 1 addition & 8 deletions packages/internal/metrics/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
9 changes: 6 additions & 3 deletions packages/internal/metrics/src/initialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,15 +35,18 @@ const runtimeHost = () => {
};

type RuntimeDetails = {
sdkVersion: string;
browser: string;
domain?: string;
tz?: string;
screen?: string;
};

const getRuntimeDetails = (): RuntimeDetails => {
storeDetail(Detail.SDK_VERSION, SDK_VERSION);

if (isNode()) {
return { browser: 'nodejs' };
return { browser: 'nodejs', sdkVersion: SDK_VERSION };
}

const domain = runtimeHost();
Expand All @@ -52,6 +55,7 @@ const getRuntimeDetails = (): RuntimeDetails => {
}

return {
sdkVersion: SDK_VERSION,
browser: window.navigator.userAgent,
domain,
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
Expand All @@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions packages/internal/metrics/src/utils/checkEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions packages/internal/metrics/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum Detail {
PUBLISHABLE_API_KEY = 'pak',
IDENTITY = 'uid',
DOMAIN = 'domain',
SDK_VERSION = 'sdkVersion',
}

export enum Store {
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43119f5

Please sign in to comment.