From 3c85e6012f30998b408d08a8df3f72b4234710fb Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 30 Oct 2026 15:49:49 +0530 Subject: [PATCH 01/55] Add trackIdentity option to link a visitor's Fingerprint device to their click --- .github/workflows/release.yml | 2 + packages/web/package.json | 3 +- packages/web/src/generic.ts | 9 ++++ packages/web/src/identity.ts | 89 +++++++++++++++++++++++++++++++++++ packages/web/src/types.ts | 8 ++++ packages/web/tsup.config.js | 3 ++ pnpm-lock.yaml | 50 ++++++++++++-------- 7 files changed, 144 insertions(+), 20 deletions(-) create mode 100644 packages/web/src/identity.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 394ef3f..a9369b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,6 +23,8 @@ jobs: - name: build run: pnpm --filter @dub/analytics build + env: + DUB_FINGERPRINT_PUBLIC_KEY: ${{ vars.DUB_FINGERPRINT_PUBLIC_KEY }} - run: pnpm --filter @dub/analytics publish --tag beta --no-git-checks if: github.event.release.prerelease == true diff --git a/packages/web/package.json b/packages/web/package.json index 0ce7554..9d29bb1 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -53,6 +53,7 @@ } }, "dependencies": { + "@fingerprint/agent": "^4.1.6", "server-only": "^0.0.1" }, "devDependencies": { @@ -64,4 +65,4 @@ "react-dom": "^18.2.0", "tsup": "7.1.0" } -} \ No newline at end of file +} diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index e6075c0..fc84498 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -1,4 +1,5 @@ import { name, version } from '../package.json'; +import { trackIdentity } from './identity'; import type { AnalyticsProps } from './types'; import { isBrowser } from './utils'; @@ -88,6 +89,14 @@ function inject(props: AnalyticsProps): void { Object.assign(script, restProps); } + if (props.trackIdentity) { + script.addEventListener('load', () => { + void trackIdentity({ + apiHost: props.apiHost, + }); + }); + } + script.onerror = (): void => { // eslint-disable-next-line no-console -- Logging to console is intentional console.log(`[Dub Web Analytics] failed to load script from ${src}.`); diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts new file mode 100644 index 0000000..eaa79d9 --- /dev/null +++ b/packages/web/src/identity.ts @@ -0,0 +1,89 @@ +const DEFAULT_API_HOST = 'https://api.dub.co'; +const DUB_ID_COOKIE = 'dub_id'; +const DUB_FID_COOKIE = 'dub_fid'; +const DUB_FID_MAX_AGE_SECONDS = 30 * 60; +const CLICK_ID_POLL_ATTEMPTS = 5; +const CLICK_ID_POLL_INTERVAL_MS = 1000; +const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; + +function getCookie(name: string): string | undefined { + return document.cookie + .split(';') + .map((cookie) => cookie.trim().split('=')) + .find(([key]) => key === name)?.[1]; +} + +// The script sets dub_id asynchronously for ?via= clicks, so give it a few seconds +async function waitForClickId( + attemptsLeft = CLICK_ID_POLL_ATTEMPTS, +): Promise { + const clickId = getCookie(DUB_ID_COOKIE); + + if (clickId || attemptsLeft <= 1) { + return clickId; + } + + await new Promise((resolve) => { + setTimeout(resolve, CLICK_ID_POLL_INTERVAL_MS); + }); + + return waitForClickId(attemptsLeft - 1); +} + +/** + * Identifies the visitor's device with Fingerprint and links it to their Dub click. + * Runs only for visitors with a `dub_id` cookie, at most once per click every 30 minutes. + */ +export async function trackIdentity({ + apiHost = DEFAULT_API_HOST, +}: { + apiHost?: string; +}): Promise { + try { + if (!FINGERPRINT_PUBLIC_KEY) { + return; + } + + const clickId = await waitForClickId(); + + if (!clickId || getCookie(DUB_FID_COOKIE) === clickId) { + return; + } + + const { start } = await import('@fingerprint/agent'); + + // The server reads the click from linkedId and rejects events older than 10 seconds + const { sealed_result: sealedResult } = await start({ + apiKey: FINGERPRINT_PUBLIC_KEY, + }).get({ + linkedId: clickId, + }); + + if (!sealedResult) { + return; + } + + const response = await fetch(`${apiHost}/track/identity`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + sealedResult: sealedResult.base64(), + }), + }); + + if (!response.ok) { + // eslint-disable-next-line no-console -- Logging to console is intentional + console.warn( + `[Dub Web Analytics] identity tracking failed with status ${response.status}.`, + ); + return; + } + + document.cookie = `${DUB_FID_COOKIE}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; + } catch (error) { + // eslint-disable-next-line no-console -- Logging to console is intentional + console.warn('[Dub Web Analytics] identity tracking failed.', error); + } +} diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 939c820..933fe4d 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -154,6 +154,14 @@ export interface AnalyticsProps { */ queryParams?: string[]; + /** + * Identify the visitor's device with Fingerprint and link it to their Dub click, to detect + * partners referring several customers from one device. Only runs for visitors with a `dub_id` cookie. + * + * @default false + */ + trackIdentity?: boolean; + /** * Custom properties to pass to the script. * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement diff --git a/packages/web/tsup.config.js b/packages/web/tsup.config.js index db20c66..d4b13c1 100644 --- a/packages/web/tsup.config.js +++ b/packages/web/tsup.config.js @@ -7,6 +7,9 @@ const cfg = { treeshake: false, dts: true, format: ['esm', 'cjs'], + env: { + DUB_FINGERPRINT_PUBLIC_KEY: process.env.DUB_FINGERPRINT_PUBLIC_KEY ?? '', + }, }; export default defineConfig([ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a05f541..c4e268b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -171,6 +171,9 @@ importers: packages/web: dependencies: + '@fingerprint/agent': + specifier: ^4.1.6 + version: 4.1.6 server-only: specifier: ^0.0.1 version: 0.0.1 @@ -828,6 +831,12 @@ packages: } engines: { node: ^12.22.0 || ^14.17.0 || >=16.0.0 } + '@fingerprint/agent@4.1.6': + resolution: + { + integrity: sha512-Ro7IYCaHhTv+TqnB6Hmv33kNQm1Q+Cs3xEqkxwsjfBkS8z2zb338fHWXK9Ef+qapl/qX2mCCIbjml+fIy9XCKg==, + } + '@humanwhocodes/config-array@0.11.14': resolution: { @@ -1476,6 +1485,7 @@ packages: { integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==, } + deprecated: Potential CWE-502 - Update to 1.3.1 or higher '@vercel/style-guide@5.0.1': resolution: @@ -2691,6 +2701,7 @@ packages: integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==, } engines: { node: '>=16 || 14 >=14.17' } + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me hasBin: true glob@7.1.7: @@ -2698,14 +2709,14 @@ packages: { integrity: sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==, } - deprecated: Glob versions prior to v9 are no longer supported + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me glob@7.2.3: resolution: { integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==, } - deprecated: Glob versions prior to v9 are no longer supported + deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me globals@11.12.0: resolution: @@ -3481,6 +3492,7 @@ packages: integrity: sha512-wlzrsbfeSU48YQBjZhDzOwhWhGsy+uQycR8bHAOt1LY1bn3zZEcDyHQOEoN3aWzQ8LHCAJ1nqrWCc9XF2+O45Q==, } engines: { node: '>=18.17.0' } + deprecated: This version has a security vulnerability. Please upgrade to a patched version. See https://nextjs.org/blog/security-update-2025-12-11 for more details. hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 @@ -3499,6 +3511,7 @@ packages: integrity: sha512-R8/V7vugY+822rsQGQCjoLhMuC9oFj9SOi4Cl4b2wjDrseD0LRZ10W7R6Czo4w9ZznVSshKjuIomsRjvm9EKJQ==, } engines: { node: '>=18.17.0' } + deprecated: This version has a security vulnerability. Please upgrade to a patched version. See https://nextjs.org/blog/security-update-2025-12-11 for more details. hasBin: true peerDependencies: '@opentelemetry/api': ^1.1.0 @@ -4250,6 +4263,7 @@ packages: integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==, } engines: { node: '>= 8' } + deprecated: The work that was done in this beta branch won't be included in future versions spdx-correct@3.2.0: resolution: @@ -5104,6 +5118,8 @@ snapshots: '@eslint/js@8.56.0': {} + '@fingerprint/agent@4.1.6': {} + '@humanwhocodes/config-array@0.11.14': dependencies: '@humanwhocodes/object-schema': 2.0.2 @@ -5596,10 +5612,10 @@ snapshots: '@typescript-eslint/eslint-plugin': 6.20.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0)(typescript@5.1.3) '@typescript-eslint/parser': 6.20.0(eslint@8.43.0)(typescript@5.1.3) eslint-config-prettier: 9.1.0(eslint@8.43.0) - eslint-import-resolver-alias: 1.1.2(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0)) - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0) + eslint-import-resolver-alias: 1.1.2(eslint-plugin-import@2.29.1) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1)(eslint@8.43.0) eslint-plugin-eslint-comments: 3.2.0(eslint@8.43.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) eslint-plugin-jest: 27.6.3(@typescript-eslint/eslint-plugin@6.20.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0)(typescript@5.1.3) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.43.0) eslint-plugin-playwright: 0.16.0(eslint-plugin-jest@27.6.3(@typescript-eslint/eslint-plugin@6.20.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0) @@ -6139,7 +6155,7 @@ snapshots: '@typescript-eslint/parser': 6.20.0(eslint@8.43.0)(typescript@5.3.3) eslint: 8.43.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.43.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.43.0) eslint-plugin-react: 7.33.2(eslint@8.43.0) @@ -6158,10 +6174,6 @@ snapshots: dependencies: eslint: 8.56.0 - eslint-import-resolver-alias@1.1.2(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0)): - dependencies: - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) - eslint-import-resolver-alias@1.1.2(eslint-plugin-import@2.29.1): dependencies: eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.56.0) @@ -6174,13 +6186,13 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0): + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1)(eslint@8.43.0): dependencies: debug: 4.3.4 enhanced-resolve: 5.15.0 eslint: 8.43.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) fast-glob: 3.3.2 get-tsconfig: 4.7.2 is-core-module: 2.13.1 @@ -6191,7 +6203,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.43.0): + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0): dependencies: debug: 4.3.4 enhanced-resolve: 5.15.0 @@ -6242,14 +6254,14 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0): + eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 6.20.0(eslint@8.43.0)(typescript@5.1.3) eslint: 8.43.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1)(eslint@8.43.0) transitivePeerDependencies: - supports-color @@ -6260,7 +6272,7 @@ snapshots: '@typescript-eslint/parser': 6.20.0(eslint@8.56.0)(typescript@5.3.3) eslint: 8.43.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.43.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0) transitivePeerDependencies: - supports-color @@ -6287,7 +6299,7 @@ snapshots: eslint: 8.56.0 ignore: 5.3.1 - eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0): + eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0): dependencies: array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 @@ -6297,7 +6309,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.43.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.43.0)(typescript@5.1.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) hasown: 2.0.0 is-core-module: 2.13.1 is-glob: 4.0.3 From 69a3d5b7edb9ea4dbe2445feac57acbd399ee6d3 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 30 Oct 2026 15:49:56 +0530 Subject: [PATCH 02/55] Add unit tests for trackIdentity --- packages/web/package.json | 5 +- packages/web/src/identity.test.ts | 193 +++ packages/web/vitest.config.js | 10 + pnpm-lock.yaml | 1966 ++++++++++++++++++++++++++++- 4 files changed, 2163 insertions(+), 11 deletions(-) create mode 100644 packages/web/src/identity.test.ts create mode 100644 packages/web/vitest.config.js diff --git a/packages/web/package.json b/packages/web/package.json index 9d29bb1..3f73977 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -42,6 +42,7 @@ "dev": "tsup --watch", "lint": "eslint .", "lint-fix": "eslint . --fix", + "test": "vitest run", "type-check": "tsc --noEmit" }, "eslintConfig": { @@ -61,8 +62,10 @@ "@swc/core": "^1.3.66", "@types/node": "^20.3.1", "@types/react": "^18.2.14", + "jsdom": "^24.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "tsup": "7.1.0" + "tsup": "7.1.0", + "vitest": "^1.6.0" } } diff --git a/packages/web/src/identity.test.ts b/packages/web/src/identity.test.ts new file mode 100644 index 0000000..fb5d597 --- /dev/null +++ b/packages/web/src/identity.test.ts @@ -0,0 +1,193 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { trackIdentity } from './identity'; + +const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; +const SEALED_RESULT = 'noXc7Q=='; + +const { get, start } = vi.hoisted(() => { + const getMock = vi.fn(); + + return { + get: getMock, + start: vi.fn(() => ({ + get: getMock, + })), + }; +}); + +vi.mock('@fingerprint/agent', () => ({ + start, +})); + +const fetchMock = vi.fn(); + +function clearCookies(): void { + document.cookie.split(';').forEach((cookie) => { + const [name] = cookie.trim().split('='); + document.cookie = `${name}=; path=/; max-age=0`; + }); +} + +function getCookie(name: string): string | undefined { + return document.cookie + .split(';') + .map((cookie) => cookie.trim().split('=')) + .find(([key]) => key === name)?.[1]; +} + +describe('trackIdentity', () => { + beforeEach(() => { + clearCookies(); + vi.stubGlobal('fetch', fetchMock); + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + get.mockResolvedValue({ + event_id: 'evt_1', + sealed_result: { + base64: () => SEALED_RESULT, + }, + }); + + fetchMock.mockResolvedValue( + new Response( + JSON.stringify({ + clickIdentityId: 'cid_1', + }), + ), + ); + }); + + afterEach(() => { + vi.useRealTimers(); + vi.unstubAllGlobals(); + vi.clearAllMocks(); + }); + + it('identifies with linkedId set to the clickId and posts only the sealed result', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + await trackIdentity({ + apiHost: 'https://api.example.com', + }); + + expect(start).toHaveBeenCalledWith({ + apiKey: 'test_public_key', + }); + expect(get).toHaveBeenCalledWith({ + linkedId: CLICK_ID, + }); + expect(fetchMock).toHaveBeenCalledWith( + 'https://api.example.com/track/identity', + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + sealedResult: SEALED_RESULT, + }), + }, + ); + expect(getCookie('dub_fid')).toBe(CLICK_ID); + }); + + it('defaults to the Dub API host', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + await trackIdentity({}); + + expect(fetchMock).toHaveBeenCalledWith( + 'https://api.dub.co/track/identity', + expect.anything(), + ); + }); + + it('skips when dub_fid already matches the click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = `dub_fid=${CLICK_ID}; path=/`; + + await trackIdentity({}); + + expect(start).not.toHaveBeenCalled(); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('identifies again when dub_fid belongs to another click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = 'dub_fid=otherClickId; path=/'; + + await trackIdentity({}); + + expect(fetchMock).toHaveBeenCalledTimes(1); + expect(getCookie('dub_fid')).toBe(CLICK_ID); + }); + + it('waits for dub_id set after a client-side click', async () => { + vi.useFakeTimers(); + + const promise = trackIdentity({}); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + await vi.advanceTimersByTimeAsync(1000); + await promise; + + expect(get).toHaveBeenCalledWith({ + linkedId: CLICK_ID, + }); + }); + + it('skips when there is no dub_id cookie', async () => { + vi.useFakeTimers(); + + const promise = trackIdentity({}); + await vi.advanceTimersByTimeAsync(5000); + await promise; + + expect(start).not.toHaveBeenCalled(); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('skips the request when sealed results are off', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + get.mockResolvedValue({ + event_id: 'evt_1', + sealed_result: null, + }); + + await trackIdentity({}); + + expect(fetchMock).not.toHaveBeenCalled(); + expect(getCookie('dub_fid')).toBeUndefined(); + }); + + it('does not set dub_fid when the request is rejected', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + fetchMock.mockResolvedValue( + new Response('Bad Request', { + status: 400, + }), + ); + + await trackIdentity({}); + + expect(getCookie('dub_fid')).toBeUndefined(); + }); + + it('never throws when Fingerprint fails', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + get.mockRejectedValue(new Error('Network error')); + + await expect(trackIdentity({})).resolves.toBeUndefined(); + + expect(fetchMock).not.toHaveBeenCalled(); + expect(getCookie('dub_fid')).toBeUndefined(); + }); + + it('never throws when the request fails', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + fetchMock.mockRejectedValue(new TypeError('Failed to fetch')); + + await expect(trackIdentity({})).resolves.toBeUndefined(); + + expect(getCookie('dub_fid')).toBeUndefined(); + }); +}); diff --git a/packages/web/vitest.config.js b/packages/web/vitest.config.js new file mode 100644 index 0000000..2af4067 --- /dev/null +++ b/packages/web/vitest.config.js @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + environment: 'jsdom', + env: { + DUB_FINGERPRINT_PUBLIC_KEY: 'test_public_key', + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4e268b..ef19907 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -190,6 +190,9 @@ importers: '@types/react': specifier: ^18.2.14 version: 18.2.51 + jsdom: + specifier: ^24.0.0 + version: 24.1.3 react: specifier: ^18.2.0 version: 18.2.0 @@ -198,7 +201,10 @@ importers: version: 18.2.0(react@18.2.0) tsup: specifier: 7.1.0 - version: 7.1.0(@swc/core@1.3.107(@swc/helpers@0.5.5))(postcss@8.4.38)(typescript@5.3.3) + version: 7.1.0(@swc/core@1.3.107(@swc/helpers@0.5.5))(postcss@8.5.32)(typescript@5.3.3) + vitest: + specifier: ^1.6.0 + version: 1.6.1(@types/node@20.11.16)(jsdom@24.1.3)(terser@5.39.0) packages: '@aashutoshrathi/word-wrap@1.2.6': @@ -222,6 +228,12 @@ packages: } engines: { node: '>=6.0.0' } + '@asamuzakjp/css-color@3.2.0': + resolution: + { + integrity: sha512-K1A6z8tS3XsmCMM86xoWdn7Fkdn9m6RSVtocUrJYIwZnFVkng/PvkEoWtOWmP+Scc6saYWHWZYbndEEXxl24jw==, + } + '@babel/code-frame@7.23.5': resolution: { @@ -389,6 +401,49 @@ packages: } engines: { node: '>=6.9.0' } + '@csstools/color-helpers@5.1.0': + resolution: + { + integrity: sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==, + } + engines: { node: '>=18' } + + '@csstools/css-calc@2.1.4': + resolution: + { + integrity: sha512-3N8oaj+0juUw/1H3YwmDDJXCgTB1gKU6Hc/bB502u9zR0q2vd786XJH9QfrKIEgFlZmhZiq6epXl4rHqhzsIgQ==, + } + engines: { node: '>=18' } + peerDependencies: + '@csstools/css-parser-algorithms': ^3.0.5 + '@csstools/css-tokenizer': ^3.0.4 + + '@csstools/css-color-parser@3.1.0': + resolution: + { + integrity: sha512-nbtKwh3a6xNVIp/VRuXV64yTKnb1IjTAEEh3irzS+HkKjAOYLTGNb9pmVNntZ8iVBHcWDA2Dof0QtPgFI1BaTA==, + } + engines: { node: '>=18' } + peerDependencies: + '@csstools/css-parser-algorithms': ^3.0.5 + '@csstools/css-tokenizer': ^3.0.4 + + '@csstools/css-parser-algorithms@3.0.5': + resolution: + { + integrity: sha512-DaDeUkXZKjdGhgYaHNJTV9pV7Y9B3b644jCLs9Upc3VeNGg6LWARAT6O+Q+/COo+2gg/bM5rhpMAtf70WqfBdQ==, + } + engines: { node: '>=18' } + peerDependencies: + '@csstools/css-tokenizer': ^3.0.4 + + '@csstools/css-tokenizer@3.0.4': + resolution: + { + integrity: sha512-Vd/9EVDiu6PPJt9yAh6roZP6El1xHrdvIVGjyBsHR0RYwNHgL7FJPyIIW4fANJNG6FtyZfvlRPpFI4ZM/lubvw==, + } + engines: { node: '>=18' } + '@esbuild/aix-ppc64@0.19.12': resolution: { @@ -398,6 +453,15 @@ packages: cpu: [ppc64] os: [aix] + '@esbuild/aix-ppc64@0.21.5': + resolution: + { + integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==, + } + engines: { node: '>=12' } + cpu: [ppc64] + os: [aix] + '@esbuild/android-arm64@0.18.20': resolution: { @@ -416,6 +480,15 @@ packages: cpu: [arm64] os: [android] + '@esbuild/android-arm64@0.21.5': + resolution: + { + integrity: sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==, + } + engines: { node: '>=12' } + cpu: [arm64] + os: [android] + '@esbuild/android-arm@0.18.20': resolution: { @@ -434,6 +507,15 @@ packages: cpu: [arm] os: [android] + '@esbuild/android-arm@0.21.5': + resolution: + { + integrity: sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==, + } + engines: { node: '>=12' } + cpu: [arm] + os: [android] + '@esbuild/android-x64@0.18.20': resolution: { @@ -452,6 +534,15 @@ packages: cpu: [x64] os: [android] + '@esbuild/android-x64@0.21.5': + resolution: + { + integrity: sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [android] + '@esbuild/darwin-arm64@0.18.20': resolution: { @@ -470,6 +561,15 @@ packages: cpu: [arm64] os: [darwin] + '@esbuild/darwin-arm64@0.21.5': + resolution: + { + integrity: sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==, + } + engines: { node: '>=12' } + cpu: [arm64] + os: [darwin] + '@esbuild/darwin-x64@0.18.20': resolution: { @@ -488,6 +588,15 @@ packages: cpu: [x64] os: [darwin] + '@esbuild/darwin-x64@0.21.5': + resolution: + { + integrity: sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [darwin] + '@esbuild/freebsd-arm64@0.18.20': resolution: { @@ -506,6 +615,15 @@ packages: cpu: [arm64] os: [freebsd] + '@esbuild/freebsd-arm64@0.21.5': + resolution: + { + integrity: sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==, + } + engines: { node: '>=12' } + cpu: [arm64] + os: [freebsd] + '@esbuild/freebsd-x64@0.18.20': resolution: { @@ -524,6 +642,15 @@ packages: cpu: [x64] os: [freebsd] + '@esbuild/freebsd-x64@0.21.5': + resolution: + { + integrity: sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [freebsd] + '@esbuild/linux-arm64@0.18.20': resolution: { @@ -542,6 +669,15 @@ packages: cpu: [arm64] os: [linux] + '@esbuild/linux-arm64@0.21.5': + resolution: + { + integrity: sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==, + } + engines: { node: '>=12' } + cpu: [arm64] + os: [linux] + '@esbuild/linux-arm@0.18.20': resolution: { @@ -560,6 +696,15 @@ packages: cpu: [arm] os: [linux] + '@esbuild/linux-arm@0.21.5': + resolution: + { + integrity: sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==, + } + engines: { node: '>=12' } + cpu: [arm] + os: [linux] + '@esbuild/linux-ia32@0.18.20': resolution: { @@ -578,6 +723,15 @@ packages: cpu: [ia32] os: [linux] + '@esbuild/linux-ia32@0.21.5': + resolution: + { + integrity: sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==, + } + engines: { node: '>=12' } + cpu: [ia32] + os: [linux] + '@esbuild/linux-loong64@0.18.20': resolution: { @@ -596,6 +750,15 @@ packages: cpu: [loong64] os: [linux] + '@esbuild/linux-loong64@0.21.5': + resolution: + { + integrity: sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==, + } + engines: { node: '>=12' } + cpu: [loong64] + os: [linux] + '@esbuild/linux-mips64el@0.18.20': resolution: { @@ -614,6 +777,15 @@ packages: cpu: [mips64el] os: [linux] + '@esbuild/linux-mips64el@0.21.5': + resolution: + { + integrity: sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==, + } + engines: { node: '>=12' } + cpu: [mips64el] + os: [linux] + '@esbuild/linux-ppc64@0.18.20': resolution: { @@ -632,6 +804,15 @@ packages: cpu: [ppc64] os: [linux] + '@esbuild/linux-ppc64@0.21.5': + resolution: + { + integrity: sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==, + } + engines: { node: '>=12' } + cpu: [ppc64] + os: [linux] + '@esbuild/linux-riscv64@0.18.20': resolution: { @@ -650,6 +831,15 @@ packages: cpu: [riscv64] os: [linux] + '@esbuild/linux-riscv64@0.21.5': + resolution: + { + integrity: sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==, + } + engines: { node: '>=12' } + cpu: [riscv64] + os: [linux] + '@esbuild/linux-s390x@0.18.20': resolution: { @@ -668,6 +858,15 @@ packages: cpu: [s390x] os: [linux] + '@esbuild/linux-s390x@0.21.5': + resolution: + { + integrity: sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==, + } + engines: { node: '>=12' } + cpu: [s390x] + os: [linux] + '@esbuild/linux-x64@0.18.20': resolution: { @@ -686,6 +885,15 @@ packages: cpu: [x64] os: [linux] + '@esbuild/linux-x64@0.21.5': + resolution: + { + integrity: sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [linux] + '@esbuild/netbsd-x64@0.18.20': resolution: { @@ -704,6 +912,15 @@ packages: cpu: [x64] os: [netbsd] + '@esbuild/netbsd-x64@0.21.5': + resolution: + { + integrity: sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [netbsd] + '@esbuild/openbsd-x64@0.18.20': resolution: { @@ -722,6 +939,15 @@ packages: cpu: [x64] os: [openbsd] + '@esbuild/openbsd-x64@0.21.5': + resolution: + { + integrity: sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [openbsd] + '@esbuild/sunos-x64@0.18.20': resolution: { @@ -740,6 +966,15 @@ packages: cpu: [x64] os: [sunos] + '@esbuild/sunos-x64@0.21.5': + resolution: + { + integrity: sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [sunos] + '@esbuild/win32-arm64@0.18.20': resolution: { @@ -758,6 +993,15 @@ packages: cpu: [arm64] os: [win32] + '@esbuild/win32-arm64@0.21.5': + resolution: + { + integrity: sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==, + } + engines: { node: '>=12' } + cpu: [arm64] + os: [win32] + '@esbuild/win32-ia32@0.18.20': resolution: { @@ -776,6 +1020,15 @@ packages: cpu: [ia32] os: [win32] + '@esbuild/win32-ia32@0.21.5': + resolution: + { + integrity: sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==, + } + engines: { node: '>=12' } + cpu: [ia32] + os: [win32] + '@esbuild/win32-x64@0.18.20': resolution: { @@ -794,6 +1047,15 @@ packages: cpu: [x64] os: [win32] + '@esbuild/win32-x64@0.21.5': + resolution: + { + integrity: sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==, + } + engines: { node: '>=12' } + cpu: [x64] + os: [win32] + '@eslint-community/eslint-utils@4.4.0': resolution: { @@ -866,6 +1128,13 @@ packages: } engines: { node: '>=12' } + '@jest/schemas@29.6.3': + resolution: + { + integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==, + } + engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } + '@jridgewell/gen-mapping@0.3.3': resolution: { @@ -899,6 +1168,12 @@ packages: integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==, } + '@jridgewell/sourcemap-codec@1.6.0': + resolution: + { + integrity: sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==, + } + '@jridgewell/trace-mapping@0.3.22': resolution: { @@ -917,6 +1192,15 @@ packages: integrity: sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==, } + '@napi-rs/lzma-linux-x64-gnu@1.5.1': + resolution: + { + integrity: sha512-oTXEIha4SsuXdTA4Iyskj0kpdx2yVXdhd75c2v3xGrHFfVMsbhTPZU/nMPL4sWKo4pBHm3aucLaqGlF696dTyQ==, + } + engines: { node: ^22.20 || ^24.12 || >=25 } + cpu: [x64] + os: [linux] + '@next/env@14.1.0': resolution: { @@ -1158,12 +1442,218 @@ packages: engines: { node: '>=18' } hasBin: true + '@rollup/rollup-android-arm-eabi@4.66.0': + resolution: + { + integrity: sha512-7y4XeoUHPecjfUDRmap8U0q6bjfLAPn7uOGT8BKyqy8uNDOjsGS8rlBhOx6sZLVwwjN6hapvGl2mW9/IS6UNww==, + } + cpu: [arm] + os: [android] + + '@rollup/rollup-android-arm64@4.66.0': + resolution: + { + integrity: sha512-e8WugYZXpgqrlMXLCudYVRAxAcK7AIY36JxRDwFRD38L9q62G1VsEUW6ijXxzjxYjNB8i1zo3B/ycIQ/qjLC/Q==, + } + cpu: [arm64] + os: [android] + + '@rollup/rollup-darwin-arm64@4.66.0': + resolution: + { + integrity: sha512-6vkDCfyDjNLokh+Rt1D2KtNgFFMEPdkWha/mbtP4cSjh9xiN8T/JBS/A7nDYKjmMAXHrvR9J3AzUk2LtFbIBLg==, + } + cpu: [arm64] + os: [darwin] + + '@rollup/rollup-darwin-x64@4.66.0': + resolution: + { + integrity: sha512-/mzZAX0+Q6eXxvkR0HB0RZCCrsbmFD8DpsvCQoMYABDfq/DjqkbfytuJ7GvZ4AhR/Mgis2fXbZrGqfbcK2Z5fA==, + } + cpu: [x64] + os: [darwin] + + '@rollup/rollup-freebsd-arm64@4.66.0': + resolution: + { + integrity: sha512-JQJx9E8tUjGqed1RevDmoHaS3V30ODdV8uyvGxlwd4K5se6bkPrMeltSybqAtpJ+ltDRfo7FORQaJG2Hd5nGog==, + } + cpu: [arm64] + os: [freebsd] + + '@rollup/rollup-freebsd-x64@4.66.0': + resolution: + { + integrity: sha512-GEaUQQjMaG7X1304qMgqLjzCKv6CdDirzJSS+UqUs3xhJ9X2Kjzu0JDbLoUU42FWxwmZqz+SsgU1SlQv9GNRVA==, + } + cpu: [x64] + os: [freebsd] + + '@rollup/rollup-linux-arm-gnueabihf@4.66.0': + resolution: + { + integrity: sha512-DgmAU9N0NhDQDzHgFUocDio7zRO8jR/nY/obDGvCR8zbJ6J77Fg6X49yPuExJUpYPbC82EOaRhG969pWzUSnHQ==, + } + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm-musleabihf@4.66.0': + resolution: + { + integrity: sha512-zG09YZ+sk/HoHq+P9gYB0EseQ3M20RbDuKGWey6fbiMDV1LxfXvhgSW9jDaCcvFPMgfLXpimzXY+UYvA8R2mLQ==, + } + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm64-gnu@4.66.0': + resolution: + { + integrity: sha512-vlArhgyXbcVc1D4WZPoiYuqJIaMiSHBj6etRXua0KlfjlZeuiQyVAPYi0/N49O4mSp3u1iGUBLEjNa8ec81XZg==, + } + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-arm64-musl@4.66.0': + resolution: + { + integrity: sha512-RxJZtk0G87YPotDaRDvRqStV8cbqLSC5TroHvQHHKsqBg0ok64RxKgtXeFsa7FBcy7mb4crBrG3xK8USWIqWNA==, + } + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-loong64-gnu@4.66.0': + resolution: + { + integrity: sha512-qlGcw959PrLLkZhiBxF3OZ6SQvj+OKY85mCqGNgSRs4LZlDJ6ICqmz6UdxtINdhcXYwNIbZoapQVBAmZlD2hUQ==, + } + cpu: [loong64] + os: [linux] + + '@rollup/rollup-linux-loong64-musl@4.66.0': + resolution: + { + integrity: sha512-TvTI/7Cy0WvRA1SXgwzu6bwXBnMpmeT/ln5q7WvSpqmXy1VbmEnY8HVIDQNBiaHJvoWqRr0M4FNo7qiqtyMaFw==, + } + cpu: [loong64] + os: [linux] + + '@rollup/rollup-linux-ppc64-gnu@4.66.0': + resolution: + { + integrity: sha512-UZEDkSoDRZ50NyLj70nO6mpIK3dvs2cPTTvQb1bA/PBDmr9fvn5KiESuGfh6srd7Zi6Lt9Sv2sVrFr1QoHLvPQ==, + } + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-ppc64-musl@4.66.0': + resolution: + { + integrity: sha512-VRbxTvagLh3HRcysx1CNq+HHcvJbSebNI6fCbk7jwmmWHkXjrSIV3igXBpRHUTFdg0pagWGu50xoSZXnrZHjVQ==, + } + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-riscv64-gnu@4.66.0': + resolution: + { + integrity: sha512-uWdJpvYqh0LE/i+YBL3sMX0a2kUkICENjmrPmyBmMOFc3jMrs6MSQH/pMD+VIpGEoUcr3XkHGLLfymzIqPSRRg==, + } + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-riscv64-musl@4.66.0': + resolution: + { + integrity: sha512-3FUd88pxgWAjK60OgCrika1AcNG+u8zaCdWjg4TlcZTDkt5TGyci8ZU64l3OJ9ax0MEjw3P80B/3PoSQDCLwJQ==, + } + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-s390x-gnu@4.66.0': + resolution: + { + integrity: sha512-qT2rMmgyej62g5AdwktK+Bt2lBu497pzWZe12TTQ5JmZjOYPnEwcPEAOSLTBxBV+6gIES75rXm219v/QkT397A==, + } + cpu: [s390x] + os: [linux] + + '@rollup/rollup-linux-x64-gnu@4.66.0': + resolution: + { + integrity: sha512-E46rnZgp7J84Qwe8RMlF+rgimnDo/9fuiGbUArGB0ZkMWf97O7yeSCfKls5x/YJOF0RcuSe9RctuKe1hlxICiA==, + } + cpu: [x64] + os: [linux] + + '@rollup/rollup-linux-x64-musl@4.66.0': + resolution: + { + integrity: sha512-Uz1HiZe+qBzqgdPsON+z0wRx3WdATuyzwvGT6cr2VZVrqqko0ZJVfkrQJtwDMuDcAfXYdo7XucaxJ7lTLjEcgg==, + } + cpu: [x64] + os: [linux] + + '@rollup/rollup-openbsd-x64@4.66.0': + resolution: + { + integrity: sha512-Ph7TX3Ex5qdfcb7Tc6eEPugVkRfJ501eTovO4T5029YObfpZ7dzn3RiwpFvGp50nk2QUhvBMZ0PFGlEj6pOYTg==, + } + cpu: [x64] + os: [openbsd] + + '@rollup/rollup-openharmony-arm64@4.66.0': + resolution: + { + integrity: sha512-nZYPEya7ZkeNxUEiF7qmNZbyLTyRN3MK5cO22KqsaoneUzXJuzBIQRw+7BEQy9LGj2O5vrCE9V3EpK06FYo1tQ==, + } + cpu: [arm64] + os: [openharmony] + + '@rollup/rollup-win32-arm64-msvc@4.66.0': + resolution: + { + integrity: sha512-u7aTfS3R6C4hRsqXSzaO6qLZYLVuMkHMvcWlux4IM8IJif1VCl2cgPBSo5gSNoFoStQypQP+qwq8W1IyFBf1QQ==, + } + cpu: [arm64] + os: [win32] + + '@rollup/rollup-win32-ia32-msvc@4.66.0': + resolution: + { + integrity: sha512-e+i9ueHrH1Bafb0cf0woAIVJbYcoC8vRaD+vz+Xi8w6jz9cYJSV3vyKO6ELGSZ6g4W4MJOm2WPLN4/nQf77h7w==, + } + cpu: [ia32] + os: [win32] + + '@rollup/rollup-win32-x64-gnu@4.66.0': + resolution: + { + integrity: sha512-KfTCbrtr2zXTqH2E1F+uYlFTrYibxHKqPAHobpd8Kfg49cEHmuHebOidCTDRgqG1suaPFX7oejFQeGE71zWKfA==, + } + cpu: [x64] + os: [win32] + + '@rollup/rollup-win32-x64-msvc@4.66.0': + resolution: + { + integrity: sha512-xA+neBh1bqkqaS3b48T2UHZnDsTIpb9B0h+TdBzynjF/ymCpYndhfY10RqW0qSKB1HqqQA83mINVhAdwA+mETg==, + } + cpu: [x64] + os: [win32] + '@rushstack/eslint-patch@1.7.2': resolution: { integrity: sha512-RbhOOTCNoCrbfkRyoXODZp75MlpiHMgbE5MEBZAnnnLyQNgrigEj4p0lzsMDyc1zVsJDLrivB58tgg3emX0eEA==, } + '@sinclair/typebox@0.27.12': + resolution: + { + integrity: sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==, + } + '@swc/core-darwin-arm64@1.3.107': resolution: { @@ -1302,6 +1792,18 @@ packages: integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==, } + '@types/estree@1.0.10': + resolution: + { + integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==, + } + + '@types/estree@1.0.9': + resolution: + { + integrity: sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==, + } + '@types/json-schema@7.0.15': resolution: { @@ -1529,6 +2031,36 @@ packages: typescript: optional: true + '@vitest/expect@1.6.1': + resolution: + { + integrity: sha512-jXL+9+ZNIJKruofqXuuTClf44eSpcHlgj3CiuNihUF3Ioujtmc0zIa3UJOW5RjDK1YLBJZnWBlPuqhYycLioog==, + } + + '@vitest/runner@1.6.1': + resolution: + { + integrity: sha512-3nSnYXkVkf3mXFfE7vVyPmi3Sazhb/2cfZGGs0JRzFsPFvAMBEcrweV1V1GsrstdXeKCTXlJbvnQwGWgEIHmOA==, + } + + '@vitest/snapshot@1.6.1': + resolution: + { + integrity: sha512-WvidQuWAzU2p95u8GAKlRMqMyN1yOJkGHnx3M1PL9Raf7AQ1kwLKg04ADlCa3+OXUZE7BceOhVZiuWAbzCKcUQ==, + } + + '@vitest/spy@1.6.1': + resolution: + { + integrity: sha512-MGcMmpGkZebsMZhbQKkAf9CX5zGvjkBTqf8Zx3ApYWXr3wG+QvEu2eXWfnIIWYSJExIp4V9FCKDEeygzkYrXMw==, + } + + '@vitest/utils@1.6.1': + resolution: + { + integrity: sha512-jOrrUvXM4Av9ZWiG1EajNto0u96kWAhJ1LmPmJhXXQx/32MecEKd10pOLYgS2BQx1TgkGhloPU1ArDW2vvaY6g==, + } + acorn-jsx@5.3.2: resolution: { @@ -1537,6 +2069,13 @@ packages: peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 + acorn-walk@8.3.5: + resolution: + { + integrity: sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==, + } + engines: { node: '>=0.4.0' } + acorn@8.11.3: resolution: { @@ -1545,6 +2084,21 @@ packages: engines: { node: '>=0.4.0' } hasBin: true + acorn@8.19.0: + resolution: + { + integrity: sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw==, + } + engines: { node: '>=0.4.0' } + hasBin: true + + agent-base@7.1.4: + resolution: + { + integrity: sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==, + } + engines: { node: '>= 14' } + ajv@6.12.6: resolution: { @@ -1586,6 +2140,13 @@ packages: } engines: { node: '>=8' } + ansi-styles@5.2.0: + resolution: + { + integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==, + } + engines: { node: '>=10' } + ansi-styles@6.2.1: resolution: { @@ -1678,16 +2239,28 @@ packages: } engines: { node: '>= 0.4' } + assertion-error@1.1.0: + resolution: + { + integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==, + } + ast-types-flow@0.0.8: resolution: { integrity: sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==, } - asynciterator.prototype@1.0.0: + asynciterator.prototype@1.0.0: + resolution: + { + integrity: sha512-wwHYEIS0Q80f5mosx3L/dfG5t5rjEa9Ft51GTaNt862EnpyGHpgz2RkZvLPp1oF5TnAiTohkEKVEu8pQPJI7Vg==, + } + + asynckit@0.4.0: resolution: { - integrity: sha512-wwHYEIS0Q80f5mosx3L/dfG5t5rjEa9Ft51GTaNt862EnpyGHpgz2RkZvLPp1oF5TnAiTohkEKVEu8pQPJI7Vg==, + integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==, } autoprefixer@10.4.19: @@ -1804,6 +2377,13 @@ packages: } engines: { node: '>=8' } + call-bind-apply-helpers@1.0.2: + resolution: + { + integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==, + } + engines: { node: '>= 0.4' } + call-bind@1.0.5: resolution: { @@ -1836,6 +2416,13 @@ packages: integrity: sha512-bMg2vmr8XBsbL6Lr0UHXy/21m84FTxDLWn2FSqMd5PrlbMxwJlQnC2YWYxVgp66PZE+BBNF2jYQUBKCo1FDeZg==, } + chai@4.5.0: + resolution: + { + integrity: sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==, + } + engines: { node: '>=4' } + chalk@2.4.2: resolution: { @@ -1857,6 +2444,12 @@ packages: } engines: { node: ^12.17.0 || ^14.13 || >=16.0.0 } + check-error@1.0.3: + resolution: + { + integrity: sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==, + } + chokidar@3.5.3: resolution: { @@ -1929,6 +2522,13 @@ packages: integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==, } + combined-stream@1.0.8: + resolution: + { + integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==, + } + engines: { node: '>= 0.8' } + commander@11.0.0: resolution: { @@ -1955,6 +2555,12 @@ packages: integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==, } + confbox@0.1.8: + resolution: + { + integrity: sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==, + } + convert-source-map@2.0.0: resolution: { @@ -1983,6 +2589,13 @@ packages: engines: { node: '>=4' } hasBin: true + cssstyle@4.6.0: + resolution: + { + integrity: sha512-2z+rWdzbbSZv6/rhtvzvqeZQHrBaqgogqt85sqFNbabZOuFbCVFb8kPeEtZjiKkbrm395irpNKiYeFeLiQnFPg==, + } + engines: { node: '>=18' } + csstype@3.1.3: resolution: { @@ -1995,6 +2608,13 @@ packages: integrity: sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==, } + data-urls@5.0.0: + resolution: + { + integrity: sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==, + } + engines: { node: '>=18' } + debug@3.2.7: resolution: { @@ -2018,6 +2638,19 @@ packages: supports-color: optional: true + decimal.js@10.6.0: + resolution: + { + integrity: sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==, + } + + deep-eql@4.1.4: + resolution: + { + integrity: sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==, + } + engines: { node: '>=6' } + deep-is@0.1.4: resolution: { @@ -2038,6 +2671,13 @@ packages: } engines: { node: '>= 0.4' } + delayed-stream@1.0.0: + resolution: + { + integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==, + } + engines: { node: '>=0.4.0' } + dequal@2.0.3: resolution: { @@ -2065,6 +2705,13 @@ packages: integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==, } + diff-sequences@29.6.3: + resolution: + { + integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==, + } + engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } + dir-glob@3.0.1: resolution: { @@ -2092,6 +2739,13 @@ packages: } engines: { node: '>=6.0.0' } + dunder-proto@1.0.1: + resolution: + { + integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==, + } + engines: { node: '>= 0.4' } + eastasianwidth@0.2.0: resolution: { @@ -2129,6 +2783,13 @@ packages: } engines: { node: '>=10.13.0' } + entities@6.0.1: + resolution: + { + integrity: sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==, + } + engines: { node: '>=0.12' } + error-ex@1.3.2: resolution: { @@ -2142,12 +2803,33 @@ packages: } engines: { node: '>= 0.4' } + es-define-property@1.0.1: + resolution: + { + integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==, + } + engines: { node: '>= 0.4' } + + es-errors@1.3.0: + resolution: + { + integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==, + } + engines: { node: '>= 0.4' } + es-iterator-helpers@1.0.15: resolution: { integrity: sha512-GhoY8uYqd6iwUl2kgjTm4CZAf6oo5mHK7BPqx3rKgx893YSsy0LGHV6gfqqQvZt/8xM8xeOnfXBCfqclMKkJ5g==, } + es-object-atoms@1.1.2: + resolution: + { + integrity: sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==, + } + engines: { node: '>= 0.4' } + es-set-tostringtag@2.0.2: resolution: { @@ -2155,6 +2837,13 @@ packages: } engines: { node: '>= 0.4' } + es-set-tostringtag@2.1.0: + resolution: + { + integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==, + } + engines: { node: '>= 0.4' } + es-shim-unscopables@1.0.2: resolution: { @@ -2184,6 +2873,14 @@ packages: engines: { node: '>=12' } hasBin: true + esbuild@0.21.5: + resolution: + { + integrity: sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==, + } + engines: { node: '>=12' } + hasBin: true + escalade@3.1.1: resolution: { @@ -2476,6 +3173,12 @@ packages: } engines: { node: '>=4.0' } + estree-walker@3.0.3: + resolution: + { + integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==, + } + esutils@2.0.3: resolution: { @@ -2503,6 +3206,13 @@ packages: } engines: { node: ^14.18.0 || ^16.14.0 || >=18.0.0 } + execa@8.0.1: + resolution: + { + integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==, + } + engines: { node: '>=16.17' } + fast-deep-equal@3.1.3: resolution: { @@ -2588,6 +3298,13 @@ packages: } engines: { node: '>=14' } + form-data@4.0.6: + resolution: + { + integrity: sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==, + } + engines: { node: '>= 6' } + fraction.js@4.3.7: resolution: { @@ -2642,12 +3359,32 @@ packages: } engines: { node: '>=6.9.0' } + get-func-name@2.0.2: + resolution: + { + integrity: sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==, + } + get-intrinsic@1.2.2: resolution: { integrity: sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==, } + get-intrinsic@1.3.0: + resolution: + { + integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==, + } + engines: { node: '>= 0.4' } + + get-proto@1.0.1: + resolution: + { + integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==, + } + engines: { node: '>= 0.4' } + get-stdin@9.0.0: resolution: { @@ -2662,6 +3399,13 @@ packages: } engines: { node: '>=10' } + get-stream@8.0.1: + resolution: + { + integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==, + } + engines: { node: '>=16' } + get-symbol-description@1.0.0: resolution: { @@ -2759,6 +3503,13 @@ packages: integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==, } + gopd@1.2.0: + resolution: + { + integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==, + } + engines: { node: '>= 0.4' } + graceful-fs@4.2.11: resolution: { @@ -2811,6 +3562,13 @@ packages: } engines: { node: '>= 0.4' } + has-symbols@1.1.0: + resolution: + { + integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==, + } + engines: { node: '>= 0.4' } + has-tostringtag@1.0.2: resolution: { @@ -2825,12 +3583,40 @@ packages: } engines: { node: '>= 0.4' } + hasown@2.0.4: + resolution: + { + integrity: sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==, + } + engines: { node: '>= 0.4' } + hosted-git-info@2.8.9: resolution: { integrity: sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==, } + html-encoding-sniffer@4.0.0: + resolution: + { + integrity: sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==, + } + engines: { node: '>=18' } + + http-proxy-agent@7.0.2: + resolution: + { + integrity: sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==, + } + engines: { node: '>= 14' } + + https-proxy-agent@7.0.6: + resolution: + { + integrity: sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==, + } + engines: { node: '>= 14' } + human-signals@2.1.0: resolution: { @@ -2845,6 +3631,13 @@ packages: } engines: { node: '>=14.18.0' } + human-signals@5.0.0: + resolution: + { + integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==, + } + engines: { node: '>=16.17.0' } + husky@8.0.3: resolution: { @@ -2853,6 +3646,13 @@ packages: engines: { node: '>=14' } hasBin: true + iconv-lite@0.6.3: + resolution: + { + integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==, + } + engines: { node: '>=0.10.0' } + ignore@5.3.1: resolution: { @@ -3049,6 +3849,12 @@ packages: } engines: { node: '>=12' } + is-potential-custom-element-name@1.0.1: + resolution: + { + integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==, + } + is-regex@1.1.4: resolution: { @@ -3172,6 +3978,12 @@ packages: integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==, } + js-tokens@9.0.1: + resolution: + { + integrity: sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==, + } + js-yaml@4.1.0: resolution: { @@ -3179,6 +3991,18 @@ packages: } hasBin: true + jsdom@24.1.3: + resolution: + { + integrity: sha512-MyL55p3Ut3cXbeBEG7Hcv0mVM8pp8PBNWxRqchZnSfAiES1v1mRnMeFfaHWIPULpwsYfvO+ZmMZz5tGCnjzDUQ==, + } + engines: { node: '>=18' } + peerDependencies: + canvas: ^2.11.2 + peerDependenciesMeta: + canvas: + optional: true + jsesc@0.5.0: resolution: { @@ -3321,6 +4145,13 @@ packages: } engines: { node: ^12.20.0 || ^14.13.1 || >=16.0.0 } + local-pkg@0.5.1: + resolution: + { + integrity: sha512-9rrA30MRRP3gBD3HTGnC6cDFpaE1kVDWxWgqWJUN0RvDNAo+Nz/9GxB+nHOH0ifbVFy0hSA1V6vFDvnx54lTEQ==, + } + engines: { node: '>=14' } + locate-path@5.0.0: resolution: { @@ -3367,6 +4198,12 @@ packages: } hasBin: true + loupe@2.3.7: + resolution: + { + integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==, + } + lru-cache@10.2.0: resolution: { @@ -3374,6 +4211,12 @@ packages: } engines: { node: 14 || >=16.14 } + lru-cache@10.4.3: + resolution: + { + integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==, + } + lru-cache@5.1.1: resolution: { @@ -3387,6 +4230,19 @@ packages: } engines: { node: '>=10' } + magic-string@0.30.21: + resolution: + { + integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==, + } + + math-intrinsics@1.1.0: + resolution: + { + integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==, + } + engines: { node: '>= 0.4' } + merge-stream@2.0.0: resolution: { @@ -3407,6 +4263,20 @@ packages: } engines: { node: '>=8.6' } + mime-db@1.52.0: + resolution: + { + integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==, + } + engines: { node: '>= 0.6' } + + mime-types@2.1.35: + resolution: + { + integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==, + } + engines: { node: '>= 0.6' } + mimic-fn@2.1.0: resolution: { @@ -3454,6 +4324,12 @@ packages: } engines: { node: '>=16 || 14 >=14.17' } + mlly@1.8.2: + resolution: + { + integrity: sha512-d+ObxMQFmbt10sretNDytwt85VrbkhhUA/JBGm1MPaWJ65Cl4wOgLaB1NYvJSZ0Ef03MMEU/0xpPMXUIQ29UfA==, + } + ms@2.1.2: resolution: { @@ -3472,6 +4348,14 @@ packages: integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==, } + nanoid@3.3.20: + resolution: + { + integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==, + } + engines: { node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1 } + hasBin: true + nanoid@3.3.7: resolution: { @@ -3567,6 +4451,12 @@ packages: } engines: { node: ^12.20.0 || ^14.13.1 || >=16.0.0 } + nwsapi@2.2.28: + resolution: + { + integrity: sha512-IlVB7OS7qrOsVYlpnFIkETjMwT9jwvmocJmmM+GZU/PAB3uGi9Ezd7vcWhWBUnSc0ya4ppmQITOyP1ez9gg8cg==, + } + object-assign@4.1.1: resolution: { @@ -3675,6 +4565,13 @@ packages: } engines: { node: '>=10' } + p-limit@5.0.0: + resolution: + { + integrity: sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==, + } + engines: { node: '>=18' } + p-locate@4.1.0: resolution: { @@ -3710,6 +4607,12 @@ packages: } engines: { node: '>=8' } + parse5@7.3.0: + resolution: + { + integrity: sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==, + } + path-exists@4.0.0: resolution: { @@ -3758,6 +4661,24 @@ packages: } engines: { node: '>=8' } + pathe@1.1.2: + resolution: + { + integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==, + } + + pathe@2.0.3: + resolution: + { + integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==, + } + + pathval@1.1.1: + resolution: + { + integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==, + } + picocolors@1.0.0: resolution: { @@ -3770,6 +4691,12 @@ packages: integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==, } + picocolors@1.1.1: + resolution: + { + integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==, + } + picomatch@2.3.1: resolution: { @@ -3799,6 +4726,12 @@ packages: } engines: { node: '>= 6' } + pkg-types@1.3.1: + resolution: + { + integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==, + } + playwright-core@1.52.0: resolution: { @@ -3887,7 +4820,14 @@ packages: postcss@8.4.38: resolution: { - integrity: sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==, + integrity: sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==, + } + engines: { node: ^10 || ^12 || >=14 } + + postcss@8.5.32: + resolution: + { + integrity: sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==, } engines: { node: ^10 || ^12 || >=14 } @@ -3925,12 +4865,25 @@ packages: engines: { node: '>=14' } hasBin: true + pretty-format@29.7.0: + resolution: + { + integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==, + } + engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } + prop-types@15.8.1: resolution: { integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==, } + psl@1.15.0: + resolution: + { + integrity: sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==, + } + punycode@2.3.1: resolution: { @@ -3938,6 +4891,12 @@ packages: } engines: { node: '>=6' } + querystringify@2.2.0: + resolution: + { + integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==, + } + queue-microtask@1.2.3: resolution: { @@ -3958,6 +4917,12 @@ packages: integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==, } + react-is@18.3.1: + resolution: + { + integrity: sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==, + } + react@18.2.0: resolution: { @@ -4026,6 +4991,12 @@ packages: } hasBin: true + requires-port@1.0.0: + resolution: + { + integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==, + } + resolve-from@4.0.0: resolution: { @@ -4102,6 +5073,26 @@ packages: engines: { node: '>=14.18.0', npm: '>=8.0.0' } hasBin: true + rollup@4.66.0: + resolution: + { + integrity: sha512-Onq6/qO4ARhxIs+jYiHE0pYehadLyMECAiGEqQ+0/aWND3+2PmifJIIqBLYtuBODqHTlOUEQFtIVPyCy0Lck7A==, + } + engines: { node: '>=18.0.0', npm: '>=8.0.0' } + hasBin: true + + rrweb-cssom@0.7.1: + resolution: + { + integrity: sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==, + } + + rrweb-cssom@0.8.0: + resolution: + { + integrity: sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==, + } + run-parallel@1.2.0: resolution: { @@ -4122,6 +5113,19 @@ packages: } engines: { node: '>= 0.4' } + safer-buffer@2.1.2: + resolution: + { + integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==, + } + + saxes@6.0.0: + resolution: + { + integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==, + } + engines: { node: '>=v12.22.7' } + scheduler@0.23.0: resolution: { @@ -4190,6 +5194,12 @@ packages: integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==, } + siginfo@2.0.0: + resolution: + { + integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==, + } + signal-exit@3.0.7: resolution: { @@ -4244,6 +5254,13 @@ packages: } engines: { node: '>=0.10.0' } + source-map-js@1.2.2: + resolution: + { + integrity: sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==, + } + engines: { node: '>=0.10.0' } + source-map-support@0.5.21: resolution: { @@ -4289,6 +5306,18 @@ packages: integrity: sha512-eWN+LnM3GR6gPu35WxNgbGl8rmY1AEmoMDvL/QD6zYmPWgywxWqJWNdLGT+ke8dKNWrcYgYjPpG5gbTfghP8rw==, } + stackback@0.0.2: + resolution: + { + integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==, + } + + std-env@3.10.0: + resolution: + { + integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==, + } + streamsearch@1.1.0: resolution: { @@ -4391,6 +5420,12 @@ packages: } engines: { node: '>=8' } + strip-literal@2.1.1: + resolution: + { + integrity: sha512-631UJ6O00eNGfMiWG78ck80dfBab8X6IVFB51jZK5Icd7XAs60Z5y7QdSd/wGIklnWvRbUNloVzhOKKmutxQ6Q==, + } + styled-jsx@5.1.1: resolution: { @@ -4436,6 +5471,12 @@ packages: } engines: { node: '>= 0.4' } + symbol-tree@3.2.4: + resolution: + { + integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==, + } + synckit@0.9.0: resolution: { @@ -4485,6 +5526,26 @@ packages: integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==, } + tinybench@2.9.0: + resolution: + { + integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==, + } + + tinypool@0.8.4: + resolution: + { + integrity: sha512-i11VH5gS6IFeLY3gMBQ00/MmLncVP7JLXOw1vlgkytLmJK7QnEr7NXf0LBdxfmNPAeyetukOk0bOYrJrFGjYJQ==, + } + engines: { node: '>=14.0.0' } + + tinyspy@2.2.1: + resolution: + { + integrity: sha512-KYad6Vy5VDWV4GH3fjpseMQ/XU2BhIYP7Vzd0LG44qRWm/Yt2WCOTicFdvmgo6gWaqooMQCawTtILVQJupKu7A==, + } + engines: { node: '>=14.0.0' } + to-fast-properties@2.0.0: resolution: { @@ -4499,12 +5560,26 @@ packages: } engines: { node: '>=8.0' } + tough-cookie@4.1.4: + resolution: + { + integrity: sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==, + } + engines: { node: '>=6' } + tr46@1.0.1: resolution: { integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==, } + tr46@5.1.1: + resolution: + { + integrity: sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==, + } + engines: { node: '>=18' } + tree-kill@1.2.2: resolution: { @@ -4580,6 +5655,13 @@ packages: } engines: { node: '>= 0.8.0' } + type-detect@4.1.0: + resolution: + { + integrity: sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==, + } + engines: { node: '>=4' } + type-fest@0.20.2: resolution: { @@ -4651,6 +5733,12 @@ packages: engines: { node: '>=14.17' } hasBin: true + ufo@1.6.4: + resolution: + { + integrity: sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==, + } + unbox-primitive@1.0.2: resolution: { @@ -4663,6 +5751,13 @@ packages: integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==, } + universalify@0.2.0: + resolution: + { + integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==, + } + engines: { node: '>= 4.0.0' } + update-browserslist-db@1.0.13: resolution: { @@ -4687,6 +5782,12 @@ packages: integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==, } + url-parse@1.5.10: + resolution: + { + integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==, + } + util-deprecate@1.0.2: resolution: { @@ -4699,12 +5800,118 @@ packages: integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==, } + vite-node@1.6.1: + resolution: + { + integrity: sha512-YAXkfvGtuTzwWbDSACdJSg4A4DZiAqckWe90Zapc/sEX3XvHcw1NdurM/6od8J207tSDqNbSsgdCacBgvJKFuA==, + } + engines: { node: ^18.0.0 || >=20.0.0 } + hasBin: true + + vite@5.4.21: + resolution: + { + integrity: sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==, + } + engines: { node: ^18.0.0 || >=20.0.0 } + hasBin: true + peerDependencies: + '@types/node': ^18.0.0 || >=20.0.0 + less: '*' + lightningcss: ^1.21.0 + sass: '*' + sass-embedded: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + + vitest@1.6.1: + resolution: + { + integrity: sha512-Ljb1cnSJSivGN0LqXd/zmDbWEM0RNNg2t1QW/XUhYl/qPqyu7CsqeWtqQXHVaJsecLPuDoak2oJcZN2QoRIOag==, + } + engines: { node: ^18.0.0 || >=20.0.0 } + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@types/node': ^18.0.0 || >=20.0.0 + '@vitest/browser': 1.6.1 + '@vitest/ui': 1.6.1 + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@types/node': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + + w3c-xmlserializer@5.0.0: + resolution: + { + integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==, + } + engines: { node: '>=18' } + webidl-conversions@4.0.2: resolution: { integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==, } + webidl-conversions@7.0.0: + resolution: + { + integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==, + } + engines: { node: '>=12' } + + whatwg-encoding@3.1.1: + resolution: + { + integrity: sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==, + } + engines: { node: '>=18' } + deprecated: Use @exodus/bytes instead for a more spec-conformant and faster implementation + + whatwg-mimetype@4.0.0: + resolution: + { + integrity: sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==, + } + engines: { node: '>=18' } + + whatwg-url@14.2.0: + resolution: + { + integrity: sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==, + } + engines: { node: '>=18' } + whatwg-url@7.1.0: resolution: { @@ -4745,6 +5952,14 @@ packages: engines: { node: '>= 8' } hasBin: true + why-is-node-running@2.3.0: + resolution: + { + integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==, + } + engines: { node: '>=8' } + hasBin: true + wrap-ansi@7.0.0: resolution: { @@ -4765,6 +5980,34 @@ packages: integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==, } + ws@8.22.0: + resolution: + { + integrity: sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==, + } + engines: { node: '>=10.0.0' } + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + + xml-name-validator@5.0.0: + resolution: + { + integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==, + } + engines: { node: '>=18' } + + xmlchars@2.2.0: + resolution: + { + integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==, + } + yallist@3.1.1: resolution: { @@ -4798,6 +6041,13 @@ packages: } engines: { node: '>=10' } + yocto-queue@1.2.2: + resolution: + { + integrity: sha512-4LCcse/U2MHZ63HAJVE+v71o7yOdIe4cZ70Wpf8D/IyjDKYQLV5GD46B+hSTjJsvV5PztjvHoU580EftxjDZFQ==, + } + engines: { node: '>=12.20' } + snapshots: '@aashutoshrathi/word-wrap@1.2.6': {} @@ -4808,6 +6058,14 @@ snapshots: '@jridgewell/gen-mapping': 0.3.3 '@jridgewell/trace-mapping': 0.3.22 + '@asamuzakjp/css-color@3.2.0': + dependencies: + '@csstools/css-calc': 2.1.4(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4) + '@csstools/css-color-parser': 3.1.0(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4) + '@csstools/css-parser-algorithms': 3.0.5(@csstools/css-tokenizer@3.0.4) + '@csstools/css-tokenizer': 3.0.4 + lru-cache: 10.4.3 + '@babel/code-frame@7.23.5': dependencies: '@babel/highlight': 7.23.4 @@ -4953,141 +6211,230 @@ snapshots: '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 + '@csstools/color-helpers@5.1.0': {} + + '@csstools/css-calc@2.1.4(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4)': + dependencies: + '@csstools/css-parser-algorithms': 3.0.5(@csstools/css-tokenizer@3.0.4) + '@csstools/css-tokenizer': 3.0.4 + + '@csstools/css-color-parser@3.1.0(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4)': + dependencies: + '@csstools/color-helpers': 5.1.0 + '@csstools/css-calc': 2.1.4(@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4))(@csstools/css-tokenizer@3.0.4) + '@csstools/css-parser-algorithms': 3.0.5(@csstools/css-tokenizer@3.0.4) + '@csstools/css-tokenizer': 3.0.4 + + '@csstools/css-parser-algorithms@3.0.5(@csstools/css-tokenizer@3.0.4)': + dependencies: + '@csstools/css-tokenizer': 3.0.4 + + '@csstools/css-tokenizer@3.0.4': {} + '@esbuild/aix-ppc64@0.19.12': optional: true + '@esbuild/aix-ppc64@0.21.5': + optional: true + '@esbuild/android-arm64@0.18.20': optional: true '@esbuild/android-arm64@0.19.12': optional: true + '@esbuild/android-arm64@0.21.5': + optional: true + '@esbuild/android-arm@0.18.20': optional: true '@esbuild/android-arm@0.19.12': optional: true + '@esbuild/android-arm@0.21.5': + optional: true + '@esbuild/android-x64@0.18.20': optional: true '@esbuild/android-x64@0.19.12': optional: true + '@esbuild/android-x64@0.21.5': + optional: true + '@esbuild/darwin-arm64@0.18.20': optional: true '@esbuild/darwin-arm64@0.19.12': optional: true + '@esbuild/darwin-arm64@0.21.5': + optional: true + '@esbuild/darwin-x64@0.18.20': optional: true '@esbuild/darwin-x64@0.19.12': optional: true + '@esbuild/darwin-x64@0.21.5': + optional: true + '@esbuild/freebsd-arm64@0.18.20': optional: true '@esbuild/freebsd-arm64@0.19.12': optional: true + '@esbuild/freebsd-arm64@0.21.5': + optional: true + '@esbuild/freebsd-x64@0.18.20': optional: true '@esbuild/freebsd-x64@0.19.12': optional: true + '@esbuild/freebsd-x64@0.21.5': + optional: true + '@esbuild/linux-arm64@0.18.20': optional: true '@esbuild/linux-arm64@0.19.12': optional: true + '@esbuild/linux-arm64@0.21.5': + optional: true + '@esbuild/linux-arm@0.18.20': optional: true '@esbuild/linux-arm@0.19.12': optional: true + '@esbuild/linux-arm@0.21.5': + optional: true + '@esbuild/linux-ia32@0.18.20': optional: true '@esbuild/linux-ia32@0.19.12': optional: true + '@esbuild/linux-ia32@0.21.5': + optional: true + '@esbuild/linux-loong64@0.18.20': optional: true '@esbuild/linux-loong64@0.19.12': optional: true + '@esbuild/linux-loong64@0.21.5': + optional: true + '@esbuild/linux-mips64el@0.18.20': optional: true '@esbuild/linux-mips64el@0.19.12': optional: true + '@esbuild/linux-mips64el@0.21.5': + optional: true + '@esbuild/linux-ppc64@0.18.20': optional: true '@esbuild/linux-ppc64@0.19.12': optional: true + '@esbuild/linux-ppc64@0.21.5': + optional: true + '@esbuild/linux-riscv64@0.18.20': optional: true '@esbuild/linux-riscv64@0.19.12': optional: true + '@esbuild/linux-riscv64@0.21.5': + optional: true + '@esbuild/linux-s390x@0.18.20': optional: true '@esbuild/linux-s390x@0.19.12': optional: true + '@esbuild/linux-s390x@0.21.5': + optional: true + '@esbuild/linux-x64@0.18.20': optional: true '@esbuild/linux-x64@0.19.12': optional: true + '@esbuild/linux-x64@0.21.5': + optional: true + '@esbuild/netbsd-x64@0.18.20': optional: true '@esbuild/netbsd-x64@0.19.12': optional: true + '@esbuild/netbsd-x64@0.21.5': + optional: true + '@esbuild/openbsd-x64@0.18.20': optional: true '@esbuild/openbsd-x64@0.19.12': optional: true + '@esbuild/openbsd-x64@0.21.5': + optional: true + '@esbuild/sunos-x64@0.18.20': optional: true '@esbuild/sunos-x64@0.19.12': optional: true + '@esbuild/sunos-x64@0.21.5': + optional: true + '@esbuild/win32-arm64@0.18.20': optional: true '@esbuild/win32-arm64@0.19.12': optional: true + '@esbuild/win32-arm64@0.21.5': + optional: true + '@esbuild/win32-ia32@0.18.20': optional: true '@esbuild/win32-ia32@0.19.12': optional: true + '@esbuild/win32-ia32@0.21.5': + optional: true + '@esbuild/win32-x64@0.18.20': optional: true '@esbuild/win32-x64@0.19.12': optional: true + '@esbuild/win32-x64@0.21.5': + optional: true + '@eslint-community/eslint-utils@4.4.0(eslint@8.43.0)': dependencies: eslint: 8.43.0 @@ -5141,6 +6488,10 @@ snapshots: wrap-ansi: 8.1.0 wrap-ansi-cjs: wrap-ansi@7.0.0 + '@jest/schemas@29.6.3': + dependencies: + '@sinclair/typebox': 0.27.12 + '@jridgewell/gen-mapping@0.3.3': dependencies: '@jridgewell/set-array': 1.1.2 @@ -5158,6 +6509,8 @@ snapshots: '@jridgewell/sourcemap-codec@1.4.15': {} + '@jridgewell/sourcemap-codec@1.6.0': {} + '@jridgewell/trace-mapping@0.3.22': dependencies: '@jridgewell/resolve-uri': 3.1.1 @@ -5172,6 +6525,9 @@ snapshots: '@microsoft/tsdoc@0.14.2': {} + '@napi-rs/lzma-linux-x64-gnu@1.5.1': + optional: true + '@next/env@14.1.0': {} '@next/env@14.2.4': {} @@ -5267,8 +6623,85 @@ snapshots: dependencies: playwright: 1.52.0 + '@rollup/rollup-android-arm-eabi@4.66.0': + optional: true + + '@rollup/rollup-android-arm64@4.66.0': + optional: true + + '@rollup/rollup-darwin-arm64@4.66.0': + optional: true + + '@rollup/rollup-darwin-x64@4.66.0': + optional: true + + '@rollup/rollup-freebsd-arm64@4.66.0': + optional: true + + '@rollup/rollup-freebsd-x64@4.66.0': + optional: true + + '@rollup/rollup-linux-arm-gnueabihf@4.66.0': + optional: true + + '@rollup/rollup-linux-arm-musleabihf@4.66.0': + optional: true + + '@rollup/rollup-linux-arm64-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-arm64-musl@4.66.0': + optional: true + + '@rollup/rollup-linux-loong64-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-loong64-musl@4.66.0': + optional: true + + '@rollup/rollup-linux-ppc64-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-ppc64-musl@4.66.0': + optional: true + + '@rollup/rollup-linux-riscv64-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-riscv64-musl@4.66.0': + optional: true + + '@rollup/rollup-linux-s390x-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-x64-gnu@4.66.0': + optional: true + + '@rollup/rollup-linux-x64-musl@4.66.0': + optional: true + + '@rollup/rollup-openbsd-x64@4.66.0': + optional: true + + '@rollup/rollup-openharmony-arm64@4.66.0': + optional: true + + '@rollup/rollup-win32-arm64-msvc@4.66.0': + optional: true + + '@rollup/rollup-win32-ia32-msvc@4.66.0': + optional: true + + '@rollup/rollup-win32-x64-gnu@4.66.0': + optional: true + + '@rollup/rollup-win32-x64-msvc@4.66.0': + optional: true + '@rushstack/eslint-patch@1.7.2': {} + '@sinclair/typebox@0.27.12': {} + '@swc/core-darwin-arm64@1.3.107': optional: true @@ -5333,6 +6766,10 @@ snapshots: '@types/cookie@0.6.0': {} + '@types/estree@1.0.10': {} + + '@types/estree@1.0.9': {} + '@types/json-schema@7.0.15': {} '@types/json5@0.0.29': {} @@ -5668,12 +7105,49 @@ snapshots: - jest - supports-color + '@vitest/expect@1.6.1': + dependencies: + '@vitest/spy': 1.6.1 + '@vitest/utils': 1.6.1 + chai: 4.5.0 + + '@vitest/runner@1.6.1': + dependencies: + '@vitest/utils': 1.6.1 + p-limit: 5.0.0 + pathe: 1.1.2 + + '@vitest/snapshot@1.6.1': + dependencies: + magic-string: 0.30.21 + pathe: 1.1.2 + pretty-format: 29.7.0 + + '@vitest/spy@1.6.1': + dependencies: + tinyspy: 2.2.1 + + '@vitest/utils@1.6.1': + dependencies: + diff-sequences: 29.6.3 + estree-walker: 3.0.3 + loupe: 2.3.7 + pretty-format: 29.7.0 + acorn-jsx@5.3.2(acorn@8.11.3): dependencies: acorn: 8.11.3 + acorn-walk@8.3.5: + dependencies: + acorn: 8.11.3 + acorn@8.11.3: {} + acorn@8.19.0: {} + + agent-base@7.1.4: {} + ajv@6.12.6: dependencies: fast-deep-equal: 3.1.3 @@ -5697,6 +7171,8 @@ snapshots: dependencies: color-convert: 2.0.1 + ansi-styles@5.2.0: {} + ansi-styles@6.2.1: {} any-promise@1.3.0: {} @@ -5769,12 +7245,16 @@ snapshots: is-array-buffer: 3.0.2 is-shared-array-buffer: 1.0.2 + assertion-error@1.1.0: {} + ast-types-flow@0.0.8: {} asynciterator.prototype@1.0.0: dependencies: has-symbols: 1.0.3 + asynckit@0.4.0: {} + autoprefixer@10.4.19(postcss@8.4.38): dependencies: browserslist: 4.23.1 @@ -5839,6 +7319,11 @@ snapshots: cac@6.7.14: {} + call-bind-apply-helpers@1.0.2: + dependencies: + es-errors: 1.3.0 + function-bind: 1.1.2 + call-bind@1.0.5: dependencies: function-bind: 1.1.2 @@ -5853,6 +7338,16 @@ snapshots: caniuse-lite@1.0.30001636: {} + chai@4.5.0: + dependencies: + assertion-error: 1.1.0 + check-error: 1.0.3 + deep-eql: 4.1.4 + get-func-name: 2.0.2 + loupe: 2.3.7 + pathval: 1.1.1 + type-detect: 4.1.0 + chalk@2.4.2: dependencies: ansi-styles: 3.2.1 @@ -5866,6 +7361,10 @@ snapshots: chalk@5.3.0: {} + check-error@1.0.3: + dependencies: + get-func-name: 2.0.2 + chokidar@3.5.3: dependencies: anymatch: 3.1.3 @@ -5909,6 +7408,10 @@ snapshots: colorette@2.0.20: {} + combined-stream@1.0.8: + dependencies: + delayed-stream: 1.0.0 + commander@11.0.0: {} commander@2.20.3: {} @@ -5917,6 +7420,8 @@ snapshots: concat-map@0.0.1: {} + confbox@0.1.8: {} + convert-source-map@2.0.0: {} cookie@0.6.0: {} @@ -5929,10 +7434,20 @@ snapshots: cssesc@3.0.0: {} + cssstyle@4.6.0: + dependencies: + '@asamuzakjp/css-color': 3.2.0 + rrweb-cssom: 0.8.0 + csstype@3.1.3: {} damerau-levenshtein@1.0.8: {} + data-urls@5.0.0: + dependencies: + whatwg-mimetype: 4.0.0 + whatwg-url: 14.2.0 + debug@3.2.7: dependencies: ms: 2.1.3 @@ -5941,6 +7456,12 @@ snapshots: dependencies: ms: 2.1.2 + decimal.js@10.6.0: {} + + deep-eql@4.1.4: + dependencies: + type-detect: 4.1.0 + deep-is@0.1.4: {} define-data-property@1.1.1: @@ -5955,6 +7476,8 @@ snapshots: has-property-descriptors: 1.0.1 object-keys: 1.1.1 + delayed-stream@1.0.0: {} + dequal@2.0.3: {} detect-indent@7.0.1: {} @@ -5963,6 +7486,8 @@ snapshots: didyoumean@1.2.2: {} + diff-sequences@29.6.3: {} + dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -5977,6 +7502,12 @@ snapshots: dependencies: esutils: 2.0.3 + dunder-proto@1.0.1: + dependencies: + call-bind-apply-helpers: 1.0.2 + es-errors: 1.3.0 + gopd: 1.2.0 + eastasianwidth@0.2.0: {} electron-to-chromium@1.4.656: {} @@ -5992,6 +7523,8 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 + entities@6.0.1: {} + error-ex@1.3.2: dependencies: is-arrayish: 0.2.1 @@ -6038,6 +7571,10 @@ snapshots: unbox-primitive: 1.0.2 which-typed-array: 1.1.14 + es-define-property@1.0.1: {} + + es-errors@1.3.0: {} + es-iterator-helpers@1.0.15: dependencies: asynciterator.prototype: 1.0.0 @@ -6055,12 +7592,23 @@ snapshots: iterator.prototype: 1.1.2 safe-array-concat: 1.1.0 + es-object-atoms@1.1.2: + dependencies: + es-errors: 1.3.0 + es-set-tostringtag@2.0.2: dependencies: get-intrinsic: 1.2.2 has-tostringtag: 1.0.2 hasown: 2.0.0 + es-set-tostringtag@2.1.0: + dependencies: + es-errors: 1.3.0 + get-intrinsic: 1.3.0 + has-tostringtag: 1.0.2 + hasown: 2.0.4 + es-shim-unscopables@1.0.2: dependencies: hasown: 2.0.0 @@ -6122,6 +7670,32 @@ snapshots: '@esbuild/win32-ia32': 0.19.12 '@esbuild/win32-x64': 0.19.12 + esbuild@0.21.5: + optionalDependencies: + '@esbuild/aix-ppc64': 0.21.5 + '@esbuild/android-arm': 0.21.5 + '@esbuild/android-arm64': 0.21.5 + '@esbuild/android-x64': 0.21.5 + '@esbuild/darwin-arm64': 0.21.5 + '@esbuild/darwin-x64': 0.21.5 + '@esbuild/freebsd-arm64': 0.21.5 + '@esbuild/freebsd-x64': 0.21.5 + '@esbuild/linux-arm': 0.21.5 + '@esbuild/linux-arm64': 0.21.5 + '@esbuild/linux-ia32': 0.21.5 + '@esbuild/linux-loong64': 0.21.5 + '@esbuild/linux-mips64el': 0.21.5 + '@esbuild/linux-ppc64': 0.21.5 + '@esbuild/linux-riscv64': 0.21.5 + '@esbuild/linux-s390x': 0.21.5 + '@esbuild/linux-x64': 0.21.5 + '@esbuild/netbsd-x64': 0.21.5 + '@esbuild/openbsd-x64': 0.21.5 + '@esbuild/sunos-x64': 0.21.5 + '@esbuild/win32-arm64': 0.21.5 + '@esbuild/win32-ia32': 0.21.5 + '@esbuild/win32-x64': 0.21.5 + escalade@3.1.1: {} escalade@3.1.2: {} @@ -6208,7 +7782,7 @@ snapshots: debug: 4.3.4 enhanced-resolve: 5.15.0 eslint: 8.43.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) fast-glob: 3.3.2 get-tsconfig: 4.7.2 @@ -6265,7 +7839,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0): + eslint-module-utils@2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0): dependencies: debug: 3.2.7 optionalDependencies: @@ -6336,7 +7910,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.43.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.43.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.20.0(eslint@8.56.0)(typescript@5.3.3))(eslint@8.43.0))(eslint@8.43.0))(eslint@8.43.0) hasown: 2.0.0 is-core-module: 2.13.1 is-glob: 4.0.3 @@ -6678,6 +8252,10 @@ snapshots: estraverse@5.3.0: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.10 + esutils@2.0.3: {} eventemitter3@5.0.1: {} @@ -6706,6 +8284,18 @@ snapshots: signal-exit: 3.0.7 strip-final-newline: 3.0.0 + execa@8.0.1: + dependencies: + cross-spawn: 7.0.3 + get-stream: 8.0.1 + human-signals: 5.0.0 + is-stream: 3.0.0 + merge-stream: 2.0.0 + npm-run-path: 5.2.0 + onetime: 6.0.0 + signal-exit: 4.1.0 + strip-final-newline: 3.0.0 + fast-deep-equal@3.1.3: {} fast-glob@3.3.2: @@ -6759,6 +8349,14 @@ snapshots: cross-spawn: 7.0.3 signal-exit: 4.1.0 + form-data@4.0.6: + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + es-set-tostringtag: 2.1.0 + hasown: 2.0.4 + mime-types: 2.1.35 + fraction.js@4.3.7: {} fs.realpath@1.0.0: {} @@ -6782,6 +8380,8 @@ snapshots: gensync@1.0.0-beta.2: {} + get-func-name@2.0.2: {} + get-intrinsic@1.2.2: dependencies: function-bind: 1.1.2 @@ -6789,10 +8389,30 @@ snapshots: has-symbols: 1.0.3 hasown: 2.0.0 + get-intrinsic@1.3.0: + dependencies: + call-bind-apply-helpers: 1.0.2 + es-define-property: 1.0.1 + es-errors: 1.3.0 + es-object-atoms: 1.1.2 + function-bind: 1.1.2 + get-proto: 1.0.1 + gopd: 1.2.0 + has-symbols: 1.1.0 + hasown: 2.0.4 + math-intrinsics: 1.1.0 + + get-proto@1.0.1: + dependencies: + dunder-proto: 1.0.1 + es-object-atoms: 1.1.2 + get-stdin@9.0.0: {} get-stream@6.0.1: {} + get-stream@8.0.1: {} + get-symbol-description@1.0.0: dependencies: call-bind: 1.0.5 @@ -6869,6 +8489,8 @@ snapshots: dependencies: get-intrinsic: 1.2.2 + gopd@1.2.0: {} + graceful-fs@4.2.11: {} graphemer@1.4.0: {} @@ -6887,6 +8509,8 @@ snapshots: has-symbols@1.0.3: {} + has-symbols@1.1.0: {} + has-tostringtag@1.0.2: dependencies: has-symbols: 1.0.3 @@ -6895,14 +8519,42 @@ snapshots: dependencies: function-bind: 1.1.2 + hasown@2.0.4: + dependencies: + function-bind: 1.1.2 + hosted-git-info@2.8.9: {} + html-encoding-sniffer@4.0.0: + dependencies: + whatwg-encoding: 3.1.1 + + http-proxy-agent@7.0.2: + dependencies: + agent-base: 7.1.4 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + + https-proxy-agent@7.0.6: + dependencies: + agent-base: 7.1.4 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + human-signals@2.1.0: {} human-signals@4.3.1: {} + human-signals@5.0.0: {} + husky@8.0.3: {} + iconv-lite@0.6.3: + dependencies: + safer-buffer: 2.1.2 + ignore@5.3.1: {} import-fresh@3.3.0: @@ -6998,6 +8650,8 @@ snapshots: is-plain-obj@4.1.0: {} + is-potential-custom-element-name@1.0.1: {} + is-regex@1.1.4: dependencies: call-bind: 1.0.5 @@ -7062,10 +8716,40 @@ snapshots: js-tokens@4.0.0: {} + js-tokens@9.0.1: {} + js-yaml@4.1.0: dependencies: argparse: 2.0.1 + jsdom@24.1.3: + dependencies: + cssstyle: 4.6.0 + data-urls: 5.0.0 + decimal.js: 10.6.0 + form-data: 4.0.6 + html-encoding-sniffer: 4.0.0 + http-proxy-agent: 7.0.2 + https-proxy-agent: 7.0.6 + is-potential-custom-element-name: 1.0.1 + nwsapi: 2.2.28 + parse5: 7.3.0 + rrweb-cssom: 0.7.1 + saxes: 6.0.0 + symbol-tree: 3.2.4 + tough-cookie: 4.1.4 + w3c-xmlserializer: 5.0.0 + webidl-conversions: 7.0.0 + whatwg-encoding: 3.1.1 + whatwg-mimetype: 4.0.0 + whatwg-url: 14.2.0 + ws: 8.22.0 + xml-name-validator: 5.0.0 + transitivePeerDependencies: + - bufferutil + - supports-color + - utf-8-validate + jsesc@0.5.0: {} jsesc@2.5.2: {} @@ -7141,6 +8825,11 @@ snapshots: load-tsconfig@0.2.5: {} + local-pkg@0.5.1: + dependencies: + mlly: 1.8.2 + pkg-types: 1.3.1 + locate-path@5.0.0: dependencies: p-locate: 4.1.0 @@ -7167,8 +8856,14 @@ snapshots: dependencies: js-tokens: 4.0.0 + loupe@2.3.7: + dependencies: + get-func-name: 2.0.2 + lru-cache@10.2.0: {} + lru-cache@10.4.3: {} + lru-cache@5.1.1: dependencies: yallist: 3.1.1 @@ -7177,6 +8872,12 @@ snapshots: dependencies: yallist: 4.0.0 + magic-string@0.30.21: + dependencies: + '@jridgewell/sourcemap-codec': 1.6.0 + + math-intrinsics@1.1.0: {} + merge-stream@2.0.0: {} merge2@1.4.1: {} @@ -7186,6 +8887,12 @@ snapshots: braces: 3.0.2 picomatch: 2.3.1 + mime-db@1.52.0: {} + + mime-types@2.1.35: + dependencies: + mime-db: 1.52.0 + mimic-fn@2.1.0: {} mimic-fn@4.0.0: {} @@ -7204,6 +8911,13 @@ snapshots: minipass@7.0.4: {} + mlly@1.8.2: + dependencies: + acorn: 8.19.0 + pathe: 2.0.3 + pkg-types: 1.3.1 + ufo: 1.6.4 + ms@2.1.2: {} ms@2.1.3: {} @@ -7214,6 +8928,8 @@ snapshots: object-assign: 4.1.1 thenify-all: 1.6.0 + nanoid@3.3.20: {} + nanoid@3.3.7: {} natural-compare@1.4.0: {} @@ -7290,6 +9006,8 @@ snapshots: dependencies: path-key: 4.0.0 + nwsapi@2.2.28: {} + object-assign@4.1.1: {} object-hash@3.0.0: {} @@ -7364,6 +9082,10 @@ snapshots: dependencies: yocto-queue: 0.1.0 + p-limit@5.0.0: + dependencies: + yocto-queue: 1.2.2 + p-locate@4.1.0: dependencies: p-limit: 2.3.0 @@ -7385,6 +9107,10 @@ snapshots: json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 + parse5@7.3.0: + dependencies: + entities: 6.0.1 + path-exists@4.0.0: {} path-is-absolute@1.0.1: {} @@ -7402,10 +9128,18 @@ snapshots: path-type@4.0.0: {} + pathe@1.1.2: {} + + pathe@2.0.3: {} + + pathval@1.1.1: {} + picocolors@1.0.0: {} picocolors@1.0.1: {} + picocolors@1.1.1: {} + picomatch@2.3.1: {} pidtree@0.6.0: {} @@ -7414,6 +9148,12 @@ snapshots: pirates@4.0.6: {} + pkg-types@1.3.1: + dependencies: + confbox: 0.1.8 + mlly: 1.8.2 + pathe: 2.0.3 + playwright-core@1.52.0: {} playwright@1.52.0: @@ -7443,6 +9183,13 @@ snapshots: optionalDependencies: postcss: 8.4.38 + postcss-load-config@4.0.2(postcss@8.5.32): + dependencies: + lilconfig: 3.0.0 + yaml: 2.3.4 + optionalDependencies: + postcss: 8.5.32 + postcss-nested@6.0.1(postcss@8.4.38): dependencies: postcss: 8.4.38 @@ -7467,6 +9214,12 @@ snapshots: picocolors: 1.0.0 source-map-js: 1.2.0 + postcss@8.5.32: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.2 + prelude-ls@1.2.1: {} prettier-plugin-packagejson@2.4.10(prettier@2.8.8): @@ -7487,14 +9240,26 @@ snapshots: prettier@3.2.4: {} + pretty-format@29.7.0: + dependencies: + '@jest/schemas': 29.6.3 + ansi-styles: 5.2.0 + react-is: 18.3.1 + prop-types@15.8.1: dependencies: loose-envify: 1.4.0 object-assign: 4.1.1 react-is: 16.13.1 + psl@1.15.0: + dependencies: + punycode: 2.3.1 + punycode@2.3.1: {} + querystringify@2.2.0: {} + queue-microtask@1.2.3: {} react-dom@18.2.0(react@18.2.0): @@ -7505,6 +9270,8 @@ snapshots: react-is@16.13.1: {} + react-is@18.3.1: {} + react@18.2.0: dependencies: loose-envify: 1.4.0 @@ -7553,6 +9320,8 @@ snapshots: dependencies: jsesc: 0.5.0 + requires-port@1.0.0: {} + resolve-from@4.0.0: {} resolve-from@5.0.0: {} @@ -7593,6 +9362,42 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + rollup@4.66.0: + dependencies: + '@types/estree': 1.0.9 + optionalDependencies: + '@napi-rs/lzma-linux-x64-gnu': 1.5.1 + '@rollup/rollup-android-arm-eabi': 4.66.0 + '@rollup/rollup-android-arm64': 4.66.0 + '@rollup/rollup-darwin-arm64': 4.66.0 + '@rollup/rollup-darwin-x64': 4.66.0 + '@rollup/rollup-freebsd-arm64': 4.66.0 + '@rollup/rollup-freebsd-x64': 4.66.0 + '@rollup/rollup-linux-arm-gnueabihf': 4.66.0 + '@rollup/rollup-linux-arm-musleabihf': 4.66.0 + '@rollup/rollup-linux-arm64-gnu': 4.66.0 + '@rollup/rollup-linux-arm64-musl': 4.66.0 + '@rollup/rollup-linux-loong64-gnu': 4.66.0 + '@rollup/rollup-linux-loong64-musl': 4.66.0 + '@rollup/rollup-linux-ppc64-gnu': 4.66.0 + '@rollup/rollup-linux-ppc64-musl': 4.66.0 + '@rollup/rollup-linux-riscv64-gnu': 4.66.0 + '@rollup/rollup-linux-riscv64-musl': 4.66.0 + '@rollup/rollup-linux-s390x-gnu': 4.66.0 + '@rollup/rollup-linux-x64-gnu': 4.66.0 + '@rollup/rollup-linux-x64-musl': 4.66.0 + '@rollup/rollup-openbsd-x64': 4.66.0 + '@rollup/rollup-openharmony-arm64': 4.66.0 + '@rollup/rollup-win32-arm64-msvc': 4.66.0 + '@rollup/rollup-win32-ia32-msvc': 4.66.0 + '@rollup/rollup-win32-x64-gnu': 4.66.0 + '@rollup/rollup-win32-x64-msvc': 4.66.0 + fsevents: 2.3.3 + + rrweb-cssom@0.7.1: {} + + rrweb-cssom@0.8.0: {} + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -7610,6 +9415,12 @@ snapshots: get-intrinsic: 1.2.2 is-regex: 1.1.4 + safer-buffer@2.1.2: {} + + saxes@6.0.0: + dependencies: + xmlchars: 2.2.0 + scheduler@0.23.0: dependencies: loose-envify: 1.4.0 @@ -7650,6 +9461,8 @@ snapshots: get-intrinsic: 1.2.2 object-inspect: 1.13.1 + siginfo@2.0.0: {} + signal-exit@3.0.7: {} signal-exit@4.1.0: {} @@ -7677,6 +9490,8 @@ snapshots: source-map-js@1.2.0: {} + source-map-js@1.2.2: {} + source-map-support@0.5.21: dependencies: buffer-from: 1.1.2 @@ -7702,6 +9517,10 @@ snapshots: spdx-license-ids@3.0.16: {} + stackback@0.0.2: {} + + std-env@3.10.0: {} + streamsearch@1.1.0: {} string-argv@0.3.2: {} @@ -7768,6 +9587,10 @@ snapshots: strip-json-comments@3.1.1: {} + strip-literal@2.1.1: + dependencies: + js-tokens: 9.0.1 + styled-jsx@5.1.1(@babel/core@7.23.9)(react@18.2.0): dependencies: client-only: 0.0.1 @@ -7795,6 +9618,8 @@ snapshots: supports-preserve-symlinks-flag@1.0.0: {} + symbol-tree@3.2.4: {} + synckit@0.9.0: dependencies: '@pkgr/core': 0.1.1 @@ -7846,16 +9671,33 @@ snapshots: dependencies: any-promise: 1.3.0 + tinybench@2.9.0: {} + + tinypool@0.8.4: {} + + tinyspy@2.2.1: {} + to-fast-properties@2.0.0: {} to-regex-range@5.0.1: dependencies: is-number: 7.0.0 + tough-cookie@4.1.4: + dependencies: + psl: 1.15.0 + punycode: 2.3.1 + universalify: 0.2.0 + url-parse: 1.5.10 + tr46@1.0.1: dependencies: punycode: 2.3.1 + tr46@5.1.1: + dependencies: + punycode: 2.3.1 + tree-kill@1.2.2: {} ts-api-utils@1.0.3(typescript@5.1.3): @@ -7879,7 +9721,7 @@ snapshots: tslib@2.6.2: {} - tsup@7.1.0(@swc/core@1.3.107(@swc/helpers@0.5.5))(postcss@8.4.38)(typescript@5.3.3): + tsup@7.1.0(@swc/core@1.3.107(@swc/helpers@0.5.5))(postcss@8.5.32)(typescript@5.3.3): dependencies: bundle-require: 4.0.2(esbuild@0.18.20) cac: 6.7.14 @@ -7889,7 +9731,7 @@ snapshots: execa: 5.1.1 globby: 11.1.0 joycon: 3.1.1 - postcss-load-config: 4.0.2(postcss@8.4.38) + postcss-load-config: 4.0.2(postcss@8.5.32) resolve-from: 5.0.0 rollup: 3.29.4 source-map: 0.8.0-beta.0 @@ -7897,7 +9739,7 @@ snapshots: tree-kill: 1.2.2 optionalDependencies: '@swc/core': 1.3.107(@swc/helpers@0.5.5) - postcss: 8.4.38 + postcss: 8.5.32 typescript: 5.3.3 transitivePeerDependencies: - supports-color @@ -7917,6 +9759,8 @@ snapshots: dependencies: prelude-ls: 1.2.1 + type-detect@4.1.0: {} + type-fest@0.20.2: {} type-fest@0.6.0: {} @@ -7956,6 +9800,8 @@ snapshots: typescript@5.3.3: {} + ufo@1.6.4: {} + unbox-primitive@1.0.2: dependencies: call-bind: 1.0.5 @@ -7965,6 +9811,8 @@ snapshots: undici-types@5.26.5: {} + universalify@0.2.0: {} + update-browserslist-db@1.0.13(browserslist@4.22.3): dependencies: browserslist: 4.22.3 @@ -7981,6 +9829,11 @@ snapshots: dependencies: punycode: 2.3.1 + url-parse@1.5.10: + dependencies: + querystringify: 2.2.0 + requires-port: 1.0.0 + util-deprecate@1.0.2: {} validate-npm-package-license@3.0.4: @@ -7988,8 +9841,88 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 + vite-node@1.6.1(@types/node@20.11.16)(terser@5.39.0): + dependencies: + cac: 6.7.14 + debug: 4.3.4 + pathe: 1.1.2 + picocolors: 1.0.1 + vite: 5.4.21(@types/node@20.11.16)(terser@5.39.0) + transitivePeerDependencies: + - '@types/node' + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + + vite@5.4.21(@types/node@20.11.16)(terser@5.39.0): + dependencies: + esbuild: 0.21.5 + postcss: 8.5.32 + rollup: 4.66.0 + optionalDependencies: + '@types/node': 20.11.16 + fsevents: 2.3.3 + terser: 5.39.0 + + vitest@1.6.1(@types/node@20.11.16)(jsdom@24.1.3)(terser@5.39.0): + dependencies: + '@vitest/expect': 1.6.1 + '@vitest/runner': 1.6.1 + '@vitest/snapshot': 1.6.1 + '@vitest/spy': 1.6.1 + '@vitest/utils': 1.6.1 + acorn-walk: 8.3.5 + chai: 4.5.0 + debug: 4.3.4 + execa: 8.0.1 + local-pkg: 0.5.1 + magic-string: 0.30.21 + pathe: 1.1.2 + picocolors: 1.0.1 + std-env: 3.10.0 + strip-literal: 2.1.1 + tinybench: 2.9.0 + tinypool: 0.8.4 + vite: 5.4.21(@types/node@20.11.16)(terser@5.39.0) + vite-node: 1.6.1(@types/node@20.11.16)(terser@5.39.0) + why-is-node-running: 2.3.0 + optionalDependencies: + '@types/node': 20.11.16 + jsdom: 24.1.3 + transitivePeerDependencies: + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + + w3c-xmlserializer@5.0.0: + dependencies: + xml-name-validator: 5.0.0 + webidl-conversions@4.0.2: {} + webidl-conversions@7.0.0: {} + + whatwg-encoding@3.1.1: + dependencies: + iconv-lite: 0.6.3 + + whatwg-mimetype@4.0.0: {} + + whatwg-url@14.2.0: + dependencies: + tr46: 5.1.1 + webidl-conversions: 7.0.0 + whatwg-url@7.1.0: dependencies: lodash.sortby: 4.7.0 @@ -8038,6 +9971,11 @@ snapshots: dependencies: isexe: 2.0.0 + why-is-node-running@2.3.0: + dependencies: + siginfo: 2.0.0 + stackback: 0.0.2 + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 @@ -8052,6 +9990,12 @@ snapshots: wrappy@1.0.2: {} + ws@8.22.0: {} + + xml-name-validator@5.0.0: {} + + xmlchars@2.2.0: {} + yallist@3.1.1: {} yallist@4.0.0: {} @@ -8061,3 +10005,5 @@ snapshots: yaml@2.3.4: {} yocto-queue@0.1.0: {} + + yocto-queue@1.2.2: {} From fd8b61a5dc5ab1938bc0fdf122dadb78dd6d513c Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 30 Oct 2026 15:49:57 +0530 Subject: [PATCH 03/55] Document the trackIdentity option --- packages/web/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/web/README.md b/packages/web/README.md index 0402709..edf3805 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -86,6 +86,16 @@ import { Analytics as DubAnalytics } from "@dub/analytics" The query parameter to listen to for client-side click-tracking (e.g. `?via=john`, `?ref=jane`). The default is `via`. +### `trackIdentity` + +Identifies the visitor's device with [Fingerprint](https://fingerprint.com) and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. The default is `false`. + +It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The Fingerprint agent is loaded only when this is on, and failures never throw or block the page. + +```tsx + +``` + ### `scriptProps` Custom properties to pass to the script tag. Refer to [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement) for all available options. \ No newline at end of file From 1960931b03668505e2ad4a6a513041b9408f6c61 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 30 Oct 2026 15:55:12 +0530 Subject: [PATCH 04/55] Updated --- packages/web/README.md | 4 ++-- packages/web/src/identity.ts | 2 +- packages/web/src/types.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index edf3805..c2b594f 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -88,9 +88,9 @@ The query parameter to listen to for client-side click-tracking (e.g. `?via=john ### `trackIdentity` -Identifies the visitor's device with [Fingerprint](https://fingerprint.com) and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. The default is `false`. +Identifies the visitor's device and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. The default is `false`. -It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The Fingerprint agent is loaded only when this is on, and failures never throw or block the page. +It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The device identification agent is loaded only when this is on, and failures never throw or block the page. ```tsx diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts index eaa79d9..8ab7d81 100644 --- a/packages/web/src/identity.ts +++ b/packages/web/src/identity.ts @@ -31,7 +31,7 @@ async function waitForClickId( } /** - * Identifies the visitor's device with Fingerprint and links it to their Dub click. + * Identifies the visitor's device and links it to their Dub click. * Runs only for visitors with a `dub_id` cookie, at most once per click every 30 minutes. */ export async function trackIdentity({ diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 933fe4d..3114419 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -155,7 +155,7 @@ export interface AnalyticsProps { queryParams?: string[]; /** - * Identify the visitor's device with Fingerprint and link it to their Dub click, to detect + * Identify the visitor's device and link it to their Dub click, to detect * partners referring several customers from one device. Only runs for visitors with a `dub_id` cookie. * * @default false From fbc162bfd0e309cca13e8d720b5afca7a68551a4 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 15:54:29 +0530 Subject: [PATCH 05/55] Drop stale freshness note from trackIdentity comment --- packages/web/src/identity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts index 8ab7d81..61d9edd 100644 --- a/packages/web/src/identity.ts +++ b/packages/web/src/identity.ts @@ -52,7 +52,7 @@ export async function trackIdentity({ const { start } = await import('@fingerprint/agent'); - // The server reads the click from linkedId and rejects events older than 10 seconds + // The server reads the click from linkedId const { sealed_result: sealedResult } = await start({ apiKey: FINGERPRINT_PUBLIC_KEY, }).get({ From 99332138dd4f57791b943cc1571426f12cccbc25 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 15:54:30 +0530 Subject: [PATCH 06/55] Match the identity response field in trackIdentity test mock --- packages/web/src/identity.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/src/identity.test.ts b/packages/web/src/identity.test.ts index fb5d597..05f7a59 100644 --- a/packages/web/src/identity.test.ts +++ b/packages/web/src/identity.test.ts @@ -51,7 +51,7 @@ describe('trackIdentity', () => { fetchMock.mockResolvedValue( new Response( JSON.stringify({ - clickIdentityId: 'cid_1', + clickIdentificationId: 'cid_1', }), ), ); From 62b79f56d4843a3d036a9f1a3f5229899eee7548 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:22:44 +0530 Subject: [PATCH 07/55] Scope trackIdentity to configured paths and client-side navigation --- packages/web/src/generic.ts | 9 +- packages/web/src/identity.test.ts | 141 +++++++++++++++++++++++++++++- packages/web/src/identity.ts | 92 +++++++++++++++++-- packages/web/src/types.ts | 9 +- 4 files changed, 234 insertions(+), 17 deletions(-) diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index fc84498..6fa8de0 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -1,5 +1,5 @@ import { name, version } from '../package.json'; -import { trackIdentity } from './identity'; +import { watchIdentityPaths } from './identity'; import type { AnalyticsProps } from './types'; import { isBrowser } from './utils'; @@ -89,9 +89,12 @@ function inject(props: AnalyticsProps): void { Object.assign(script, restProps); } - if (props.trackIdentity) { + const { trackIdentity } = props; + + if (trackIdentity) { script.addEventListener('load', () => { - void trackIdentity({ + watchIdentityPaths({ + paths: trackIdentity.paths, apiHost: props.apiHost, }); }); diff --git a/packages/web/src/identity.test.ts b/packages/web/src/identity.test.ts index 05f7a59..f9cc2bb 100644 --- a/packages/web/src/identity.test.ts +++ b/packages/web/src/identity.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { trackIdentity } from './identity'; +import { trackIdentity, watchIdentityPaths } from './identity'; const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; const SEALED_RESULT = 'noXc7Q=='; @@ -20,6 +20,7 @@ vi.mock('@fingerprint/agent', () => ({ })); const fetchMock = vi.fn(); +const { pushState, replaceState } = window.history; function clearCookies(): void { document.cookie.split(';').forEach((cookie) => { @@ -28,6 +29,12 @@ function clearCookies(): void { }); } +function flush(): Promise { + return new Promise((resolve) => { + setTimeout(resolve, 0); + }); +} + function getCookie(name: string): string | undefined { return document.cookie .split(';') @@ -58,6 +65,9 @@ describe('trackIdentity', () => { }); afterEach(() => { + window.history.pushState = pushState; + window.history.replaceState = replaceState; + window.history.replaceState(null, '', '/'); vi.useRealTimers(); vi.unstubAllGlobals(); vi.clearAllMocks(); @@ -190,4 +200,133 @@ describe('trackIdentity', () => { expect(getCookie('dub_fid')).toBeUndefined(); }); + + it('shares one identification between concurrent calls', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + await Promise.all([trackIdentity({}), trackIdentity({})]); + + expect(get).toHaveBeenCalledTimes(1); + expect(fetchMock).toHaveBeenCalledTimes(1); + }); +}); + +describe('watchIdentityPaths', () => { + beforeEach(() => { + clearCookies(); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + vi.stubGlobal('fetch', fetchMock); + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + get.mockResolvedValue({ + event_id: 'evt_1', + sealed_result: { + base64: () => SEALED_RESULT, + }, + }); + + fetchMock.mockResolvedValue(new Response('{}')); + }); + + afterEach(() => { + window.history.pushState = pushState; + window.history.replaceState = replaceState; + window.history.replaceState(null, '', '/'); + vi.unstubAllGlobals(); + vi.clearAllMocks(); + }); + + it.each([ + ['/signup', ['/signup']], + ['/signup/', ['/signup']], + ['/checkout', ['/checkout/*']], + ['/checkout/plan/pro', ['/checkout/*']], + ['/anything', ['/*']], + ])('identifies on %s for paths %j', async (pathname, paths) => { + window.history.replaceState(null, '', pathname); + + watchIdentityPaths({ + paths, + }); + + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + }); + + it.each([ + ['/', ['/signup']], + ['/signup/step-2', ['/signup']], + ['/signup-old', ['/signup']], + ['/checkouts', ['/checkout/*']], + ])('skips %s for paths %j', async (pathname, paths) => { + window.history.replaceState(null, '', pathname); + + watchIdentityPaths({ + paths, + }); + await flush(); + + expect(start).not.toHaveBeenCalled(); + }); + + it('identifies after a client-side navigation to a matching path', async () => { + watchIdentityPaths({ + paths: ['/signup'], + apiHost: 'https://api.example.com', + }); + await flush(); + + expect(start).not.toHaveBeenCalled(); + + window.history.pushState(null, '', '/signup'); + + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledWith( + 'https://api.example.com/track/identity', + expect.anything(), + ); + }); + }); + + it('identifies when going back to a matching path', async () => { + window.history.replaceState(null, '', '/signup'); + watchIdentityPaths({ + paths: ['/signup'], + }); + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + + clearCookies(); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + window.history.pushState(null, '', '/pricing'); + await flush(); + replaceState.call(window.history, null, '', '/signup'); + + expect(start).toHaveBeenCalledTimes(1); + + window.dispatchEvent(new PopStateEvent('popstate')); + + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(2); + }); + }); + + it('ignores history updates that keep the same path', async () => { + window.history.replaceState(null, '', '/signup'); + watchIdentityPaths({ + paths: ['/signup'], + }); + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + + clearCookies(); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + window.history.replaceState(null, '', '/signup?step=2'); + await flush(); + + expect(start).toHaveBeenCalledTimes(1); + }); }); diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts index 61d9edd..ecd3875 100644 --- a/packages/web/src/identity.ts +++ b/packages/web/src/identity.ts @@ -6,6 +6,8 @@ const CLICK_ID_POLL_ATTEMPTS = 5; const CLICK_ID_POLL_INTERVAL_MS = 1000; const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; +let pendingIdentity: Promise | undefined; + function getCookie(name: string): string | undefined { return document.cookie .split(';') @@ -30,15 +32,25 @@ async function waitForClickId( return waitForClickId(attemptsLeft - 1); } -/** - * Identifies the visitor's device and links it to their Dub click. - * Runs only for visitors with a `dub_id` cookie, at most once per click every 30 minutes. - */ -export async function trackIdentity({ - apiHost = DEFAULT_API_HOST, -}: { - apiHost?: string; -}): Promise { +function normalizePath(path: string): string { + return path.length > 1 ? path.replace(/\/+$/, '') : path; +} + +function matchesIdentityPath(pathname: string, paths: string[]): boolean { + const current = normalizePath(pathname); + + return paths.some((path) => { + if (path.endsWith('/*')) { + const base = normalizePath(path.slice(0, -2)); + + return base === '' || current === base || current.startsWith(`${base}/`); + } + + return current === normalizePath(path); + }); +} + +async function identify(apiHost: string): Promise { try { if (!FINGERPRINT_PUBLIC_KEY) { return; @@ -87,3 +99,65 @@ export async function trackIdentity({ console.warn('[Dub Web Analytics] identity tracking failed.', error); } } + +/** + * Identifies the visitor's device and links it to their Dub click. + * Runs only for visitors with a `dub_id` cookie, at most once per click every 30 minutes. + */ +export function trackIdentity({ + apiHost = DEFAULT_API_HOST, +}: { + apiHost?: string; +}): Promise { + pendingIdentity ??= identify(apiHost).finally(() => { + pendingIdentity = undefined; + }); + + return pendingIdentity; +} + +/** + * Runs trackIdentity on the current page and on every client-side navigation to one of the paths. + */ +export function watchIdentityPaths({ + paths, + apiHost, +}: { + paths: string[]; + apiHost?: string; +}): void { + let lastPathname: string | undefined; + + const check = (): void => { + const { pathname } = window.location; + + if (pathname === lastPathname) { + return; + } + + lastPathname = pathname; + + if (matchesIdentityPath(pathname, paths)) { + void trackIdentity({ + apiHost, + }); + } + }; + + const pushState = window.history.pushState.bind(window.history); + const replaceState = window.history.replaceState.bind(window.history); + + window.history.pushState = (...args) => { + pushState(...args); + check(); + }; + + window.history.replaceState = (...args) => { + replaceState(...args); + check(); + }; + + window.addEventListener('popstate', check); + + check(); +} diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 3114419..0100d6f 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -155,12 +155,13 @@ export interface AnalyticsProps { queryParams?: string[]; /** - * Identify the visitor's device and link it to their Dub click, to detect + * Identify the visitor's device on these paths and link it to their Dub click, to detect * partners referring several customers from one device. Only runs for visitors with a `dub_id` cookie. - * - * @default false + * Paths match exactly; a trailing `/*` also matches everything under the path (e.g. `/checkout/*`). */ - trackIdentity?: boolean; + trackIdentity?: { + paths: string[]; + }; /** * Custom properties to pass to the script. From 23cad32a3a213bfad4b09095e3583bec446f62fa Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:22:51 +0530 Subject: [PATCH 08/55] Expose trackIdentity on window.dubAnalytics and useAnalytics --- packages/web/src/generic.test.ts | 75 +++++++++++++++++++++++++++++++ packages/web/src/generic.ts | 24 +++++++--- packages/web/src/use-analytics.ts | 10 +++++ 3 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 packages/web/src/generic.test.ts diff --git a/packages/web/src/generic.test.ts b/packages/web/src/generic.test.ts new file mode 100644 index 0000000..80f32ab --- /dev/null +++ b/packages/web/src/generic.test.ts @@ -0,0 +1,75 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { inject } from './generic'; + +const { trackIdentity, watchIdentityPaths } = vi.hoisted(() => ({ + trackIdentity: vi.fn(() => Promise.resolve()), + watchIdentityPaths: vi.fn(), +})); + +vi.mock('./identity', () => ({ + trackIdentity, + watchIdentityPaths, +})); + +function loadScript(): void { + const script = document.head.querySelector('script'); + + window.dubAnalytics = Object.assign(() => undefined, { + trackClick: vi.fn(), + trackLead: vi.fn(), + trackSale: vi.fn(), + }); + script?.dispatchEvent(new Event('load')); +} + +describe('inject', () => { + beforeEach(() => { + document.head.innerHTML = ''; + delete (window as Partial).dubAnalytics; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + it('exposes trackIdentity before and after the script replaces window.dubAnalytics', async () => { + inject({ + apiHost: 'https://api.example.com', + }); + + await window.dubAnalytics.trackIdentity?.(); + + loadScript(); + await window.dubAnalytics.trackIdentity?.(); + + expect(trackIdentity).toHaveBeenCalledTimes(2); + expect(trackIdentity).toHaveBeenCalledWith({ + apiHost: 'https://api.example.com', + }); + }); + + it('watches the trackIdentity paths once the script loads', () => { + inject({ + apiHost: 'https://api.example.com', + trackIdentity: { + paths: ['/signup'], + }, + }); + + expect(watchIdentityPaths).not.toHaveBeenCalled(); + + loadScript(); + + expect(watchIdentityPaths).toHaveBeenCalledWith({ + paths: ['/signup'], + apiHost: 'https://api.example.com', + }); + }); + + it('does not watch paths without trackIdentity', () => { + inject({}); + loadScript(); + + expect(watchIdentityPaths).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index 6fa8de0..6c7d993 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -1,5 +1,5 @@ import { name, version } from '../package.json'; -import { watchIdentityPaths } from './identity'; +import { trackIdentity, watchIdentityPaths } from './identity'; import type { AnalyticsProps } from './types'; import { isBrowser } from './utils'; @@ -89,16 +89,26 @@ function inject(props: AnalyticsProps): void { Object.assign(script, restProps); } - const { trackIdentity } = props; + const attachTrackIdentity = (): void => { + (window as DubAnalyticsWindow).dubAnalytics.trackIdentity = () => + trackIdentity({ + apiHost: props.apiHost, + }); + }; + + attachTrackIdentity(); - if (trackIdentity) { - script.addEventListener('load', () => { + // The script replaces window.dubAnalytics when it loads + script.addEventListener('load', () => { + attachTrackIdentity(); + + if (props.trackIdentity) { watchIdentityPaths({ - paths: trackIdentity.paths, + paths: props.trackIdentity.paths, apiHost: props.apiHost, }); - }); - } + } + }); script.onerror = (): void => { // eslint-disable-next-line no-console -- Logging to console is intentional diff --git a/packages/web/src/use-analytics.ts b/packages/web/src/use-analytics.ts index cb979a3..f36255f 100644 --- a/packages/web/src/use-analytics.ts +++ b/packages/web/src/use-analytics.ts @@ -20,6 +20,7 @@ declare global { trackClick: (event: TrackClickInput) => void; trackLead: (event: TrackLeadInput) => void; trackSale: (event: TrackSaleInput) => void; + trackIdentity?: () => Promise; }; } } @@ -83,6 +84,14 @@ export function useAnalytics() { window.dubAnalytics.trackSale(event); }, []); + const trackIdentity = useCallback(async () => { + if (!isDubAnalyticsReady()) { + return; + } + + await window.dubAnalytics.trackIdentity?.(); + }, []); + useEffect(() => { initialize(); }, [initialize]); @@ -92,5 +101,6 @@ export function useAnalytics() { trackClick, trackLead, trackSale, + trackIdentity, }; } From 0a3f9361a181245413cfcea20a2e37a15924fd01 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:22:51 +0530 Subject: [PATCH 09/55] Document trackIdentity paths and method --- packages/web/README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index c2b594f..2924df6 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -88,14 +88,26 @@ The query parameter to listen to for client-side click-tracking (e.g. `?via=john ### `trackIdentity` -Identifies the visitor's device and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. The default is `false`. +Identifies the visitor's device on the given paths and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. -It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The device identification agent is loaded only when this is on, and failures never throw or block the page. +A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. + +It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The device identification agent is loaded only when identification runs, and failures never throw or block the page. ```tsx - + ``` +To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` and `dub_fid` rules. + +```tsx +const { trackIdentity } = useAnalytics(); + +await trackIdentity(); +``` + +Without React, call `window.dubAnalytics.trackIdentity()`. + ### `scriptProps` Custom properties to pass to the script tag. Refer to [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement) for all available options. \ No newline at end of file From d7fe505d1a3843b760aaa49243ee16780f992c9f Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:24:06 +0530 Subject: [PATCH 10/55] Remove generic.test.ts --- packages/web/src/generic.test.ts | 75 -------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 packages/web/src/generic.test.ts diff --git a/packages/web/src/generic.test.ts b/packages/web/src/generic.test.ts deleted file mode 100644 index 80f32ab..0000000 --- a/packages/web/src/generic.test.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { inject } from './generic'; - -const { trackIdentity, watchIdentityPaths } = vi.hoisted(() => ({ - trackIdentity: vi.fn(() => Promise.resolve()), - watchIdentityPaths: vi.fn(), -})); - -vi.mock('./identity', () => ({ - trackIdentity, - watchIdentityPaths, -})); - -function loadScript(): void { - const script = document.head.querySelector('script'); - - window.dubAnalytics = Object.assign(() => undefined, { - trackClick: vi.fn(), - trackLead: vi.fn(), - trackSale: vi.fn(), - }); - script?.dispatchEvent(new Event('load')); -} - -describe('inject', () => { - beforeEach(() => { - document.head.innerHTML = ''; - delete (window as Partial).dubAnalytics; - }); - - afterEach(() => { - vi.clearAllMocks(); - }); - - it('exposes trackIdentity before and after the script replaces window.dubAnalytics', async () => { - inject({ - apiHost: 'https://api.example.com', - }); - - await window.dubAnalytics.trackIdentity?.(); - - loadScript(); - await window.dubAnalytics.trackIdentity?.(); - - expect(trackIdentity).toHaveBeenCalledTimes(2); - expect(trackIdentity).toHaveBeenCalledWith({ - apiHost: 'https://api.example.com', - }); - }); - - it('watches the trackIdentity paths once the script loads', () => { - inject({ - apiHost: 'https://api.example.com', - trackIdentity: { - paths: ['/signup'], - }, - }); - - expect(watchIdentityPaths).not.toHaveBeenCalled(); - - loadScript(); - - expect(watchIdentityPaths).toHaveBeenCalledWith({ - paths: ['/signup'], - apiHost: 'https://api.example.com', - }); - }); - - it('does not watch paths without trackIdentity', () => { - inject({}); - loadScript(); - - expect(watchIdentityPaths).not.toHaveBeenCalled(); - }); -}); From 4bc324c7daac6a6249aa109564fcd041bbf7ec1b Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:28:00 +0530 Subject: [PATCH 11/55] Describe trackIdentity as partner risk monitoring --- packages/web/README.md | 2 +- packages/web/src/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index 2924df6..49410b6 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -88,7 +88,7 @@ The query parameter to listen to for client-side click-tracking (e.g. `?via=john ### `trackIdentity` -Identifies the visitor's device on the given paths and links it to their Dub click, so Dub can flag partners who refer several customers from the same device. +Identifies the visitor's device on the given paths and links it to their Dub click, for partner risk monitoring. A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 0100d6f..8d21a78 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -155,8 +155,8 @@ export interface AnalyticsProps { queryParams?: string[]; /** - * Identify the visitor's device on these paths and link it to their Dub click, to detect - * partners referring several customers from one device. Only runs for visitors with a `dub_id` cookie. + * Identify the visitor's device on these paths and link it to their Dub click, for partner + * risk monitoring. Only runs for visitors with a `dub_id` cookie. * Paths match exactly; a trailing `/*` also matches everything under the path (e.g. `/checkout/*`). */ trackIdentity?: { From 9876e21dd2e68a841057ff075f66e91efc162498 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 16:56:22 +0530 Subject: [PATCH 12/55] Send the sealed result as identityToken --- packages/web/src/identity.test.ts | 4 ++-- packages/web/src/identity.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web/src/identity.test.ts b/packages/web/src/identity.test.ts index f9cc2bb..cafc75e 100644 --- a/packages/web/src/identity.test.ts +++ b/packages/web/src/identity.test.ts @@ -73,7 +73,7 @@ describe('trackIdentity', () => { vi.clearAllMocks(); }); - it('identifies with linkedId set to the clickId and posts only the sealed result', async () => { + it('identifies with linkedId set to the clickId and posts only the identityToken', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; await trackIdentity({ @@ -94,7 +94,7 @@ describe('trackIdentity', () => { 'Content-Type': 'application/json', }, body: JSON.stringify({ - sealedResult: SEALED_RESULT, + identityToken: SEALED_RESULT, }), }, ); diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts index ecd3875..1773aad 100644 --- a/packages/web/src/identity.ts +++ b/packages/web/src/identity.ts @@ -81,7 +81,7 @@ async function identify(apiHost: string): Promise { 'Content-Type': 'application/json', }, body: JSON.stringify({ - sealedResult: sealedResult.base64(), + identityToken: sealedResult.base64(), }), }); From 54f07b3bfbe908c6d79239b48f4a016a485378fd Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:04:46 +0530 Subject: [PATCH 13/55] Add identity tracking to the analytics script --- .github/workflows/deploy-script.yml | 2 + packages/script/build.js | 14 +- packages/script/package.json | 11 +- packages/script/src/base.identity.test.js | 365 ++++++++++++++++++++++ packages/script/src/base.js | 146 ++++++++- packages/script/src/identity.js | 44 +++ packages/script/src/identity.test.js | 100 ++++++ packages/script/vitest.config.js | 10 + pnpm-lock.yaml | 9 + 9 files changed, 695 insertions(+), 6 deletions(-) create mode 100644 packages/script/src/base.identity.test.js create mode 100644 packages/script/src/identity.js create mode 100644 packages/script/src/identity.test.js create mode 100644 packages/script/vitest.config.js diff --git a/.github/workflows/deploy-script.yml b/.github/workflows/deploy-script.yml index 44b35aa..37399a4 100644 --- a/.github/workflows/deploy-script.yml +++ b/.github/workflows/deploy-script.yml @@ -17,6 +17,8 @@ jobs: - name: Install Dependencies and Build run: pnpm --filter @dub/analytics-script build + env: + DUB_FINGERPRINT_PUBLIC_KEY: ${{ vars.DUB_FINGERPRINT_PUBLIC_KEY }} - name: Deploy to Cloudflare Pages id: cloudflare-deploy diff --git a/packages/script/build.js b/packages/script/build.js index 9232a35..0eb2c5a 100644 --- a/packages/script/build.js +++ b/packages/script/build.js @@ -24,7 +24,7 @@ fs.copyFileSync( path.join(__dirname, 'dist/_redirects'), ); -// Build all variants (8 total combinations of 3 extensions) +// Build all variants (8 total combinations of 3 extensions), plus identity.js Promise.all([ // 1. Base script (no extensions) esbuild.build({ @@ -137,4 +137,16 @@ Promise.all([ outfile: 'dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js', }), + + // 9. Identity, loaded on demand by every variant + esbuild.build({ + ...baseConfig, + entryPoints: ['src/identity.js'], + define: { + 'process.env.DUB_FINGERPRINT_PUBLIC_KEY': JSON.stringify( + process.env.DUB_FINGERPRINT_PUBLIC_KEY ?? '', + ), + }, + outfile: 'dist/analytics/identity.js', + }), ]).catch(() => process.exit(1)); diff --git a/packages/script/package.json b/packages/script/package.json index f42ed14..16bfc6f 100644 --- a/packages/script/package.json +++ b/packages/script/package.json @@ -10,14 +10,19 @@ "dist/analytics/script.site-visit.outbound-domains.js", "dist/analytics/script.site-visit.conversion-tracking.js", "dist/analytics/script.outbound-domains.conversion-tracking.js", - "dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js" + "dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js", + "dist/analytics/identity.js" ], "scripts": { "prebuild": "mkdir -p dist/analytics", - "build": "node build.js" + "build": "node build.js", + "test": "vitest run" }, "devDependencies": { + "@fingerprint/agent": "^4.1.6", "esbuild": "^0.19.0", - "terser": "^5.39.0" + "jsdom": "^24.0.0", + "terser": "^5.39.0", + "vitest": "^1.6.0" } } \ No newline at end of file diff --git a/packages/script/src/base.identity.test.js b/packages/script/src/base.identity.test.js new file mode 100644 index 0000000..d847c44 --- /dev/null +++ b/packages/script/src/base.identity.test.js @@ -0,0 +1,365 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +const BASE_SOURCE = readFileSync(join(__dirname, 'base.js'), 'utf8'); +const SCRIPT_SRC = 'https://www.dubcdn.com/analytics/script.js'; +const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; + +const { pushState, replaceState } = window.history; +const addEventListener = window.addEventListener.bind(window); +const popstateListeners = []; +const fetchMock = vi.fn(); +const identify = vi.fn(); + +function runBase(attributes = {}) { + const script = document.createElement('script'); + script.src = SCRIPT_SRC; + + Object.entries(attributes).forEach(([name, value]) => { + script.setAttribute(name, value); + }); + + Object.defineProperty(document, 'currentScript', { + configurable: true, + get: () => script, + }); + + new Function(BASE_SOURCE)(); +} + +function stubDubAnalytics() { + window.dubAnalytics = function () { + (window.dubAnalytics.q = window.dubAnalytics.q || []).push(arguments); + }; +} + +function loadedIdentityScripts() { + return [...document.head.querySelectorAll('script')].map( + (script) => script.src, + ); +} + +function clearCookies() { + document.cookie.split(';').forEach((cookie) => { + const [name] = cookie.trim().split('='); + document.cookie = `${name}=; path=/; max-age=0`; + }); +} + +function getCookie(name) { + return document.cookie + .split(';') + .map((cookie) => cookie.trim().split('=')) + .find(([key]) => key === name)?.[1]; +} + +function flush() { + return new Promise((resolve) => { + setTimeout(resolve, 0); + }); +} + +describe('base.js identity', () => { + beforeEach(() => { + clearCookies(); + document.head.innerHTML = ''; + stubDubAnalytics(); + vi.stubGlobal('fetch', fetchMock); + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + vi.spyOn(window, 'addEventListener').mockImplementation( + (type, listener, options) => { + if (type === 'popstate') { + popstateListeners.push(listener); + } + + addEventListener(type, listener, options); + }, + ); + + identify.mockResolvedValue(true); + + vi.spyOn(document.head, 'appendChild').mockImplementation((node) => { + document.head.append(node); + + if (node.src.endsWith('/identity.js')) { + window._dubIdentity = { + identify, + }; + setTimeout(() => node.onload()); + } + + return node; + }); + }); + + afterEach(() => { + popstateListeners.splice(0).forEach((listener) => { + window.removeEventListener('popstate', listener); + }); + window.history.pushState = pushState; + window.history.replaceState = replaceState; + replaceState.call(window.history, null, '', '/'); + delete window._dubIdentity; + vi.unstubAllGlobals(); + vi.restoreAllMocks(); + vi.clearAllMocks(); + }); + + it('loads identity.js next to the script and identifies the click on a matching path', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-api-host': 'https://api.example.com', + 'data-identity-paths': JSON.stringify(['/signup']), + }); + + await vi.waitFor(() => { + expect(getCookie('dub_fid')).toBe(CLICK_ID); + }); + + expect(loadedIdentityScripts()).toEqual([ + 'https://www.dubcdn.com/analytics/identity.js', + ]); + expect(identify).toHaveBeenCalledWith({ + apiHost: 'https://api.example.com', + clickId: CLICK_ID, + }); + }); + + it.each([ + ['/signup/', ['/signup']], + ['/checkout', ['/checkout/*']], + ['/checkout/plan/pro', ['/checkout/*']], + ['/anything', ['/*']], + ])('identifies on %s for paths %j', async (pathname, paths) => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', pathname); + + runBase({ + 'data-identity-paths': JSON.stringify(paths), + }); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + }); + + it.each([ + ['/', ['/signup']], + ['/signup/step-2', ['/signup']], + ['/signup-old', ['/signup']], + ['/checkouts', ['/checkout/*']], + ])('skips %s for paths %j', async (pathname, paths) => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', pathname); + + runBase({ + 'data-identity-paths': JSON.stringify(paths), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + }); + + it('does nothing without data-identity-paths', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase(); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + }); + + it('skips loading identity.js without a dub_id cookie', async () => { + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + }); + + it('skips when dub_fid already matches the click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = `dub_fid=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + }); + + it('identifies again when dub_fid belongs to another click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = 'dub_fid=otherClickId; path=/'; + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + + await vi.waitFor(() => { + expect(getCookie('dub_fid')).toBe(CLICK_ID); + }); + }); + + it('waits for a ?via= click before identifying', async () => { + let resolveClick; + fetchMock.mockReturnValue( + new Promise((resolve) => { + resolveClick = resolve; + }), + ); + replaceState.call(window.history, null, '', '/signup?via=partner'); + + runBase({ + 'data-domains': JSON.stringify({ + refer: 'dub.sh', + }), + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + + resolveClick( + new Response( + JSON.stringify({ + clickId: CLICK_ID, + }), + ), + ); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledWith( + expect.objectContaining({ + clickId: CLICK_ID, + }), + ); + }); + }); + + it('does not set dub_fid when identification fails', async () => { + identify.mockResolvedValue(false); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + await flush(); + + expect(getCookie('dub_fid')).toBeUndefined(); + }); + + it('never throws when identity.js fails to load', async () => { + document.head.appendChild.mockImplementation((node) => { + document.head.append(node); + setTimeout(() => node.onerror()); + return node; + }); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase(); + + await expect(window.dubAnalytics.trackIdentity()).resolves.toBeUndefined(); + expect(getCookie('dub_fid')).toBeUndefined(); + }); + + it('identifies after a client-side navigation to a matching path', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + + window.history.pushState(null, '', '/signup'); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + }); + + it('identifies when going back to a matching path', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + replaceState.call(window.history, null, '', '/signup'); + window.dispatchEvent(new PopStateEvent('popstate')); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + }); + + it('ignores history updates that keep the same path', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runBase({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + + clearCookies(); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + window.history.replaceState(null, '', '/signup?step=2'); + await flush(); + + expect(identify).toHaveBeenCalledTimes(1); + }); + + it('exposes trackIdentity on window.dubAnalytics without paths', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase(); + await window.dubAnalytics.trackIdentity(); + + expect(identify).toHaveBeenCalledTimes(1); + expect(getCookie('dub_fid')).toBe(CLICK_ID); + }); + + it('runs a trackIdentity call queued before the script loaded', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + window.dubAnalytics('trackIdentity'); + + runBase(); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + }); + + it('shares one identification between concurrent calls', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runBase(); + await Promise.all([ + window.dubAnalytics.trackIdentity(), + window.dubAnalytics.trackIdentity(), + ]); + + expect(identify).toHaveBeenCalledTimes(1); + expect(loadedIdentityScripts()).toHaveLength(1); + }); +}); diff --git a/packages/script/src/base.js b/packages/script/src/base.js index 138fa36..17c9cc4 100644 --- a/packages/script/src/base.js +++ b/packages/script/src/base.js @@ -4,6 +4,8 @@ const DUB_ID_VAR = 'dub_id'; const DUB_PARTNER_COOKIE = 'dub_partner_data'; + const DUB_FID_VAR = 'dub_fid'; + const DUB_FID_MAX_AGE_SECONDS = 30 * 60; const COOKIE_EXPIRES = 90 * 24 * 60 * 60 * 1000; // 90 days const HOSTNAME = window.location.hostname; @@ -89,6 +91,22 @@ return [...new Set(resolvedQueryParams)]; })(); + const IDENTITY_PATHS = (() => { + const identityPaths = script.getAttribute('data-identity-paths'); + + if (!identityPaths) return []; + + try { + return JSON.parse(identityPaths); + } catch (error) { + console.warn( + '[dubAnalytics] Failed to parse data-identity-paths.', + error, + ); + return []; + } + })(); + const QUERY_PARAM_VALUE = (() => { const params = new URLSearchParams(location.search); @@ -118,6 +136,8 @@ dubAnalytics.ready(...args); } else if (method === 'trackClick') { dubAnalytics.trackClick(...args); + } else if (method === 'trackIdentity') { + return dubAnalytics.trackIdentity(); } else { console.warn('[dubAnalytics] Unknown method:', method); } @@ -134,6 +154,10 @@ trackClick(...args); }; + dubAnalytics.trackIdentity = function () { + return trackIdentity(); + }; + // Replace window.dubAnalytics with the callable + augmented function window.dubAnalytics = dubAnalytics; } @@ -184,6 +208,8 @@ callback(); } else if (['trackClick'].includes(method)) { trackClick(...args); + } else if (method === 'trackIdentity') { + trackIdentity(); } else { console.warn('[dubAnalytics] Unknown method:', method); } @@ -191,6 +217,9 @@ }; let clientClickTracked = false; + let pendingClick = Promise.resolve(); + let pendingIdentity; + let identityScript; // Track click and set cookie function trackClick({ domain, key }) { @@ -200,7 +229,7 @@ clientClickTracked = true; - fetch(`${API_HOST}/track/click`, { + pendingClick = fetch(`${API_HOST}/track/click`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -241,6 +270,115 @@ }); } + function matchesIdentityPath(pathname) { + const normalize = (path) => + path.length > 1 ? path.replace(/\/+$/, '') : path; + const current = normalize(pathname); + + return IDENTITY_PATHS.some((path) => { + if (path.endsWith('/*')) { + const base = normalize(path.slice(0, -2)); + + return ( + base === '' || current === base || current.startsWith(`${base}/`) + ); + } + + return current === normalize(path); + }); + } + + // The Fingerprint agent lives in identity.js, next to this script, so it only loads when needed + function loadIdentityScript() { + identityScript = + identityScript || + new Promise((resolve, reject) => { + const identity = document.createElement('script'); + identity.src = new URL('identity.js', script.src).href; + identity.async = true; + identity.onload = () => resolve(window._dubIdentity); + identity.onerror = () => { + identityScript = undefined; + reject(new Error('Failed to load identity.js')); + }; + document.head.appendChild(identity); + }); + + return identityScript; + } + + // Links the visitor's device to their click, at most once per click every 30 minutes + function trackIdentity() { + pendingIdentity = + pendingIdentity || + pendingClick + .catch(() => undefined) + .then(() => { + const clickId = cookieManager.get(DUB_ID_VAR); + + if (!clickId || cookieManager.get(DUB_FID_VAR) === clickId) { + return; + } + + return loadIdentityScript() + .then((identity) => + identity.identify({ + apiHost: API_HOST, + clickId, + }), + ) + .then((identified) => { + if (identified) { + document.cookie = `${DUB_FID_VAR}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; + } + }); + }) + .catch((error) => { + console.warn('[dubAnalytics] trackIdentity failed.', error); + }) + .then(() => { + pendingIdentity = undefined; + }); + + return pendingIdentity; + } + + // Identifies on the first page load and on client-side navigation to a matching path + function watchIdentityPaths() { + if (!IDENTITY_PATHS.length) return; + + let lastPathname; + + const check = () => { + const { pathname } = window.location; + + if (pathname === lastPathname) return; + + lastPathname = pathname; + + if (matchesIdentityPath(pathname)) { + trackIdentity(); + } + }; + + const pushState = history.pushState.bind(history); + const replaceState = history.replaceState.bind(history); + + history.pushState = (...args) => { + pushState(...args); + check(); + }; + + history.replaceState = (...args) => { + replaceState(...args); + check(); + }; + + window.addEventListener('popstate', check); + + check(); + } + // Initialize tracking function init() { const params = new URLSearchParams(location.search); @@ -268,7 +406,11 @@ } // Process the queued methods - queueManager.flush((method) => method === 'trackClick'); + queueManager.flush( + (method) => method === 'trackClick' || method === 'trackIdentity', + ); + + watchIdentityPaths(); // Initialize DubAnalytics from cookie if it exists const partnerCookie = cookieManager.get(DUB_PARTNER_COOKIE); diff --git a/packages/script/src/identity.js b/packages/script/src/identity.js new file mode 100644 index 0000000..6567e8c --- /dev/null +++ b/packages/script/src/identity.js @@ -0,0 +1,44 @@ +import { start } from '@fingerprint/agent'; + +const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; + +// Loaded on demand by base.js; resolves true once Dub has linked the device to the click +async function identify({ apiHost, clickId }) { + if (!FINGERPRINT_PUBLIC_KEY) { + return false; + } + + // The server reads the click from linkedId + const { sealed_result: sealedResult } = await start({ + apiKey: FINGERPRINT_PUBLIC_KEY, + }).get({ + linkedId: clickId, + }); + + if (!sealedResult) { + return false; + } + + const response = await fetch(`${apiHost}/track/identity`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + identityToken: sealedResult.base64(), + }), + }); + + if (!response.ok) { + console.warn( + `[dubAnalytics] trackIdentity failed with status ${response.status}.`, + ); + return false; + } + + return true; +} + +window._dubIdentity = { + identify, +}; diff --git a/packages/script/src/identity.test.js b/packages/script/src/identity.test.js new file mode 100644 index 0000000..52ca749 --- /dev/null +++ b/packages/script/src/identity.test.js @@ -0,0 +1,100 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import './identity'; + +const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; +const SEALED_RESULT = 'noXc7Q=='; + +const { get, start } = vi.hoisted(() => { + const getMock = vi.fn(); + + return { + get: getMock, + start: vi.fn(() => ({ + get: getMock, + })), + }; +}); + +vi.mock('@fingerprint/agent', () => ({ + start, +})); + +const fetchMock = vi.fn(); + +function identify() { + return window._dubIdentity.identify({ + apiHost: 'https://api.example.com', + clickId: CLICK_ID, + }); +} + +describe('identity.js', () => { + beforeEach(() => { + vi.stubGlobal('fetch', fetchMock); + vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + get.mockResolvedValue({ + event_id: 'evt_1', + sealed_result: { + base64: () => SEALED_RESULT, + }, + }); + + fetchMock.mockResolvedValue( + new Response( + JSON.stringify({ + clickIdentificationId: 'cid_1', + }), + ), + ); + }); + + afterEach(() => { + vi.unstubAllGlobals(); + vi.clearAllMocks(); + }); + + it('identifies with linkedId set to the clickId and posts only the identityToken', async () => { + await expect(identify()).resolves.toBe(true); + + expect(start).toHaveBeenCalledWith({ + apiKey: 'test_public_key', + }); + expect(get).toHaveBeenCalledWith({ + linkedId: CLICK_ID, + }); + expect(fetchMock).toHaveBeenCalledWith( + 'https://api.example.com/track/identity', + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + identityToken: SEALED_RESULT, + }), + }, + ); + }); + + it('skips the request when sealed results are off', async () => { + get.mockResolvedValue({ + event_id: 'evt_1', + sealed_result: null, + }); + + await expect(identify()).resolves.toBe(false); + + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('resolves false when the request is rejected', async () => { + fetchMock.mockResolvedValue( + new Response('Bad Request', { + status: 400, + }), + ); + + await expect(identify()).resolves.toBe(false); + }); +}); diff --git a/packages/script/vitest.config.js b/packages/script/vitest.config.js new file mode 100644 index 0000000..2af4067 --- /dev/null +++ b/packages/script/vitest.config.js @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + environment: 'jsdom', + env: { + DUB_FINGERPRINT_PUBLIC_KEY: 'test_public_key', + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ef19907..9e26ff6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,12 +162,21 @@ importers: packages/script: devDependencies: + '@fingerprint/agent': + specifier: ^4.1.6 + version: 4.1.6 esbuild: specifier: ^0.19.0 version: 0.19.12 + jsdom: + specifier: ^24.0.0 + version: 24.1.3 terser: specifier: ^5.39.0 version: 5.39.0 + vitest: + specifier: ^1.6.0 + version: 1.6.1(@types/node@20.11.16)(jsdom@24.1.3)(terser@5.39.0) packages/web: dependencies: From 3bdbcadd971f9f7614d7f38feb5c596a4802ac95 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:04:56 +0530 Subject: [PATCH 14/55] Pass trackIdentity paths to the script instead of identifying in the package --- .github/workflows/release.yml | 2 - packages/web/package.json | 8 +- packages/web/src/generic.ts | 41 ++-- packages/web/src/identity.test.ts | 332 ------------------------------ packages/web/src/identity.ts | 163 --------------- packages/web/src/use-analytics.ts | 4 +- packages/web/tsup.config.js | 3 - packages/web/vitest.config.js | 10 - pnpm-lock.yaml | 9 - 9 files changed, 18 insertions(+), 554 deletions(-) delete mode 100644 packages/web/src/identity.test.ts delete mode 100644 packages/web/src/identity.ts delete mode 100644 packages/web/vitest.config.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9369b0..394ef3f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,8 +23,6 @@ jobs: - name: build run: pnpm --filter @dub/analytics build - env: - DUB_FINGERPRINT_PUBLIC_KEY: ${{ vars.DUB_FINGERPRINT_PUBLIC_KEY }} - run: pnpm --filter @dub/analytics publish --tag beta --no-git-checks if: github.event.release.prerelease == true diff --git a/packages/web/package.json b/packages/web/package.json index 3f73977..0ce7554 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -42,7 +42,6 @@ "dev": "tsup --watch", "lint": "eslint .", "lint-fix": "eslint . --fix", - "test": "vitest run", "type-check": "tsc --noEmit" }, "eslintConfig": { @@ -54,7 +53,6 @@ } }, "dependencies": { - "@fingerprint/agent": "^4.1.6", "server-only": "^0.0.1" }, "devDependencies": { @@ -62,10 +60,8 @@ "@swc/core": "^1.3.66", "@types/node": "^20.3.1", "@types/react": "^18.2.14", - "jsdom": "^24.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "tsup": "7.1.0", - "vitest": "^1.6.0" + "tsup": "7.1.0" } -} +} \ No newline at end of file diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index 6c7d993..904baf9 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -1,5 +1,4 @@ import { name, version } from '../package.json'; -import { trackIdentity, watchIdentityPaths } from './identity'; import type { AnalyticsProps } from './types'; import { isBrowser } from './utils'; @@ -20,11 +19,13 @@ function inject(props: AnalyticsProps): void { (w[da].q = w[da].q || []).push(arguments); }; - ['trackClick', 'trackLead', 'trackSale'].forEach(function (m) { - w[da][m] = function () { - (w[da].q = w[da].q || []).push([m, ...Array.from(arguments)]); - }; - }); + ['trackClick', 'trackLead', 'trackSale', 'trackIdentity'].forEach( + function (m) { + w[da][m] = function () { + (w[da].q = w[da].q || []).push([m, ...Array.from(arguments)]); + }; + }, + ); })(window as DubAnalyticsWindow, 'dubAnalytics'); // Determine script source based on enabled features @@ -84,32 +85,18 @@ function inject(props: AnalyticsProps): void { script.setAttribute('data-query-params', JSON.stringify(props.queryParams)); } + if (props.trackIdentity) { + script.setAttribute( + 'data-identity-paths', + JSON.stringify(props.trackIdentity.paths), + ); + } + if (props.scriptProps) { const { src: _, ...restProps } = props.scriptProps; // we already set the src above Object.assign(script, restProps); } - const attachTrackIdentity = (): void => { - (window as DubAnalyticsWindow).dubAnalytics.trackIdentity = () => - trackIdentity({ - apiHost: props.apiHost, - }); - }; - - attachTrackIdentity(); - - // The script replaces window.dubAnalytics when it loads - script.addEventListener('load', () => { - attachTrackIdentity(); - - if (props.trackIdentity) { - watchIdentityPaths({ - paths: props.trackIdentity.paths, - apiHost: props.apiHost, - }); - } - }); - script.onerror = (): void => { // eslint-disable-next-line no-console -- Logging to console is intentional console.log(`[Dub Web Analytics] failed to load script from ${src}.`); diff --git a/packages/web/src/identity.test.ts b/packages/web/src/identity.test.ts deleted file mode 100644 index cafc75e..0000000 --- a/packages/web/src/identity.test.ts +++ /dev/null @@ -1,332 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { trackIdentity, watchIdentityPaths } from './identity'; - -const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; -const SEALED_RESULT = 'noXc7Q=='; - -const { get, start } = vi.hoisted(() => { - const getMock = vi.fn(); - - return { - get: getMock, - start: vi.fn(() => ({ - get: getMock, - })), - }; -}); - -vi.mock('@fingerprint/agent', () => ({ - start, -})); - -const fetchMock = vi.fn(); -const { pushState, replaceState } = window.history; - -function clearCookies(): void { - document.cookie.split(';').forEach((cookie) => { - const [name] = cookie.trim().split('='); - document.cookie = `${name}=; path=/; max-age=0`; - }); -} - -function flush(): Promise { - return new Promise((resolve) => { - setTimeout(resolve, 0); - }); -} - -function getCookie(name: string): string | undefined { - return document.cookie - .split(';') - .map((cookie) => cookie.trim().split('=')) - .find(([key]) => key === name)?.[1]; -} - -describe('trackIdentity', () => { - beforeEach(() => { - clearCookies(); - vi.stubGlobal('fetch', fetchMock); - vi.spyOn(console, 'warn').mockImplementation(() => undefined); - - get.mockResolvedValue({ - event_id: 'evt_1', - sealed_result: { - base64: () => SEALED_RESULT, - }, - }); - - fetchMock.mockResolvedValue( - new Response( - JSON.stringify({ - clickIdentificationId: 'cid_1', - }), - ), - ); - }); - - afterEach(() => { - window.history.pushState = pushState; - window.history.replaceState = replaceState; - window.history.replaceState(null, '', '/'); - vi.useRealTimers(); - vi.unstubAllGlobals(); - vi.clearAllMocks(); - }); - - it('identifies with linkedId set to the clickId and posts only the identityToken', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - - await trackIdentity({ - apiHost: 'https://api.example.com', - }); - - expect(start).toHaveBeenCalledWith({ - apiKey: 'test_public_key', - }); - expect(get).toHaveBeenCalledWith({ - linkedId: CLICK_ID, - }); - expect(fetchMock).toHaveBeenCalledWith( - 'https://api.example.com/track/identity', - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - identityToken: SEALED_RESULT, - }), - }, - ); - expect(getCookie('dub_fid')).toBe(CLICK_ID); - }); - - it('defaults to the Dub API host', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - - await trackIdentity({}); - - expect(fetchMock).toHaveBeenCalledWith( - 'https://api.dub.co/track/identity', - expect.anything(), - ); - }); - - it('skips when dub_fid already matches the click', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - document.cookie = `dub_fid=${CLICK_ID}; path=/`; - - await trackIdentity({}); - - expect(start).not.toHaveBeenCalled(); - expect(fetchMock).not.toHaveBeenCalled(); - }); - - it('identifies again when dub_fid belongs to another click', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - document.cookie = 'dub_fid=otherClickId; path=/'; - - await trackIdentity({}); - - expect(fetchMock).toHaveBeenCalledTimes(1); - expect(getCookie('dub_fid')).toBe(CLICK_ID); - }); - - it('waits for dub_id set after a client-side click', async () => { - vi.useFakeTimers(); - - const promise = trackIdentity({}); - document.cookie = `dub_id=${CLICK_ID}; path=/`; - await vi.advanceTimersByTimeAsync(1000); - await promise; - - expect(get).toHaveBeenCalledWith({ - linkedId: CLICK_ID, - }); - }); - - it('skips when there is no dub_id cookie', async () => { - vi.useFakeTimers(); - - const promise = trackIdentity({}); - await vi.advanceTimersByTimeAsync(5000); - await promise; - - expect(start).not.toHaveBeenCalled(); - expect(fetchMock).not.toHaveBeenCalled(); - }); - - it('skips the request when sealed results are off', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - get.mockResolvedValue({ - event_id: 'evt_1', - sealed_result: null, - }); - - await trackIdentity({}); - - expect(fetchMock).not.toHaveBeenCalled(); - expect(getCookie('dub_fid')).toBeUndefined(); - }); - - it('does not set dub_fid when the request is rejected', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - fetchMock.mockResolvedValue( - new Response('Bad Request', { - status: 400, - }), - ); - - await trackIdentity({}); - - expect(getCookie('dub_fid')).toBeUndefined(); - }); - - it('never throws when Fingerprint fails', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - get.mockRejectedValue(new Error('Network error')); - - await expect(trackIdentity({})).resolves.toBeUndefined(); - - expect(fetchMock).not.toHaveBeenCalled(); - expect(getCookie('dub_fid')).toBeUndefined(); - }); - - it('never throws when the request fails', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - fetchMock.mockRejectedValue(new TypeError('Failed to fetch')); - - await expect(trackIdentity({})).resolves.toBeUndefined(); - - expect(getCookie('dub_fid')).toBeUndefined(); - }); - - it('shares one identification between concurrent calls', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - - await Promise.all([trackIdentity({}), trackIdentity({})]); - - expect(get).toHaveBeenCalledTimes(1); - expect(fetchMock).toHaveBeenCalledTimes(1); - }); -}); - -describe('watchIdentityPaths', () => { - beforeEach(() => { - clearCookies(); - document.cookie = `dub_id=${CLICK_ID}; path=/`; - vi.stubGlobal('fetch', fetchMock); - vi.spyOn(console, 'warn').mockImplementation(() => undefined); - - get.mockResolvedValue({ - event_id: 'evt_1', - sealed_result: { - base64: () => SEALED_RESULT, - }, - }); - - fetchMock.mockResolvedValue(new Response('{}')); - }); - - afterEach(() => { - window.history.pushState = pushState; - window.history.replaceState = replaceState; - window.history.replaceState(null, '', '/'); - vi.unstubAllGlobals(); - vi.clearAllMocks(); - }); - - it.each([ - ['/signup', ['/signup']], - ['/signup/', ['/signup']], - ['/checkout', ['/checkout/*']], - ['/checkout/plan/pro', ['/checkout/*']], - ['/anything', ['/*']], - ])('identifies on %s for paths %j', async (pathname, paths) => { - window.history.replaceState(null, '', pathname); - - watchIdentityPaths({ - paths, - }); - - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledTimes(1); - }); - }); - - it.each([ - ['/', ['/signup']], - ['/signup/step-2', ['/signup']], - ['/signup-old', ['/signup']], - ['/checkouts', ['/checkout/*']], - ])('skips %s for paths %j', async (pathname, paths) => { - window.history.replaceState(null, '', pathname); - - watchIdentityPaths({ - paths, - }); - await flush(); - - expect(start).not.toHaveBeenCalled(); - }); - - it('identifies after a client-side navigation to a matching path', async () => { - watchIdentityPaths({ - paths: ['/signup'], - apiHost: 'https://api.example.com', - }); - await flush(); - - expect(start).not.toHaveBeenCalled(); - - window.history.pushState(null, '', '/signup'); - - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledWith( - 'https://api.example.com/track/identity', - expect.anything(), - ); - }); - }); - - it('identifies when going back to a matching path', async () => { - window.history.replaceState(null, '', '/signup'); - watchIdentityPaths({ - paths: ['/signup'], - }); - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledTimes(1); - }); - - clearCookies(); - document.cookie = `dub_id=${CLICK_ID}; path=/`; - window.history.pushState(null, '', '/pricing'); - await flush(); - replaceState.call(window.history, null, '', '/signup'); - - expect(start).toHaveBeenCalledTimes(1); - - window.dispatchEvent(new PopStateEvent('popstate')); - - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledTimes(2); - }); - }); - - it('ignores history updates that keep the same path', async () => { - window.history.replaceState(null, '', '/signup'); - watchIdentityPaths({ - paths: ['/signup'], - }); - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledTimes(1); - }); - - clearCookies(); - document.cookie = `dub_id=${CLICK_ID}; path=/`; - window.history.replaceState(null, '', '/signup?step=2'); - await flush(); - - expect(start).toHaveBeenCalledTimes(1); - }); -}); diff --git a/packages/web/src/identity.ts b/packages/web/src/identity.ts deleted file mode 100644 index 1773aad..0000000 --- a/packages/web/src/identity.ts +++ /dev/null @@ -1,163 +0,0 @@ -const DEFAULT_API_HOST = 'https://api.dub.co'; -const DUB_ID_COOKIE = 'dub_id'; -const DUB_FID_COOKIE = 'dub_fid'; -const DUB_FID_MAX_AGE_SECONDS = 30 * 60; -const CLICK_ID_POLL_ATTEMPTS = 5; -const CLICK_ID_POLL_INTERVAL_MS = 1000; -const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; - -let pendingIdentity: Promise | undefined; - -function getCookie(name: string): string | undefined { - return document.cookie - .split(';') - .map((cookie) => cookie.trim().split('=')) - .find(([key]) => key === name)?.[1]; -} - -// The script sets dub_id asynchronously for ?via= clicks, so give it a few seconds -async function waitForClickId( - attemptsLeft = CLICK_ID_POLL_ATTEMPTS, -): Promise { - const clickId = getCookie(DUB_ID_COOKIE); - - if (clickId || attemptsLeft <= 1) { - return clickId; - } - - await new Promise((resolve) => { - setTimeout(resolve, CLICK_ID_POLL_INTERVAL_MS); - }); - - return waitForClickId(attemptsLeft - 1); -} - -function normalizePath(path: string): string { - return path.length > 1 ? path.replace(/\/+$/, '') : path; -} - -function matchesIdentityPath(pathname: string, paths: string[]): boolean { - const current = normalizePath(pathname); - - return paths.some((path) => { - if (path.endsWith('/*')) { - const base = normalizePath(path.slice(0, -2)); - - return base === '' || current === base || current.startsWith(`${base}/`); - } - - return current === normalizePath(path); - }); -} - -async function identify(apiHost: string): Promise { - try { - if (!FINGERPRINT_PUBLIC_KEY) { - return; - } - - const clickId = await waitForClickId(); - - if (!clickId || getCookie(DUB_FID_COOKIE) === clickId) { - return; - } - - const { start } = await import('@fingerprint/agent'); - - // The server reads the click from linkedId - const { sealed_result: sealedResult } = await start({ - apiKey: FINGERPRINT_PUBLIC_KEY, - }).get({ - linkedId: clickId, - }); - - if (!sealedResult) { - return; - } - - const response = await fetch(`${apiHost}/track/identity`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - identityToken: sealedResult.base64(), - }), - }); - - if (!response.ok) { - // eslint-disable-next-line no-console -- Logging to console is intentional - console.warn( - `[Dub Web Analytics] identity tracking failed with status ${response.status}.`, - ); - return; - } - - document.cookie = `${DUB_FID_COOKIE}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; - } catch (error) { - // eslint-disable-next-line no-console -- Logging to console is intentional - console.warn('[Dub Web Analytics] identity tracking failed.', error); - } -} - -/** - * Identifies the visitor's device and links it to their Dub click. - * Runs only for visitors with a `dub_id` cookie, at most once per click every 30 minutes. - */ -export function trackIdentity({ - apiHost = DEFAULT_API_HOST, -}: { - apiHost?: string; -}): Promise { - pendingIdentity ??= identify(apiHost).finally(() => { - pendingIdentity = undefined; - }); - - return pendingIdentity; -} - -/** - * Runs trackIdentity on the current page and on every client-side navigation to one of the paths. - */ -export function watchIdentityPaths({ - paths, - apiHost, -}: { - paths: string[]; - apiHost?: string; -}): void { - let lastPathname: string | undefined; - - const check = (): void => { - const { pathname } = window.location; - - if (pathname === lastPathname) { - return; - } - - lastPathname = pathname; - - if (matchesIdentityPath(pathname, paths)) { - void trackIdentity({ - apiHost, - }); - } - }; - - const pushState = window.history.pushState.bind(window.history); - const replaceState = window.history.replaceState.bind(window.history); - - window.history.pushState = (...args) => { - pushState(...args); - check(); - }; - - window.history.replaceState = (...args) => { - replaceState(...args); - check(); - }; - - window.addEventListener('popstate', check); - - check(); -} diff --git a/packages/web/src/use-analytics.ts b/packages/web/src/use-analytics.ts index f36255f..fed0ecf 100644 --- a/packages/web/src/use-analytics.ts +++ b/packages/web/src/use-analytics.ts @@ -20,7 +20,7 @@ declare global { trackClick: (event: TrackClickInput) => void; trackLead: (event: TrackLeadInput) => void; trackSale: (event: TrackSaleInput) => void; - trackIdentity?: () => Promise; + trackIdentity: () => Promise | void; }; } } @@ -89,7 +89,7 @@ export function useAnalytics() { return; } - await window.dubAnalytics.trackIdentity?.(); + await window.dubAnalytics.trackIdentity(); }, []); useEffect(() => { diff --git a/packages/web/tsup.config.js b/packages/web/tsup.config.js index d4b13c1..db20c66 100644 --- a/packages/web/tsup.config.js +++ b/packages/web/tsup.config.js @@ -7,9 +7,6 @@ const cfg = { treeshake: false, dts: true, format: ['esm', 'cjs'], - env: { - DUB_FINGERPRINT_PUBLIC_KEY: process.env.DUB_FINGERPRINT_PUBLIC_KEY ?? '', - }, }; export default defineConfig([ diff --git a/packages/web/vitest.config.js b/packages/web/vitest.config.js deleted file mode 100644 index 2af4067..0000000 --- a/packages/web/vitest.config.js +++ /dev/null @@ -1,10 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -export default defineConfig({ - test: { - environment: 'jsdom', - env: { - DUB_FINGERPRINT_PUBLIC_KEY: 'test_public_key', - }, - }, -}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e26ff6..d188857 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -180,9 +180,6 @@ importers: packages/web: dependencies: - '@fingerprint/agent': - specifier: ^4.1.6 - version: 4.1.6 server-only: specifier: ^0.0.1 version: 0.0.1 @@ -199,9 +196,6 @@ importers: '@types/react': specifier: ^18.2.14 version: 18.2.51 - jsdom: - specifier: ^24.0.0 - version: 24.1.3 react: specifier: ^18.2.0 version: 18.2.0 @@ -211,9 +205,6 @@ importers: tsup: specifier: 7.1.0 version: 7.1.0(@swc/core@1.3.107(@swc/helpers@0.5.5))(postcss@8.5.32)(typescript@5.3.3) - vitest: - specifier: ^1.6.0 - version: 1.6.1(@types/node@20.11.16)(jsdom@24.1.3)(terser@5.39.0) packages: '@aashutoshrathi/word-wrap@1.2.6': From 3c42262d6fb371be7cb92b038f8a174b92b4ac58 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:04:57 +0530 Subject: [PATCH 15/55] Document trackIdentity for script-tag installs --- packages/web/README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/web/README.md b/packages/web/README.md index 49410b6..e640929 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -106,7 +106,17 @@ const { trackIdentity } = useAnalytics(); await trackIdentity(); ``` -Without React, call `window.dubAnalytics.trackIdentity()`. +Every script variant supports this, so installs without React work too. Set the paths with a `data-identity-paths` attribute, and call `dubAnalytics.trackIdentity()`. To queue calls made before the script loads, add `trackIdentity` to the snippet's method list. + +```html + +``` + +The device identification agent loads from `identity.js` next to the script. If you serve the script from your own domain or a proxy, serve `identity.js` from the same folder. ### `scriptProps` From 334c79008ab2835ed7862959cc3daba60fafdd29 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:29:27 +0530 Subject: [PATCH 16/55] Ship identity tracking as an identity script variant --- packages/script/build.js | 149 ++++----------- packages/script/package.json | 12 +- packages/script/src/base.js | 145 +-------------- packages/script/src/extensions/identity.js | 173 ++++++++++++++++++ .../identity.test.js} | 72 +++++--- .../src/{identity.js => identity-agent.js} | 0 ...dentity.test.js => identity-agent.test.js} | 4 +- 7 files changed, 268 insertions(+), 287 deletions(-) create mode 100644 packages/script/src/extensions/identity.js rename packages/script/src/{base.identity.test.js => extensions/identity.test.js} (86%) rename packages/script/src/{identity.js => identity-agent.js} (100%) rename packages/script/src/{identity.test.js => identity-agent.test.js} (97%) diff --git a/packages/script/build.js b/packages/script/build.js index 0eb2c5a..60f183f 100644 --- a/packages/script/build.js +++ b/packages/script/build.js @@ -9,12 +9,29 @@ const baseConfig = { target: 'es2015', }; +// Order matters: variant names list extensions in this order (e.g. script.site-visit.identity.js) +const EXTENSIONS = [ + 'site-visit', + 'outbound-domains', + 'conversion-tracking', + 'identity', +]; + // Helper to read and combine files const combineFiles = (files) => { // Just concatenate the files, esbuild will handle the IIFE wrapping return files.map((file) => fs.readFileSync(file, 'utf8')).join('\n'); }; +// Every subset of EXTENSIONS, keeping their order +const combinations = EXTENSIONS.reduce( + (subsets, extension) => [ + ...subsets, + ...subsets.map((subset) => [...subset, extension]), + ], + [[]], +); + // Ensure dist/analytics exists fs.mkdirSync(path.join(__dirname, 'dist/analytics'), { recursive: true }); @@ -24,129 +41,31 @@ fs.copyFileSync( path.join(__dirname, 'dist/_redirects'), ); -// Build all variants (8 total combinations of 3 extensions), plus identity.js +// Build all variants (16 combinations of 4 extensions), plus the identity agent they load on demand Promise.all([ - // 1. Base script (no extensions) - esbuild.build({ - ...baseConfig, - stdin: { - contents: fs.readFileSync('src/base.js', 'utf8'), - resolveDir: __dirname, - sourcefile: 'base.js', - }, - outfile: 'dist/analytics/script.js', - }), - - // 2. Site visit only - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles(['src/base.js', 'src/extensions/site-visit.js']), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.site-visit.js', - }), - - // 3. Outbound domains only - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/outbound-domains.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.outbound-domains.js', - }), - - // 4. Conversion tracking only - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/conversion-tracking.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.conversion-tracking.js', - }), - - // 5. Site visit + Outbound domains - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/site-visit.js', - 'src/extensions/outbound-domains.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.site-visit.outbound-domains.js', - }), - - // 6. Site visit + Conversion tracking - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/site-visit.js', - 'src/extensions/conversion-tracking.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.site-visit.conversion-tracking.js', - }), - - // 7. Outbound domains + Conversion tracking - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/outbound-domains.js', - 'src/extensions/conversion-tracking.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: 'dist/analytics/script.outbound-domains.conversion-tracking.js', - }), - - // 8. All extensions combined - esbuild.build({ - ...baseConfig, - stdin: { - contents: combineFiles([ - 'src/base.js', - 'src/extensions/site-visit.js', - 'src/extensions/outbound-domains.js', - 'src/extensions/conversion-tracking.js', - ]), - resolveDir: __dirname, - sourcefile: 'combined.js', - }, - outfile: - 'dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js', - }), + ...combinations.map((extensions) => + esbuild.build({ + ...baseConfig, + stdin: { + contents: combineFiles([ + 'src/base.js', + ...extensions.map((extension) => `src/extensions/${extension}.js`), + ]), + resolveDir: __dirname, + sourcefile: extensions.length ? 'combined.js' : 'base.js', + }, + outfile: `dist/analytics/${['script', ...extensions, 'js'].join('.')}`, + }), + ), - // 9. Identity, loaded on demand by every variant esbuild.build({ ...baseConfig, - entryPoints: ['src/identity.js'], + entryPoints: ['src/identity-agent.js'], define: { 'process.env.DUB_FINGERPRINT_PUBLIC_KEY': JSON.stringify( process.env.DUB_FINGERPRINT_PUBLIC_KEY ?? '', ), }, - outfile: 'dist/analytics/identity.js', + outfile: 'dist/analytics/identity-agent.js', }), ]).catch(() => process.exit(1)); diff --git a/packages/script/package.json b/packages/script/package.json index 16bfc6f..bff94a3 100644 --- a/packages/script/package.json +++ b/packages/script/package.json @@ -6,12 +6,20 @@ "dist/analytics/script.js", "dist/analytics/script.site-visit.js", "dist/analytics/script.outbound-domains.js", - "dist/analytics/script.conversion-tracking.js", "dist/analytics/script.site-visit.outbound-domains.js", + "dist/analytics/script.conversion-tracking.js", "dist/analytics/script.site-visit.conversion-tracking.js", "dist/analytics/script.outbound-domains.conversion-tracking.js", "dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js", - "dist/analytics/identity.js" + "dist/analytics/script.identity.js", + "dist/analytics/script.site-visit.identity.js", + "dist/analytics/script.outbound-domains.identity.js", + "dist/analytics/script.site-visit.outbound-domains.identity.js", + "dist/analytics/script.conversion-tracking.identity.js", + "dist/analytics/script.site-visit.conversion-tracking.identity.js", + "dist/analytics/script.outbound-domains.conversion-tracking.identity.js", + "dist/analytics/script.site-visit.outbound-domains.conversion-tracking.identity.js", + "dist/analytics/identity-agent.js" ], "scripts": { "prebuild": "mkdir -p dist/analytics", diff --git a/packages/script/src/base.js b/packages/script/src/base.js index 17c9cc4..f66cc0f 100644 --- a/packages/script/src/base.js +++ b/packages/script/src/base.js @@ -4,8 +4,6 @@ const DUB_ID_VAR = 'dub_id'; const DUB_PARTNER_COOKIE = 'dub_partner_data'; - const DUB_FID_VAR = 'dub_fid'; - const DUB_FID_MAX_AGE_SECONDS = 30 * 60; const COOKIE_EXPIRES = 90 * 24 * 60 * 60 * 1000; // 90 days const HOSTNAME = window.location.hostname; @@ -91,22 +89,6 @@ return [...new Set(resolvedQueryParams)]; })(); - const IDENTITY_PATHS = (() => { - const identityPaths = script.getAttribute('data-identity-paths'); - - if (!identityPaths) return []; - - try { - return JSON.parse(identityPaths); - } catch (error) { - console.warn( - '[dubAnalytics] Failed to parse data-identity-paths.', - error, - ); - return []; - } - })(); - const QUERY_PARAM_VALUE = (() => { const params = new URLSearchParams(location.search); @@ -136,8 +118,6 @@ dubAnalytics.ready(...args); } else if (method === 'trackClick') { dubAnalytics.trackClick(...args); - } else if (method === 'trackIdentity') { - return dubAnalytics.trackIdentity(); } else { console.warn('[dubAnalytics] Unknown method:', method); } @@ -154,10 +134,6 @@ trackClick(...args); }; - dubAnalytics.trackIdentity = function () { - return trackIdentity(); - }; - // Replace window.dubAnalytics with the callable + augmented function window.dubAnalytics = dubAnalytics; } @@ -208,8 +184,6 @@ callback(); } else if (['trackClick'].includes(method)) { trackClick(...args); - } else if (method === 'trackIdentity') { - trackIdentity(); } else { console.warn('[dubAnalytics] Unknown method:', method); } @@ -218,8 +192,6 @@ let clientClickTracked = false; let pendingClick = Promise.resolve(); - let pendingIdentity; - let identityScript; // Track click and set cookie function trackClick({ domain, key }) { @@ -270,115 +242,6 @@ }); } - function matchesIdentityPath(pathname) { - const normalize = (path) => - path.length > 1 ? path.replace(/\/+$/, '') : path; - const current = normalize(pathname); - - return IDENTITY_PATHS.some((path) => { - if (path.endsWith('/*')) { - const base = normalize(path.slice(0, -2)); - - return ( - base === '' || current === base || current.startsWith(`${base}/`) - ); - } - - return current === normalize(path); - }); - } - - // The Fingerprint agent lives in identity.js, next to this script, so it only loads when needed - function loadIdentityScript() { - identityScript = - identityScript || - new Promise((resolve, reject) => { - const identity = document.createElement('script'); - identity.src = new URL('identity.js', script.src).href; - identity.async = true; - identity.onload = () => resolve(window._dubIdentity); - identity.onerror = () => { - identityScript = undefined; - reject(new Error('Failed to load identity.js')); - }; - document.head.appendChild(identity); - }); - - return identityScript; - } - - // Links the visitor's device to their click, at most once per click every 30 minutes - function trackIdentity() { - pendingIdentity = - pendingIdentity || - pendingClick - .catch(() => undefined) - .then(() => { - const clickId = cookieManager.get(DUB_ID_VAR); - - if (!clickId || cookieManager.get(DUB_FID_VAR) === clickId) { - return; - } - - return loadIdentityScript() - .then((identity) => - identity.identify({ - apiHost: API_HOST, - clickId, - }), - ) - .then((identified) => { - if (identified) { - document.cookie = `${DUB_FID_VAR}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; - } - }); - }) - .catch((error) => { - console.warn('[dubAnalytics] trackIdentity failed.', error); - }) - .then(() => { - pendingIdentity = undefined; - }); - - return pendingIdentity; - } - - // Identifies on the first page load and on client-side navigation to a matching path - function watchIdentityPaths() { - if (!IDENTITY_PATHS.length) return; - - let lastPathname; - - const check = () => { - const { pathname } = window.location; - - if (pathname === lastPathname) return; - - lastPathname = pathname; - - if (matchesIdentityPath(pathname)) { - trackIdentity(); - } - }; - - const pushState = history.pushState.bind(history); - const replaceState = history.replaceState.bind(history); - - history.pushState = (...args) => { - pushState(...args); - check(); - }; - - history.replaceState = (...args) => { - replaceState(...args); - check(); - }; - - window.addEventListener('popstate', check); - - check(); - } - // Initialize tracking function init() { const params = new URLSearchParams(location.search); @@ -406,11 +269,7 @@ } // Process the queued methods - queueManager.flush( - (method) => method === 'trackClick' || method === 'trackIdentity', - ); - - watchIdentityPaths(); + queueManager.flush((method) => method === 'trackClick'); // Initialize DubAnalytics from cookie if it exists const partnerCookie = cookieManager.get(DUB_PARTNER_COOKIE); @@ -438,6 +297,8 @@ v: QUERY_PARAM_VALUE, n: DOMAINS_CONFIG, k: PUBLISHABLE_KEY, + s: script, + p: () => pendingClick, }; // Initialize diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js new file mode 100644 index 0000000..9d00144 --- /dev/null +++ b/packages/script/src/extensions/identity.js @@ -0,0 +1,173 @@ +const initIdentity = () => { + const { + a: API_HOST, + c: cookieManager, + i: DUB_ID_VAR, + s: script, + p: getPendingClick, + } = window._dubAnalytics || {}; + + const DUB_FID_VAR = 'dub_fid'; + const DUB_FID_MAX_AGE_SECONDS = 30 * 60; + + const IDENTITY_PATHS = (() => { + const identityPaths = script.getAttribute('data-identity-paths'); + + if (!identityPaths) return []; + + try { + return JSON.parse(identityPaths); + } catch (error) { + console.warn( + '[dubAnalytics] Failed to parse data-identity-paths.', + error, + ); + return []; + } + })(); + + let pendingIdentity; + let identityAgent; + + function matchesIdentityPath(pathname) { + const normalize = (path) => + path.length > 1 ? path.replace(/\/+$/, '') : path; + const current = normalize(pathname); + + return IDENTITY_PATHS.some((path) => { + if (path.endsWith('/*')) { + const base = normalize(path.slice(0, -2)); + + return ( + base === '' || current === base || current.startsWith(`${base}/`) + ); + } + + return current === normalize(path); + }); + } + + // The Fingerprint agent lives in identity-agent.js, next to this script, so it only loads when needed + function loadIdentityAgent() { + identityAgent = + identityAgent || + new Promise((resolve, reject) => { + const agent = document.createElement('script'); + agent.src = new URL('identity-agent.js', script.src).href; + agent.async = true; + agent.onload = () => resolve(window._dubIdentity); + agent.onerror = () => { + identityAgent = undefined; + reject(new Error('Failed to load identity-agent.js')); + }; + document.head.appendChild(agent); + }); + + return identityAgent; + } + + // Links the visitor's device to their click, at most once per click every 30 minutes + function trackIdentity() { + pendingIdentity = + pendingIdentity || + getPendingClick() + .catch(() => undefined) + .then(() => { + const clickId = cookieManager.get(DUB_ID_VAR); + + if (!clickId || cookieManager.get(DUB_FID_VAR) === clickId) { + return; + } + + return loadIdentityAgent() + .then((identity) => + identity.identify({ + apiHost: API_HOST, + clickId, + }), + ) + .then((identified) => { + if (identified) { + document.cookie = `${DUB_FID_VAR}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; + } + }); + }) + .catch((error) => { + console.warn('[dubAnalytics] trackIdentity failed.', error); + }) + .then(() => { + pendingIdentity = undefined; + }); + + return pendingIdentity; + } + + // Identifies on the first page load and on client-side navigation to a matching path + function watchIdentityPaths() { + if (!IDENTITY_PATHS.length) return; + + let lastPathname; + + const check = () => { + const { pathname } = window.location; + + if (pathname === lastPathname) return; + + lastPathname = pathname; + + if (matchesIdentityPath(pathname)) { + trackIdentity(); + } + }; + + const pushState = history.pushState.bind(history); + const replaceState = history.replaceState.bind(history); + + history.pushState = (...args) => { + pushState(...args); + check(); + }; + + history.replaceState = (...args) => { + replaceState(...args); + check(); + }; + + window.addEventListener('popstate', check); + + check(); + } + + // Add method to the global dubAnalytics object for direct calls + if (window.dubAnalytics) { + window.dubAnalytics.trackIdentity = function () { + return trackIdentity(); + }; + } + + // Process any existing queued trackIdentity calls + if (window._dubAnalytics && window._dubAnalytics.qm) { + const queueManager = window._dubAnalytics.qm; + const existingQueue = queueManager.queue || []; + + const remainingQueue = existingQueue.filter(([method]) => { + if (method === 'trackIdentity') { + trackIdentity(); + return false; + } + + return true; + }); + + queueManager.queue = remainingQueue; + } + + watchIdentityPaths(); +}; + +// Run when base script is ready +if (window._dubAnalytics) { + initIdentity(); +} else { + window.addEventListener('load', initIdentity); +} diff --git a/packages/script/src/base.identity.test.js b/packages/script/src/extensions/identity.test.js similarity index 86% rename from packages/script/src/base.identity.test.js rename to packages/script/src/extensions/identity.test.js index d847c44..922b5e7 100644 --- a/packages/script/src/base.identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -2,8 +2,12 @@ import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -const BASE_SOURCE = readFileSync(join(__dirname, 'base.js'), 'utf8'); -const SCRIPT_SRC = 'https://www.dubcdn.com/analytics/script.js'; +const BASE_SOURCE = readFileSync(join(__dirname, '../base.js'), 'utf8'); +const SOURCE = [ + BASE_SOURCE, + readFileSync(join(__dirname, 'identity.js'), 'utf8'), +].join('\n'); +const SCRIPT_SRC = 'https://www.dubcdn.com/analytics/script.identity.js'; const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; const { pushState, replaceState } = window.history; @@ -12,7 +16,7 @@ const popstateListeners = []; const fetchMock = vi.fn(); const identify = vi.fn(); -function runBase(attributes = {}) { +function runScript(attributes = {}, source = SOURCE) { const script = document.createElement('script'); script.src = SCRIPT_SRC; @@ -25,7 +29,7 @@ function runBase(attributes = {}) { get: () => script, }); - new Function(BASE_SOURCE)(); + new Function(source)(); } function stubDubAnalytics() { @@ -60,7 +64,7 @@ function flush() { }); } -describe('base.js identity', () => { +describe('identity extension', () => { beforeEach(() => { clearCookies(); document.head.innerHTML = ''; @@ -82,7 +86,7 @@ describe('base.js identity', () => { vi.spyOn(document.head, 'appendChild').mockImplementation((node) => { document.head.append(node); - if (node.src.endsWith('/identity.js')) { + if (node.src.endsWith('/identity-agent.js')) { window._dubIdentity = { identify, }; @@ -106,11 +110,11 @@ describe('base.js identity', () => { vi.clearAllMocks(); }); - it('loads identity.js next to the script and identifies the click on a matching path', async () => { + it('loads identity-agent.js next to the script and identifies the click on a matching path', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-api-host': 'https://api.example.com', 'data-identity-paths': JSON.stringify(['/signup']), }); @@ -120,7 +124,7 @@ describe('base.js identity', () => { }); expect(loadedIdentityScripts()).toEqual([ - 'https://www.dubcdn.com/analytics/identity.js', + 'https://www.dubcdn.com/analytics/identity-agent.js', ]); expect(identify).toHaveBeenCalledWith({ apiHost: 'https://api.example.com', @@ -137,7 +141,7 @@ describe('base.js identity', () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', pathname); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(paths), }); @@ -155,7 +159,7 @@ describe('base.js identity', () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', pathname); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(paths), }); await flush(); @@ -163,19 +167,35 @@ describe('base.js identity', () => { expect(loadedIdentityScripts()).toEqual([]); }); + it('is not part of variants without the identity extension', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runScript( + { + 'data-identity-paths': JSON.stringify(['/signup']), + }, + BASE_SOURCE, + ); + await flush(); + + expect(window.dubAnalytics.trackIdentity).toBeUndefined(); + expect(loadedIdentityScripts()).toEqual([]); + }); + it('does nothing without data-identity-paths', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase(); + runScript(); await flush(); expect(loadedIdentityScripts()).toEqual([]); }); - it('skips loading identity.js without a dub_id cookie', async () => { + it('skips loading identity-agent.js without a dub_id cookie', async () => { replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -188,7 +208,7 @@ describe('base.js identity', () => { document.cookie = `dub_fid=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -201,7 +221,7 @@ describe('base.js identity', () => { document.cookie = 'dub_fid=otherClickId; path=/'; replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); @@ -219,7 +239,7 @@ describe('base.js identity', () => { ); replaceState.call(window.history, null, '', '/signup?via=partner'); - runBase({ + runScript({ 'data-domains': JSON.stringify({ refer: 'dub.sh', }), @@ -251,7 +271,7 @@ describe('base.js identity', () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); @@ -263,7 +283,7 @@ describe('base.js identity', () => { expect(getCookie('dub_fid')).toBeUndefined(); }); - it('never throws when identity.js fails to load', async () => { + it('never throws when identity-agent.js fails to load', async () => { document.head.appendChild.mockImplementation((node) => { document.head.append(node); setTimeout(() => node.onerror()); @@ -271,7 +291,7 @@ describe('base.js identity', () => { }); document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase(); + runScript(); await expect(window.dubAnalytics.trackIdentity()).resolves.toBeUndefined(); expect(getCookie('dub_fid')).toBeUndefined(); @@ -280,7 +300,7 @@ describe('base.js identity', () => { it('identifies after a client-side navigation to a matching path', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -297,7 +317,7 @@ describe('base.js identity', () => { it('identifies when going back to a matching path', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -314,7 +334,7 @@ describe('base.js identity', () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); - runBase({ + runScript({ 'data-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { @@ -332,7 +352,7 @@ describe('base.js identity', () => { it('exposes trackIdentity on window.dubAnalytics without paths', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase(); + runScript(); await window.dubAnalytics.trackIdentity(); expect(identify).toHaveBeenCalledTimes(1); @@ -343,7 +363,7 @@ describe('base.js identity', () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; window.dubAnalytics('trackIdentity'); - runBase(); + runScript(); await vi.waitFor(() => { expect(identify).toHaveBeenCalledTimes(1); @@ -353,7 +373,7 @@ describe('base.js identity', () => { it('shares one identification between concurrent calls', async () => { document.cookie = `dub_id=${CLICK_ID}; path=/`; - runBase(); + runScript(); await Promise.all([ window.dubAnalytics.trackIdentity(), window.dubAnalytics.trackIdentity(), diff --git a/packages/script/src/identity.js b/packages/script/src/identity-agent.js similarity index 100% rename from packages/script/src/identity.js rename to packages/script/src/identity-agent.js diff --git a/packages/script/src/identity.test.js b/packages/script/src/identity-agent.test.js similarity index 97% rename from packages/script/src/identity.test.js rename to packages/script/src/identity-agent.test.js index 52ca749..eceb5da 100644 --- a/packages/script/src/identity.test.js +++ b/packages/script/src/identity-agent.test.js @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import './identity'; +import './identity-agent'; const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; const SEALED_RESULT = 'noXc7Q=='; @@ -28,7 +28,7 @@ function identify() { }); } -describe('identity.js', () => { +describe('identity-agent.js', () => { beforeEach(() => { vi.stubGlobal('fetch', fetchMock); vi.spyOn(console, 'warn').mockImplementation(() => undefined); From 600df93fd09c342425a91b954c74681d4a912bff Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:29:27 +0530 Subject: [PATCH 17/55] Load the identity script variant when trackIdentity is set --- packages/web/src/generic.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index 904baf9..90a2422 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -35,6 +35,7 @@ function inject(props: AnalyticsProps): void { if (props.domainsConfig?.site) features.push('site-visit'); if (props.domainsConfig?.outbound) features.push('outbound-domains'); if (props.publishableKey) features.push('conversion-tracking'); + if (props.trackIdentity) features.push('identity'); const src = props.scriptProps?.src || From eeab545ae89b7a0d3e524e8e3dbc50a0691de7ed Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 17:29:28 +0530 Subject: [PATCH 18/55] Document the identity script variant --- packages/web/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index e640929..40878b8 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -98,7 +98,7 @@ It only runs for visitors with a `dub_id` cookie, and at most once per click eve ``` -To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` and `dub_fid` rules. +To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` and `dub_fid` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). ```tsx const { trackIdentity } = useAnalytics(); @@ -106,17 +106,17 @@ const { trackIdentity } = useAnalytics(); await trackIdentity(); ``` -Every script variant supports this, so installs without React work too. Set the paths with a `data-identity-paths` attribute, and call `dubAnalytics.trackIdentity()`. To queue calls made before the script loads, add `trackIdentity` to the snippet's method list. +Without React, use the `identity` script variant (`script.identity.js`, or combined like `script.site-visit.identity.js`). Set the paths with a `data-identity-paths` attribute, and call `dubAnalytics.trackIdentity()`. To queue calls made before the script loads, add `trackIdentity` to the snippet's method list. ```html ``` -The device identification agent loads from `identity.js` next to the script. If you serve the script from your own domain or a proxy, serve `identity.js` from the same folder. +The device identification agent loads from `identity-agent.js` next to the script. If you serve the script from your own domain or a proxy, serve `identity-agent.js` from the same folder. ### `scriptProps` From 94550859e9a95b7f6065d966c625db772bd58deb Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 19:57:11 +0530 Subject: [PATCH 19/55] Ignore data-identity-paths that is not an array of paths --- packages/script/src/extensions/identity.js | 6 +++++- .../script/src/extensions/identity.test.js | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index 9d00144..ad65780 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -16,7 +16,11 @@ const initIdentity = () => { if (!identityPaths) return []; try { - return JSON.parse(identityPaths); + const paths = JSON.parse(identityPaths); + + return Array.isArray(paths) + ? paths.filter((path) => typeof path === 'string') + : []; } catch (error) { console.warn( '[dubAnalytics] Failed to parse data-identity-paths.', diff --git a/packages/script/src/extensions/identity.test.js b/packages/script/src/extensions/identity.test.js index 922b5e7..8d54411 100644 --- a/packages/script/src/extensions/identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -192,6 +192,26 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); + it('ignores data-identity-paths that is not an array of paths', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + expect(() => + runScript({ + 'data-identity-paths': JSON.stringify('/signup'), + }), + ).not.toThrow(); + expect(() => + runScript({ + 'data-identity-paths': JSON.stringify([42, '/signup']), + }), + ).not.toThrow(); + + await vi.waitFor(() => { + expect(identify).toHaveBeenCalledTimes(1); + }); + }); + it('skips loading identity-agent.js without a dub_id cookie', async () => { replaceState.call(window.history, null, '', '/signup'); From 389d35109bc53f96ce13388936da591fd9e8b1dd Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 19:57:48 +0530 Subject: [PATCH 20/55] Skip trackIdentity in useAnalytics when the identity variant isn't loaded --- packages/web/src/use-analytics.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/src/use-analytics.ts b/packages/web/src/use-analytics.ts index fed0ecf..db2cb8e 100644 --- a/packages/web/src/use-analytics.ts +++ b/packages/web/src/use-analytics.ts @@ -20,7 +20,7 @@ declare global { trackClick: (event: TrackClickInput) => void; trackLead: (event: TrackLeadInput) => void; trackSale: (event: TrackSaleInput) => void; - trackIdentity: () => Promise | void; + trackIdentity?: () => Promise | void; }; } } @@ -89,7 +89,7 @@ export function useAnalytics() { return; } - await window.dubAnalytics.trackIdentity(); + await window.dubAnalytics.trackIdentity?.(); }, []); useEffect(() => { From c1a9752170c2b07db2602e54af82da8c76126dbb Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 19:57:48 +0530 Subject: [PATCH 21/55] Keep the existing files order in the script package --- packages/script/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/script/package.json b/packages/script/package.json index bff94a3..fdabd6b 100644 --- a/packages/script/package.json +++ b/packages/script/package.json @@ -6,8 +6,8 @@ "dist/analytics/script.js", "dist/analytics/script.site-visit.js", "dist/analytics/script.outbound-domains.js", - "dist/analytics/script.site-visit.outbound-domains.js", "dist/analytics/script.conversion-tracking.js", + "dist/analytics/script.site-visit.outbound-domains.js", "dist/analytics/script.site-visit.conversion-tracking.js", "dist/analytics/script.outbound-domains.conversion-tracking.js", "dist/analytics/script.site-visit.outbound-domains.conversion-tracking.js", From bf8ac23033dd2dcd67b322c3a4d0f24cf0366975 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 2 Nov 2026 19:57:49 +0530 Subject: [PATCH 22/55] Fix the identity agent loader comment --- packages/script/src/identity-agent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/script/src/identity-agent.js b/packages/script/src/identity-agent.js index 6567e8c..1e392f3 100644 --- a/packages/script/src/identity-agent.js +++ b/packages/script/src/identity-agent.js @@ -2,7 +2,7 @@ import { start } from '@fingerprint/agent'; const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; -// Loaded on demand by base.js; resolves true once Dub has linked the device to the click +// Loaded on demand by the identity extension; resolves true once Dub has linked the device to the click async function identify({ apiHost, clickId }) { if (!FINGERPRINT_PUBLIC_KEY) { return false; From 75098bb1d664b9d325466c53d2d69a36a14207c9 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 4 Nov 2026 11:59:07 +0530 Subject: [PATCH 23/55] Send the bare clickId when dub_id carries a visitorId suffix --- .../src/extensions/conversion-tracking.js | 6 +- .../src/extensions/identified-dub-id.test.js | 90 +++++++++++++++++++ .../script/src/extensions/outbound-domains.js | 4 +- 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 packages/script/src/extensions/identified-dub-id.test.js diff --git a/packages/script/src/extensions/conversion-tracking.js b/packages/script/src/extensions/conversion-tracking.js index 6d23a5f..c20073c 100644 --- a/packages/script/src/extensions/conversion-tracking.js +++ b/packages/script/src/extensions/conversion-tracking.js @@ -18,7 +18,8 @@ const initConversionTracking = () => { // Track lead conversion const trackLead = async (input) => { - const clickId = cookieManager?.get(DUB_ID_VAR); + // Drop the visitorId the identity extension appends to dub_id + const clickId = cookieManager?.get(DUB_ID_VAR)?.split('_')[0]; const requestBody = { clickId: clickId ?? '', ...input, @@ -44,7 +45,8 @@ const initConversionTracking = () => { // Track sale conversion const trackSale = async (input) => { - const clickId = cookieManager?.get(DUB_ID_VAR); + // Drop the visitorId the identity extension appends to dub_id + const clickId = cookieManager?.get(DUB_ID_VAR)?.split('_')[0]; const requestBody = { clickId: clickId ?? '', ...input, diff --git a/packages/script/src/extensions/identified-dub-id.test.js b/packages/script/src/extensions/identified-dub-id.test.js new file mode 100644 index 0000000..35e7fbb --- /dev/null +++ b/packages/script/src/extensions/identified-dub-id.test.js @@ -0,0 +1,90 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +const BASE_SOURCE = readFileSync(join(__dirname, '../base.js'), 'utf8'); +const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; +const IDENTIFIED_CLICK_ID = `${CLICK_ID}_Uxk0Swb1Ofgfq2Jcg1cV`; + +const fetchMock = vi.fn(); + +function runScript(extension, attributes) { + const script = document.createElement('script'); + script.src = 'https://www.dubcdn.com/analytics/script.js'; + + Object.entries(attributes).forEach(([name, value]) => { + script.setAttribute(name, value); + }); + + Object.defineProperty(document, 'currentScript', { + configurable: true, + get: () => script, + }); + + new Function( + [ + BASE_SOURCE, + readFileSync(join(__dirname, `${extension}.js`), 'utf8'), + ].join('\n'), + )(); +} + +describe('dub_id suffixed by the identity extension', () => { + beforeEach(() => { + window.dubAnalytics = function () {}; + document.cookie = `dub_id=${IDENTIFIED_CLICK_ID}; path=/`; + vi.stubGlobal('fetch', fetchMock); + fetchMock.mockResolvedValue(new Response(JSON.stringify({}))); + }); + + afterEach(() => { + document.cookie = 'dub_id=; path=/; max-age=0'; + document.body.innerHTML = ''; + vi.unstubAllGlobals(); + vi.clearAllMocks(); + }); + + it.each(['trackLead', 'trackSale'])( + '%s sends the bare clickId', + async (method) => { + runScript('conversion-tracking', { + 'data-publishable-key': 'dub_pk_test', + }); + + window.dubAnalytics[method]({ + eventName: 'Sign up', + }); + + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + expect(JSON.parse(fetchMock.mock.calls[0][1].body).clickId).toBe( + CLICK_ID, + ); + }, + ); + + it('decorates outbound links with the bare clickId', () => { + document.body.innerHTML = 'Go'; + + runScript('outbound-domains', { + 'data-domains': JSON.stringify({ + outbound: ['app.example.com'], + }), + }); + + expect(document.querySelector('a').href).toBe( + `https://app.example.com/signup?dub_id=${CLICK_ID}`, + ); + }); + + it('does not track a new click on the next load', () => { + runScript('site-visit', { + 'data-domains': JSON.stringify({ + site: 'dub.sh', + }), + }); + + expect(fetchMock).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/script/src/extensions/outbound-domains.js b/packages/script/src/extensions/outbound-domains.js index 8b3bd9b..1f78f16 100644 --- a/packages/script/src/extensions/outbound-domains.js +++ b/packages/script/src/extensions/outbound-domains.js @@ -44,7 +44,9 @@ const initOutboundDomains = () => { .map(normalizeDomain) .filter((d) => d !== currentDomain); - const existingCookie = clickId || cookieManager.get(DUB_ID_VAR); + // Drop the visitorId the identity extension appends to dub_id, so each domain identifies its own visit + const existingCookie = + clickId || cookieManager.get(DUB_ID_VAR)?.split('_')[0]; if (!existingCookie) return; // Get all links and iframes From 0aec2d6ee4e31055abf22e1999bdd280b582df8f Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 4 Nov 2026 11:59:07 +0530 Subject: [PATCH 24/55] Suffix dub_id with the Fingerprint visitorId instead of sending sealed results --- packages/script/src/extensions/identity.js | 15 +++-- .../script/src/extensions/identity.test.js | 58 ++++++++++++++----- packages/script/src/identity-agent.js | 39 +++++++------ packages/script/src/identity-agent.test.js | 42 +++++++++----- 4 files changed, 99 insertions(+), 55 deletions(-) diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index ad65780..a19395d 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -7,9 +7,6 @@ const initIdentity = () => { p: getPendingClick, } = window._dubAnalytics || {}; - const DUB_FID_VAR = 'dub_fid'; - const DUB_FID_MAX_AGE_SECONDS = 30 * 60; - const IDENTITY_PATHS = (() => { const identityPaths = script.getAttribute('data-identity-paths'); @@ -70,7 +67,7 @@ const initIdentity = () => { return identityAgent; } - // Links the visitor's device to their click, at most once per click every 30 minutes + // Links the visitor's device to their click once, then suffixes dub_id with the visitorId function trackIdentity() { pendingIdentity = pendingIdentity || @@ -79,7 +76,8 @@ const initIdentity = () => { .then(() => { const clickId = cookieManager.get(DUB_ID_VAR); - if (!clickId || cookieManager.get(DUB_FID_VAR) === clickId) { + // Click ids never contain "_", so a suffixed dub_id is already identified + if (!clickId || clickId.includes('_')) { return; } @@ -90,9 +88,10 @@ const initIdentity = () => { clickId, }), ) - .then((identified) => { - if (identified) { - document.cookie = `${DUB_FID_VAR}=${clickId}; path=/; max-age=${DUB_FID_MAX_AGE_SECONDS}; SameSite=Lax`; + .then((visitorId) => { + // Skip when a new click replaced dub_id while identifying + if (visitorId && cookieManager.get(DUB_ID_VAR) === clickId) { + cookieManager.set(DUB_ID_VAR, `${clickId}_${visitorId}`); } }); }) diff --git a/packages/script/src/extensions/identity.test.js b/packages/script/src/extensions/identity.test.js index 8d54411..ecfeef4 100644 --- a/packages/script/src/extensions/identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -9,6 +9,8 @@ const SOURCE = [ ].join('\n'); const SCRIPT_SRC = 'https://www.dubcdn.com/analytics/script.identity.js'; const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; +const VISITOR_ID = 'Uxk0Swb1Ofgfq2Jcg1cV'; +const IDENTIFIED_CLICK_ID = `${CLICK_ID}_${VISITOR_ID}`; const { pushState, replaceState } = window.history; const addEventListener = window.addEventListener.bind(window); @@ -81,7 +83,7 @@ describe('identity extension', () => { }, ); - identify.mockResolvedValue(true); + identify.mockResolvedValue(VISITOR_ID); vi.spyOn(document.head, 'appendChild').mockImplementation((node) => { document.head.append(node); @@ -120,7 +122,7 @@ describe('identity extension', () => { }); await vi.waitFor(() => { - expect(getCookie('dub_fid')).toBe(CLICK_ID); + expect(getCookie('dub_id')).toBe(IDENTIFIED_CLICK_ID); }); expect(loadedIdentityScripts()).toEqual([ @@ -223,9 +225,8 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); - it('skips when dub_fid already matches the click', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - document.cookie = `dub_fid=${CLICK_ID}; path=/`; + it('skips when dub_id is already suffixed with a visitorId', async () => { + document.cookie = `dub_id=${IDENTIFIED_CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); runScript({ @@ -236,18 +237,45 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); - it('identifies again when dub_fid belongs to another click', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; - document.cookie = 'dub_fid=otherClickId; path=/'; - replaceState.call(window.history, null, '', '/signup'); + it('identifies a new ?via= click that replaced an identified dub_id', async () => { + document.cookie = 'dub_id=oldClickId_oldVisitorId; path=/'; + fetchMock.mockResolvedValue( + new Response( + JSON.stringify({ + clickId: CLICK_ID, + }), + ), + ); + replaceState.call(window.history, null, '', '/signup?via=partner'); runScript({ + 'data-domains': JSON.stringify({ + refer: 'dub.sh', + }), 'data-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { - expect(getCookie('dub_fid')).toBe(CLICK_ID); + expect(getCookie('dub_id')).toBe(IDENTIFIED_CLICK_ID); + }); + expect(identify).toHaveBeenCalledWith( + expect.objectContaining({ + clickId: CLICK_ID, + }), + ); + }); + + it('keeps a new click that replaced dub_id while identifying', async () => { + identify.mockImplementation(async () => { + document.cookie = 'dub_id=newClickId; path=/'; + return VISITOR_ID; }); + document.cookie = `dub_id=${CLICK_ID}; path=/`; + + runScript(); + await window.dubAnalytics.trackIdentity(); + + expect(getCookie('dub_id')).toBe('newClickId'); }); it('waits for a ?via= click before identifying', async () => { @@ -286,8 +314,8 @@ describe('identity extension', () => { }); }); - it('does not set dub_fid when identification fails', async () => { - identify.mockResolvedValue(false); + it('keeps dub_id unchanged when identification fails', async () => { + identify.mockResolvedValue(null); document.cookie = `dub_id=${CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); @@ -300,7 +328,7 @@ describe('identity extension', () => { }); await flush(); - expect(getCookie('dub_fid')).toBeUndefined(); + expect(getCookie('dub_id')).toBe(CLICK_ID); }); it('never throws when identity-agent.js fails to load', async () => { @@ -314,7 +342,7 @@ describe('identity extension', () => { runScript(); await expect(window.dubAnalytics.trackIdentity()).resolves.toBeUndefined(); - expect(getCookie('dub_fid')).toBeUndefined(); + expect(getCookie('dub_id')).toBe(CLICK_ID); }); it('identifies after a client-side navigation to a matching path', async () => { @@ -376,7 +404,7 @@ describe('identity extension', () => { await window.dubAnalytics.trackIdentity(); expect(identify).toHaveBeenCalledTimes(1); - expect(getCookie('dub_fid')).toBe(CLICK_ID); + expect(getCookie('dub_id')).toBe(IDENTIFIED_CLICK_ID); }); it('runs a trackIdentity call queued before the script loaded', async () => { diff --git a/packages/script/src/identity-agent.js b/packages/script/src/identity-agent.js index 1e392f3..708bc59 100644 --- a/packages/script/src/identity-agent.js +++ b/packages/script/src/identity-agent.js @@ -2,41 +2,44 @@ import { start } from '@fingerprint/agent'; const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; -// Loaded on demand by the identity extension; resolves true once Dub has linked the device to the click +// Loaded on demand by the identity extension; resolves the visitorId once the device is identified async function identify({ apiHost, clickId }) { if (!FINGERPRINT_PUBLIC_KEY) { - return false; + return null; } - // The server reads the click from linkedId - const { sealed_result: sealedResult } = await start({ + // Needs Sealed Client Results off for the workspace, so visitor_id comes back in plaintext + const { visitor_id: visitorId, event_id: eventId } = await start({ apiKey: FINGERPRINT_PUBLIC_KEY, }).get({ linkedId: clickId, }); - if (!sealedResult) { - return false; + if (!visitorId || !eventId) { + return null; } - const response = await fetch(`${apiHost}/track/identity`, { + fetch(`${apiHost}/track/identity`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ - identityToken: sealedResult.base64(), + eventId, }), - }); - - if (!response.ok) { - console.warn( - `[dubAnalytics] trackIdentity failed with status ${response.status}.`, - ); - return false; - } - - return true; + }) + .then((response) => { + if (!response.ok) { + console.warn( + `[dubAnalytics] trackIdentity failed with status ${response.status}.`, + ); + } + }) + .catch((error) => { + console.warn('[dubAnalytics] trackIdentity failed.', error); + }); + + return visitorId; } window._dubIdentity = { diff --git a/packages/script/src/identity-agent.test.js b/packages/script/src/identity-agent.test.js index eceb5da..5719e37 100644 --- a/packages/script/src/identity-agent.test.js +++ b/packages/script/src/identity-agent.test.js @@ -2,7 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import './identity-agent'; const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; -const SEALED_RESULT = 'noXc7Q=='; +const VISITOR_ID = 'Uxk0Swb1Ofgfq2Jcg1cV'; +const EVENT_ID = '1708102555327.NLOjmg'; const { get, start } = vi.hoisted(() => { const getMock = vi.fn(); @@ -34,10 +35,9 @@ describe('identity-agent.js', () => { vi.spyOn(console, 'warn').mockImplementation(() => undefined); get.mockResolvedValue({ - event_id: 'evt_1', - sealed_result: { - base64: () => SEALED_RESULT, - }, + event_id: EVENT_ID, + visitor_id: VISITOR_ID, + sealed_result: null, }); fetchMock.mockResolvedValue( @@ -54,8 +54,8 @@ describe('identity-agent.js', () => { vi.clearAllMocks(); }); - it('identifies with linkedId set to the clickId and posts only the identityToken', async () => { - await expect(identify()).resolves.toBe(true); + it('identifies with linkedId set to the clickId and posts only the eventId', async () => { + await expect(identify()).resolves.toBe(VISITOR_ID); expect(start).toHaveBeenCalledWith({ apiKey: 'test_public_key', @@ -71,30 +71,44 @@ describe('identity-agent.js', () => { 'Content-Type': 'application/json', }, body: JSON.stringify({ - identityToken: SEALED_RESULT, + eventId: EVENT_ID, }), }, ); }); - it('skips the request when sealed results are off', async () => { + it('skips the request without a visitor_id, as when Sealed Client Results are on', async () => { get.mockResolvedValue({ - event_id: 'evt_1', - sealed_result: null, + event_id: EVENT_ID, + sealed_result: { + base64: () => 'noXc7Q==', + }, }); - await expect(identify()).resolves.toBe(false); + await expect(identify()).resolves.toBeNull(); expect(fetchMock).not.toHaveBeenCalled(); }); - it('resolves false when the request is rejected', async () => { + it('resolves the visitorId without waiting for the request', async () => { + fetchMock.mockReturnValue(new Promise(() => undefined)); + + await expect(identify()).resolves.toBe(VISITOR_ID); + }); + + it('warns when the request is rejected', async () => { fetchMock.mockResolvedValue( new Response('Bad Request', { status: 400, }), ); - await expect(identify()).resolves.toBe(false); + await expect(identify()).resolves.toBe(VISITOR_ID); + + await vi.waitFor(() => { + expect(console.warn).toHaveBeenCalledWith( + '[dubAnalytics] trackIdentity failed with status 400.', + ); + }); }); }); From f89a148e16f45cb79ce1711c09e3c5c7a72832ee Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 4 Nov 2026 11:59:08 +0530 Subject: [PATCH 25/55] Document the dub_id visitorId suffix --- packages/web/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index 40878b8..7cd18af 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -92,13 +92,15 @@ Identifies the visitor's device on the given paths and links it to their Dub cli A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. -It only runs for visitors with a `dub_id` cookie, and at most once per click every 30 minutes (tracked with a `dub_fid` cookie). The device identification agent is loaded only when identification runs, and failures never throw or block the page. +It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. The script strips the suffix before sending the click ID with `trackLead`, `trackSale` or outbound links, but if you read the `dub_id` cookie yourself, use the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. + +Identification needs Sealed Client Results turned off in the Fingerprint workspace, so the agent returns the visitor ID. ```tsx ``` -To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` and `dub_fid` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). +To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). ```tsx const { trackIdentity } = useAnalytics(); From a61fa25b78bea743ac55af32293fac4063091283 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 4 Nov 2026 12:26:39 +0530 Subject: [PATCH 26/55] Split trackIdentity into an async identifyClick for readability --- packages/script/src/extensions/identity.js | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index a19395d..8304731 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -68,33 +68,33 @@ const initIdentity = () => { } // Links the visitor's device to their click once, then suffixes dub_id with the visitorId + async function identifyClick() { + await getPendingClick().catch(() => undefined); + + const clickId = cookieManager.get(DUB_ID_VAR); + + // Click ids never contain "_", so a suffixed dub_id is already identified + if (!clickId || clickId.includes('_')) { + return; + } + + const identity = await loadIdentityAgent(); + const visitorId = await identity.identify({ + apiHost: API_HOST, + clickId, + }); + + // Skip when a new click replaced dub_id while identifying + if (visitorId && cookieManager.get(DUB_ID_VAR) === clickId) { + cookieManager.set(DUB_ID_VAR, `${clickId}_${visitorId}`); + } + } + + // Concurrent calls share one run, and failures never reach the caller function trackIdentity() { pendingIdentity = pendingIdentity || - getPendingClick() - .catch(() => undefined) - .then(() => { - const clickId = cookieManager.get(DUB_ID_VAR); - - // Click ids never contain "_", so a suffixed dub_id is already identified - if (!clickId || clickId.includes('_')) { - return; - } - - return loadIdentityAgent() - .then((identity) => - identity.identify({ - apiHost: API_HOST, - clickId, - }), - ) - .then((visitorId) => { - // Skip when a new click replaced dub_id while identifying - if (visitorId && cookieManager.get(DUB_ID_VAR) === clickId) { - cookieManager.set(DUB_ID_VAR, `${clickId}_${visitorId}`); - } - }); - }) + identifyClick() .catch((error) => { console.warn('[dubAnalytics] trackIdentity failed.', error); }) From e6d7a46b4f35387bcec66a2ea0ea85140f484a9f Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 4 Nov 2026 12:27:43 +0530 Subject: [PATCH 27/55] Drop the visitorId suffix from ?dub_id= before setting the cookie --- packages/script/src/base.js | 3 ++- packages/script/src/extensions/identity.test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/script/src/base.js b/packages/script/src/base.js index f66cc0f..c215bc7 100644 --- a/packages/script/src/base.js +++ b/packages/script/src/base.js @@ -255,7 +255,8 @@ }; // Dub Conversions tracking (via direct click ID in URL) - const clickId = params.get(DUB_ID_VAR); + // Drop any visitorId suffix, so this visit gets identified on its own + const clickId = params.get(DUB_ID_VAR)?.split('_')[0]; if (clickId && shouldSetCookie()) { cookieManager.set(DUB_ID_VAR, clickId); } diff --git a/packages/script/src/extensions/identity.test.js b/packages/script/src/extensions/identity.test.js index ecfeef4..1883f4d 100644 --- a/packages/script/src/extensions/identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -237,6 +237,23 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); + it('identifies a ?dub_id= click that carries a visitorId suffix', async () => { + replaceState.call( + window.history, + null, + '', + `/signup?dub_id=${CLICK_ID}_otherVisitorId`, + ); + + runScript({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + + await vi.waitFor(() => { + expect(getCookie('dub_id')).toBe(IDENTIFIED_CLICK_ID); + }); + }); + it('identifies a new ?via= click that replaced an identified dub_id', async () => { document.cookie = 'dub_id=oldClickId_oldVisitorId; path=/'; fetchMock.mockResolvedValue( From 03e2afd10afc5b0a24b214b5964abc737106253b Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 5 Nov 2026 18:10:57 +0530 Subject: [PATCH 28/55] Send the full dub_id in trackLead so the lead is linked to the device --- .../src/extensions/conversion-tracking.js | 4 +-- .../src/extensions/identified-dub-id.test.js | 36 +++++++++---------- packages/web/README.md | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/script/src/extensions/conversion-tracking.js b/packages/script/src/extensions/conversion-tracking.js index c20073c..eca7f2a 100644 --- a/packages/script/src/extensions/conversion-tracking.js +++ b/packages/script/src/extensions/conversion-tracking.js @@ -18,8 +18,8 @@ const initConversionTracking = () => { // Track lead conversion const trackLead = async (input) => { - // Drop the visitorId the identity extension appends to dub_id - const clickId = cookieManager?.get(DUB_ID_VAR)?.split('_')[0]; + // Keep the visitorId the identity extension appends to dub_id, so the lead is linked to the device + const clickId = cookieManager?.get(DUB_ID_VAR); const requestBody = { clickId: clickId ?? '', ...input, diff --git a/packages/script/src/extensions/identified-dub-id.test.js b/packages/script/src/extensions/identified-dub-id.test.js index 35e7fbb..dc331fa 100644 --- a/packages/script/src/extensions/identified-dub-id.test.js +++ b/packages/script/src/extensions/identified-dub-id.test.js @@ -44,25 +44,23 @@ describe('dub_id suffixed by the identity extension', () => { vi.clearAllMocks(); }); - it.each(['trackLead', 'trackSale'])( - '%s sends the bare clickId', - async (method) => { - runScript('conversion-tracking', { - 'data-publishable-key': 'dub_pk_test', - }); - - window.dubAnalytics[method]({ - eventName: 'Sign up', - }); - - await vi.waitFor(() => { - expect(fetchMock).toHaveBeenCalledTimes(1); - }); - expect(JSON.parse(fetchMock.mock.calls[0][1].body).clickId).toBe( - CLICK_ID, - ); - }, - ); + it.each([ + ['trackLead', IDENTIFIED_CLICK_ID], + ['trackSale', CLICK_ID], + ])('%s sends %s as the clickId', async (method, clickId) => { + runScript('conversion-tracking', { + 'data-publishable-key': 'dub_pk_test', + }); + + window.dubAnalytics[method]({ + eventName: 'Sign up', + }); + + await vi.waitFor(() => { + expect(fetchMock).toHaveBeenCalledTimes(1); + }); + expect(JSON.parse(fetchMock.mock.calls[0][1].body).clickId).toBe(clickId); + }); it('decorates outbound links with the bare clickId', () => { document.body.innerHTML = 'Go'; diff --git a/packages/web/README.md b/packages/web/README.md index 7cd18af..1e650ef 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -92,7 +92,7 @@ Identifies the visitor's device on the given paths and links it to their Dub cli A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. -It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. The script strips the suffix before sending the click ID with `trackLead`, `trackSale` or outbound links, but if you read the `dub_id` cookie yourself, use the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. +It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` sends the full value, so Dub can link the lead to the device; pass the cookie as is when you track leads from your server too. The script strips the suffix for `trackSale` and outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. Identification needs Sealed Client Results turned off in the Fingerprint workspace, so the agent returns the visitor ID. From 3a6039afc872be769b446d151e77622fa4382343 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 5 Nov 2026 18:14:12 +0530 Subject: [PATCH 29/55] Suffix dub_id only after Dub accepts or rejects the identification --- packages/script/src/identity-agent.js | 53 ++++++++++++++-------- packages/script/src/identity-agent.test.js | 50 ++++++++++++++++---- 2 files changed, 75 insertions(+), 28 deletions(-) diff --git a/packages/script/src/identity-agent.js b/packages/script/src/identity-agent.js index 708bc59..6c3d76a 100644 --- a/packages/script/src/identity-agent.js +++ b/packages/script/src/identity-agent.js @@ -2,7 +2,7 @@ import { start } from '@fingerprint/agent'; const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; -// Loaded on demand by the identity extension; resolves the visitorId once the device is identified +// Loaded on demand by the identity extension; resolves the visitorId once Dub has accepted or rejected the identification async function identify({ apiHost, clickId }) { if (!FINGERPRINT_PUBLIC_KEY) { return null; @@ -19,27 +19,40 @@ async function identify({ apiHost, clickId }) { return null; } - fetch(`${apiHost}/track/identity`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - eventId, - }), - }) - .then((response) => { - if (!response.ok) { - console.warn( - `[dubAnalytics] trackIdentity failed with status ${response.status}.`, - ); - } - }) - .catch((error) => { - console.warn('[dubAnalytics] trackIdentity failed.', error); + try { + const response = await fetch(`${apiHost}/track/identity`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + eventId, + }), }); - return visitorId; + if (response.ok) { + return visitorId; + } + + console.warn( + `[dubAnalytics] trackIdentity failed with status ${response.status}.`, + ); + + // A 4xx won't succeed on retry, so the click is done; a 5xx or 429 is left for the next page load + if ( + response.status >= 400 && + response.status < 500 && + response.status !== 429 + ) { + return visitorId; + } + + return null; + } catch (error) { + console.warn('[dubAnalytics] trackIdentity failed.', error); + + return null; + } } window._dubIdentity = { diff --git a/packages/script/src/identity-agent.test.js b/packages/script/src/identity-agent.test.js index 5719e37..9b1d405 100644 --- a/packages/script/src/identity-agent.test.js +++ b/packages/script/src/identity-agent.test.js @@ -90,13 +90,30 @@ describe('identity-agent.js', () => { expect(fetchMock).not.toHaveBeenCalled(); }); - it('resolves the visitorId without waiting for the request', async () => { - fetchMock.mockReturnValue(new Promise(() => undefined)); + it('waits for the request before resolving the visitorId', async () => { + let respond = (_response) => undefined; - await expect(identify()).resolves.toBe(VISITOR_ID); + fetchMock.mockReturnValue( + new Promise((resolve) => { + respond = resolve; + }), + ); + + const pending = identify(); + let settled = false; + pending.then(() => { + settled = true; + }); + + await new Promise((resolve) => setTimeout(resolve, 0)); + expect(settled).toBe(false); + + respond(new Response('{}')); + + await expect(pending).resolves.toBe(VISITOR_ID); }); - it('warns when the request is rejected', async () => { + it('resolves the visitorId after a 4xx, since retrying would fail again', async () => { fetchMock.mockResolvedValue( new Response('Bad Request', { status: 400, @@ -105,10 +122,27 @@ describe('identity-agent.js', () => { await expect(identify()).resolves.toBe(VISITOR_ID); - await vi.waitFor(() => { - expect(console.warn).toHaveBeenCalledWith( - '[dubAnalytics] trackIdentity failed with status 400.', + expect(console.warn).toHaveBeenCalledWith( + '[dubAnalytics] trackIdentity failed with status 400.', + ); + }); + + it.each([429, 500, 503])( + 'resolves null after a %i so the next page load retries', + async (status) => { + fetchMock.mockResolvedValue( + new Response('Error', { + status, + }), ); - }); + + await expect(identify()).resolves.toBeNull(); + }, + ); + + it('resolves null when the request fails to send', async () => { + fetchMock.mockRejectedValue(new TypeError('Failed to fetch')); + + await expect(identify()).resolves.toBeNull(); }); }); From 177d09a34564f1b9a010803c00a5bfe317ea4e19 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Thu, 5 Nov 2026 18:22:28 +0530 Subject: [PATCH 30/55] Send the full dub_id in trackSale so a direct sale is linked to the device --- packages/script/src/extensions/conversion-tracking.js | 4 ++-- packages/script/src/extensions/identified-dub-id.test.js | 2 +- packages/web/README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/script/src/extensions/conversion-tracking.js b/packages/script/src/extensions/conversion-tracking.js index eca7f2a..c214ce7 100644 --- a/packages/script/src/extensions/conversion-tracking.js +++ b/packages/script/src/extensions/conversion-tracking.js @@ -45,8 +45,8 @@ const initConversionTracking = () => { // Track sale conversion const trackSale = async (input) => { - // Drop the visitorId the identity extension appends to dub_id - const clickId = cookieManager?.get(DUB_ID_VAR)?.split('_')[0]; + // Keep the visitorId so a sale that creates the customer is linked to the device + const clickId = cookieManager?.get(DUB_ID_VAR); const requestBody = { clickId: clickId ?? '', ...input, diff --git a/packages/script/src/extensions/identified-dub-id.test.js b/packages/script/src/extensions/identified-dub-id.test.js index dc331fa..c0ecdd8 100644 --- a/packages/script/src/extensions/identified-dub-id.test.js +++ b/packages/script/src/extensions/identified-dub-id.test.js @@ -46,7 +46,7 @@ describe('dub_id suffixed by the identity extension', () => { it.each([ ['trackLead', IDENTIFIED_CLICK_ID], - ['trackSale', CLICK_ID], + ['trackSale', IDENTIFIED_CLICK_ID], ])('%s sends %s as the clickId', async (method, clickId) => { runScript('conversion-tracking', { 'data-publishable-key': 'dub_pk_test', diff --git a/packages/web/README.md b/packages/web/README.md index 1e650ef..4d3fab6 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -92,7 +92,7 @@ Identifies the visitor's device on the given paths and links it to their Dub cli A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. -It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` sends the full value, so Dub can link the lead to the device; pass the cookie as is when you track leads from your server too. The script strips the suffix for `trackSale` and outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. +It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` and `trackSale` send the full value, so Dub can link the customer to the device; pass the cookie as is when you track conversions from your server too. The script strips the suffix for outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. Identification needs Sealed Client Results turned off in the Fingerprint workspace, so the agent returns the visitor ID. From e967857edb75ac1accb2bb72363de8db1c5b8c9a Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Thu, 5 Nov 2026 23:48:42 -0800 Subject: [PATCH 31/55] Delete deploy-script.yml --- .github/workflows/deploy-script.yml | 38 ----------------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/deploy-script.yml diff --git a/.github/workflows/deploy-script.yml b/.github/workflows/deploy-script.yml deleted file mode 100644 index 37399a4..0000000 --- a/.github/workflows/deploy-script.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Deploy Analytics Script to Cloudflare Pages - -on: - push: - paths: - - 'packages/script/**' - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Install - uses: ./.github/composite-actions/install - - - name: Install Dependencies and Build - run: pnpm --filter @dub/analytics-script build - env: - DUB_FINGERPRINT_PUBLIC_KEY: ${{ vars.DUB_FINGERPRINT_PUBLIC_KEY }} - - - name: Deploy to Cloudflare Pages - id: cloudflare-deploy - uses: cloudflare/wrangler-action@v3 - with: - apiToken: ${{ secrets.CLOUDFLARE_PAGES_API_KEY }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - command: pages deploy dist --project-name=dub-cdn --commit-dirty=true - workingDirectory: packages/script - packageManager: pnpm - - # Dispatch deployment event to trigger Playwright tests - - name: Dispatch deployment event - uses: peter-evans/repository-dispatch@v3 - with: - event-type: analytics-script-deployed - client-payload: '{"deployment_url": "${{ steps.cloudflare-deploy.outputs.deployment-url }}"}' From 453685f28aa8a694a4199c4036a54a54233356cf Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 6 Nov 2026 16:53:14 +0530 Subject: [PATCH 32/55] Fail the script build when an output is missing or empty --- packages/script/build.js | 19 +++++++++++-- packages/script/verify-outputs.js | 16 +++++++++++ packages/script/verify-outputs.test.js | 39 ++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 packages/script/verify-outputs.js create mode 100644 packages/script/verify-outputs.test.js diff --git a/packages/script/build.js b/packages/script/build.js index 60f183f..52c02bf 100644 --- a/packages/script/build.js +++ b/packages/script/build.js @@ -1,6 +1,7 @@ const esbuild = require('esbuild'); const fs = require('fs'); const path = require('path'); +const { verifyOutputs } = require('./verify-outputs'); const baseConfig = { bundle: true, @@ -32,6 +33,9 @@ const combinations = EXTENSIONS.reduce( [[]], ); +const variantFile = (extensions) => + `dist/analytics/${['script', ...extensions, 'js'].join('.')}`; + // Ensure dist/analytics exists fs.mkdirSync(path.join(__dirname, 'dist/analytics'), { recursive: true }); @@ -54,7 +58,7 @@ Promise.all([ resolveDir: __dirname, sourcefile: extensions.length ? 'combined.js' : 'base.js', }, - outfile: `dist/analytics/${['script', ...extensions, 'js'].join('.')}`, + outfile: variantFile(extensions), }), ), @@ -68,4 +72,15 @@ Promise.all([ }, outfile: 'dist/analytics/identity-agent.js', }), -]).catch(() => process.exit(1)); +]) + .then(() => + verifyOutputs([ + ...combinations.map(variantFile), + 'dist/analytics/identity-agent.js', + 'dist/_redirects', + ]), + ) + .catch((error) => { + console.error(error.message); + process.exit(1); + }); diff --git a/packages/script/verify-outputs.js b/packages/script/verify-outputs.js new file mode 100644 index 0000000..c6d127d --- /dev/null +++ b/packages/script/verify-outputs.js @@ -0,0 +1,16 @@ +const fs = require('fs'); + +// Fails the build when an output is missing or empty, so a broken build never deploys +function verifyOutputs(files) { + const broken = files.filter( + (file) => !fs.existsSync(file) || fs.statSync(file).size === 0, + ); + + if (broken.length) { + throw new Error(`Missing or empty build output: ${broken.join(', ')}`); + } +} + +module.exports = { + verifyOutputs, +}; diff --git a/packages/script/verify-outputs.test.js b/packages/script/verify-outputs.test.js new file mode 100644 index 0000000..e247fd5 --- /dev/null +++ b/packages/script/verify-outputs.test.js @@ -0,0 +1,39 @@ +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { verifyOutputs } from './verify-outputs'; + +let dir; + +describe('verifyOutputs', () => { + beforeEach(() => { + dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dub-script-')); + }); + + afterEach(() => { + fs.rmSync(dir, { + recursive: true, + force: true, + }); + }); + + it('passes when every output exists with content', () => { + const file = path.join(dir, 'script.js'); + fs.writeFileSync(file, '(()=>{})();'); + + expect(() => verifyOutputs([file])).not.toThrow(); + }); + + it('fails and names every missing or empty output', () => { + const built = path.join(dir, 'script.js'); + const empty = path.join(dir, 'script.site-visit.js'); + const missing = path.join(dir, '_redirects'); + fs.writeFileSync(built, '(()=>{})();'); + fs.writeFileSync(empty, ''); + + expect(() => verifyOutputs([built, empty, missing])).toThrow( + `Missing or empty build output: ${empty}, ${missing}`, + ); + }); +}); From 649adf6cd270e4ffccea10419c317b68f17f1e27 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 6 Nov 2026 16:55:02 +0530 Subject: [PATCH 33/55] Fail a Cloudflare production build without the Fingerprint key --- packages/script/build.js | 8 ++++++ packages/script/verify-env.js | 18 ++++++++++++ packages/script/verify-env.test.js | 45 ++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 packages/script/verify-env.js create mode 100644 packages/script/verify-env.test.js diff --git a/packages/script/build.js b/packages/script/build.js index 52c02bf..90820e6 100644 --- a/packages/script/build.js +++ b/packages/script/build.js @@ -1,6 +1,7 @@ const esbuild = require('esbuild'); const fs = require('fs'); const path = require('path'); +const { verifyEnv } = require('./verify-env'); const { verifyOutputs } = require('./verify-outputs'); const baseConfig = { @@ -36,6 +37,13 @@ const combinations = EXTENSIONS.reduce( const variantFile = (extensions) => `dist/analytics/${['script', ...extensions, 'js'].join('.')}`; +try { + verifyEnv(process.env); +} catch (error) { + console.error(error.message); + process.exit(1); +} + // Ensure dist/analytics exists fs.mkdirSync(path.join(__dirname, 'dist/analytics'), { recursive: true }); diff --git a/packages/script/verify-env.js b/packages/script/verify-env.js new file mode 100644 index 0000000..44f3899 --- /dev/null +++ b/packages/script/verify-env.js @@ -0,0 +1,18 @@ +const PRODUCTION_BRANCH = 'main'; + +// Without the key identity-agent.js ships as a no-op, so a Cloudflare production build must have it +function verifyEnv(env) { + if ( + env.CF_PAGES && + env.CF_PAGES_BRANCH === PRODUCTION_BRANCH && + !env.DUB_FINGERPRINT_PUBLIC_KEY + ) { + throw new Error( + 'DUB_FINGERPRINT_PUBLIC_KEY is required for a Cloudflare production build.', + ); + } +} + +module.exports = { + verifyEnv, +}; diff --git a/packages/script/verify-env.test.js b/packages/script/verify-env.test.js new file mode 100644 index 0000000..515b9cf --- /dev/null +++ b/packages/script/verify-env.test.js @@ -0,0 +1,45 @@ +import { describe, expect, it } from 'vitest'; +import { verifyEnv } from './verify-env'; + +const MESSAGE = + 'DUB_FINGERPRINT_PUBLIC_KEY is required for a Cloudflare production build.'; + +describe('verifyEnv', () => { + it('fails a Cloudflare production build without the Fingerprint key', () => { + expect(() => + verifyEnv({ + CF_PAGES: '1', + CF_PAGES_BRANCH: 'main', + }), + ).toThrow(MESSAGE); + + expect(() => + verifyEnv({ + CF_PAGES: '1', + CF_PAGES_BRANCH: 'main', + DUB_FINGERPRINT_PUBLIC_KEY: '', + }), + ).toThrow(MESSAGE); + }); + + it('passes a Cloudflare production build with the key', () => { + expect(() => + verifyEnv({ + CF_PAGES: '1', + CF_PAGES_BRANCH: 'main', + DUB_FINGERPRINT_PUBLIC_KEY: 'key', + }), + ).not.toThrow(); + }); + + it('passes preview and local builds without the key', () => { + expect(() => + verifyEnv({ + CF_PAGES: '1', + CF_PAGES_BRANCH: 'track-identity', + }), + ).not.toThrow(); + + expect(() => verifyEnv({})).not.toThrow(); + }); +}); From 248afa32e4a686e60cdb254be0d57fa86a95340d Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 6 Nov 2026 16:59:59 +0530 Subject: [PATCH 34/55] Send Fingerprint requests through the identity.dub.co subdomain --- packages/script/src/identity-agent.js | 3 +++ packages/script/src/identity-agent.test.js | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/script/src/identity-agent.js b/packages/script/src/identity-agent.js index 6c3d76a..d6810ad 100644 --- a/packages/script/src/identity-agent.js +++ b/packages/script/src/identity-agent.js @@ -1,6 +1,8 @@ import { start } from '@fingerprint/agent'; const FINGERPRINT_PUBLIC_KEY = process.env.DUB_FINGERPRINT_PUBLIC_KEY; +// Dub's Fingerprint custom subdomain, so ad blockers don't stop the agent; Fingerprint's default stays as the fallback +const FINGERPRINT_ENDPOINTS = ['https://identity.dub.co']; // Loaded on demand by the identity extension; resolves the visitorId once Dub has accepted or rejected the identification async function identify({ apiHost, clickId }) { @@ -11,6 +13,7 @@ async function identify({ apiHost, clickId }) { // Needs Sealed Client Results off for the workspace, so visitor_id comes back in plaintext const { visitor_id: visitorId, event_id: eventId } = await start({ apiKey: FINGERPRINT_PUBLIC_KEY, + endpoints: FINGERPRINT_ENDPOINTS, }).get({ linkedId: clickId, }); diff --git a/packages/script/src/identity-agent.test.js b/packages/script/src/identity-agent.test.js index 9b1d405..5882c26 100644 --- a/packages/script/src/identity-agent.test.js +++ b/packages/script/src/identity-agent.test.js @@ -59,6 +59,7 @@ describe('identity-agent.js', () => { expect(start).toHaveBeenCalledWith({ apiKey: 'test_public_key', + endpoints: ['https://identity.dub.co'], }); expect(get).toHaveBeenCalledWith({ linkedId: CLICK_ID, From b0fb56889051d261298452b995e96d5e0bcd9505 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 6 Nov 2026 17:33:15 +0530 Subject: [PATCH 35/55] Remove the verifyEnv test --- packages/script/verify-env.test.js | 45 ------------------------------ 1 file changed, 45 deletions(-) delete mode 100644 packages/script/verify-env.test.js diff --git a/packages/script/verify-env.test.js b/packages/script/verify-env.test.js deleted file mode 100644 index 515b9cf..0000000 --- a/packages/script/verify-env.test.js +++ /dev/null @@ -1,45 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { verifyEnv } from './verify-env'; - -const MESSAGE = - 'DUB_FINGERPRINT_PUBLIC_KEY is required for a Cloudflare production build.'; - -describe('verifyEnv', () => { - it('fails a Cloudflare production build without the Fingerprint key', () => { - expect(() => - verifyEnv({ - CF_PAGES: '1', - CF_PAGES_BRANCH: 'main', - }), - ).toThrow(MESSAGE); - - expect(() => - verifyEnv({ - CF_PAGES: '1', - CF_PAGES_BRANCH: 'main', - DUB_FINGERPRINT_PUBLIC_KEY: '', - }), - ).toThrow(MESSAGE); - }); - - it('passes a Cloudflare production build with the key', () => { - expect(() => - verifyEnv({ - CF_PAGES: '1', - CF_PAGES_BRANCH: 'main', - DUB_FINGERPRINT_PUBLIC_KEY: 'key', - }), - ).not.toThrow(); - }); - - it('passes preview and local builds without the key', () => { - expect(() => - verifyEnv({ - CF_PAGES: '1', - CF_PAGES_BRANCH: 'track-identity', - }), - ).not.toThrow(); - - expect(() => verifyEnv({})).not.toThrow(); - }); -}); From d89e6c96aa1181ad2c4cac3e83964e3cf352bf68 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 6 Nov 2026 17:33:37 +0530 Subject: [PATCH 36/55] Remove the verifyOutputs test --- packages/script/verify-outputs.test.js | 39 -------------------------- 1 file changed, 39 deletions(-) delete mode 100644 packages/script/verify-outputs.test.js diff --git a/packages/script/verify-outputs.test.js b/packages/script/verify-outputs.test.js deleted file mode 100644 index e247fd5..0000000 --- a/packages/script/verify-outputs.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import fs from 'node:fs'; -import os from 'node:os'; -import path from 'node:path'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { verifyOutputs } from './verify-outputs'; - -let dir; - -describe('verifyOutputs', () => { - beforeEach(() => { - dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dub-script-')); - }); - - afterEach(() => { - fs.rmSync(dir, { - recursive: true, - force: true, - }); - }); - - it('passes when every output exists with content', () => { - const file = path.join(dir, 'script.js'); - fs.writeFileSync(file, '(()=>{})();'); - - expect(() => verifyOutputs([file])).not.toThrow(); - }); - - it('fails and names every missing or empty output', () => { - const built = path.join(dir, 'script.js'); - const empty = path.join(dir, 'script.site-visit.js'); - const missing = path.join(dir, '_redirects'); - fs.writeFileSync(built, '(()=>{})();'); - fs.writeFileSync(empty, ''); - - expect(() => verifyOutputs([built, empty, missing])).toThrow( - `Missing or empty build output: ${empty}, ${missing}`, - ); - }); -}); From 7613450a5ec287080186779e1c26865f80f3c201 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 15:02:40 -0500 Subject: [PATCH 37/55] Run Playwright on pull requests against a local script build Deleting deploy-script.yml removed the only trigger for these tests. They now build the script from the commit and serve it on localhost, so a PR is tested before Cloudflare Pages deploys it. --- .github/workflows/playwright.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f8cd356..af111a6 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,8 +1,10 @@ name: Playwright Tests +# Tests the script built from this commit, so a PR is checked before Cloudflare Pages deploys it on: - repository_dispatch: - types: [analytics-script-deployed] + pull_request: + push: + branches: [main] jobs: test: @@ -28,6 +30,13 @@ jobs: - name: Build workspace dependencies run: pnpm --filter @dub/analytics build + - name: Build the analytics script + run: pnpm --filter @dub/analytics-script build + + - name: Serve the analytics script + working-directory: packages/script/dist + run: nohup python3 -m http.server 4000 > /dev/null 2>&1 & + - name: Install Playwright working-directory: apps/nextjs run: pnpm add -D @playwright/test @@ -40,4 +49,4 @@ jobs: working-directory: apps/nextjs run: pnpm exec playwright test --reporter=list env: - DUB_ANALYTICS_SCRIPT_URL: ${{ github.event.client_payload.deployment_url }}/analytics/script.site-visit.outbound-domains.js + DUB_ANALYTICS_SCRIPT_URL: http://localhost:4000/analytics/script.site-visit.outbound-domains.js From c86715d7d20cabd853107e908c4be7024743a2b4 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 15:13:20 -0500 Subject: [PATCH 38/55] Document the consent rule for trackIdentity paths: [] turns off only automatic identification, so a site that needs consent must also wait to call trackIdentity(). --- packages/web/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/web/README.md b/packages/web/README.md index 4d3fab6..aeda3dc 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -102,6 +102,8 @@ Identification needs Sealed Client Results turned off in the Fingerprint workspa To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). +Where the law requires consent for device fingerprinting, use `paths: []` and call `trackIdentity()` only after the visitor gives consent. The script has no consent or opt-out setting of its own. + ```tsx const { trackIdentity } = useAnalytics(); From 76cadd7d4dab568560910efa3ce24a992ee391de Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:10:51 -0500 Subject: [PATCH 39/55] Identify only partner clicks from dub_partner_data Fingerprint identification now needs a dub_partner_data cookie for the same click as dub_id, so ad and site-visit clicks no longer use Fingerprint. --- packages/script/src/extensions/identity.js | 18 ++++ .../script/src/extensions/identity.test.js | 86 +++++++++++++++---- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index 8304731..4e6e678 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -7,6 +7,9 @@ const initIdentity = () => { p: getPendingClick, } = window._dubAnalytics || {}; + // Same name as DUB_PARTNER_COOKIE in base.js + const DUB_PARTNER_COOKIE = 'dub_partner_data'; + const IDENTITY_PATHS = (() => { const identityPaths = script.getAttribute('data-identity-paths'); @@ -67,6 +70,16 @@ const initIdentity = () => { return identityAgent; } + // A ?via= partner click stores its /track/click response, clickId included, in dub_partner_data + function getPartnerClickId() { + try { + return JSON.parse(cookieManager.get(DUB_PARTNER_COOKIE) || 'null') + ?.clickId; + } catch (error) { + return undefined; + } + } + // Links the visitor's device to their click once, then suffixes dub_id with the visitorId async function identifyClick() { await getPendingClick().catch(() => undefined); @@ -78,6 +91,11 @@ const initIdentity = () => { return; } + // Fingerprint is only for partner clicks, so skip ad and site-visit clicks, and clicks newer than the partner data + if (getPartnerClickId() !== clickId) { + return; + } + const identity = await loadIdentityAgent(); const visitorId = await identity.identify({ apiHost: API_HOST, diff --git a/packages/script/src/extensions/identity.test.js b/packages/script/src/extensions/identity.test.js index 1883f4d..e7732f5 100644 --- a/packages/script/src/extensions/identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -60,6 +60,19 @@ function getCookie(name) { .find(([key]) => key === name)?.[1]; } +// A ?via= partner click sets dub_id and dub_partner_data with the same clickId +function setPartnerClick(clickId = CLICK_ID) { + document.cookie = `dub_id=${clickId}; path=/`; + setPartnerData(clickId); +} + +function setPartnerData(clickId = CLICK_ID) { + document.cookie = `dub_partner_data=${JSON.stringify({ + clickId, + partner: { id: 'pn_1', name: 'Partner', image: null }, + })}; path=/`; +} + function flush() { return new Promise((resolve) => { setTimeout(resolve, 0); @@ -113,7 +126,7 @@ describe('identity extension', () => { }); it('loads identity-agent.js next to the script and identifies the click on a matching path', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); runScript({ @@ -140,7 +153,7 @@ describe('identity extension', () => { ['/checkout/plan/pro', ['/checkout/*']], ['/anything', ['/*']], ])('identifies on %s for paths %j', async (pathname, paths) => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', pathname); runScript({ @@ -158,7 +171,7 @@ describe('identity extension', () => { ['/signup-old', ['/signup']], ['/checkouts', ['/checkout/*']], ])('skips %s for paths %j', async (pathname, paths) => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', pathname); runScript({ @@ -170,7 +183,7 @@ describe('identity extension', () => { }); it('is not part of variants without the identity extension', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); runScript( @@ -186,7 +199,7 @@ describe('identity extension', () => { }); it('does nothing without data-identity-paths', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript(); await flush(); @@ -195,7 +208,7 @@ describe('identity extension', () => { }); it('ignores data-identity-paths that is not an array of paths', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); expect(() => @@ -225,6 +238,44 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); + it('skips a dub_id click without dub_partner_data, like an ad or site-visit click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + replaceState.call(window.history, null, '', '/signup'); + + runScript({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + await expect(window.dubAnalytics.trackIdentity()).resolves.toBeUndefined(); + expect(loadedIdentityScripts()).toEqual([]); + expect(getCookie('dub_id')).toBe(CLICK_ID); + }); + + it('skips a newer click when dub_partner_data belongs to another click', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerData('olderClickId'); + replaceState.call(window.history, null, '', '/signup'); + + runScript({ + 'data-identity-paths': JSON.stringify(['/signup']), + }); + await flush(); + + expect(loadedIdentityScripts()).toEqual([]); + }); + + it('skips when dub_partner_data is not valid JSON', async () => { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = 'dub_partner_data=not-json; path=/'; + + runScript(); + + await expect(window.dubAnalytics.trackIdentity()).resolves.toBeUndefined(); + expect(loadedIdentityScripts()).toEqual([]); + }); + it('skips when dub_id is already suffixed with a visitorId', async () => { document.cookie = `dub_id=${IDENTIFIED_CLICK_ID}; path=/`; replaceState.call(window.history, null, '', '/signup'); @@ -238,6 +289,7 @@ describe('identity extension', () => { }); it('identifies a ?dub_id= click that carries a visitorId suffix', async () => { + setPartnerData(); replaceState.call( window.history, null, @@ -260,6 +312,7 @@ describe('identity extension', () => { new Response( JSON.stringify({ clickId: CLICK_ID, + partner: { id: 'pn_1', name: 'Partner', image: null }, }), ), ); @@ -287,7 +340,7 @@ describe('identity extension', () => { document.cookie = 'dub_id=newClickId; path=/'; return VISITOR_ID; }); - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript(); await window.dubAnalytics.trackIdentity(); @@ -318,6 +371,7 @@ describe('identity extension', () => { new Response( JSON.stringify({ clickId: CLICK_ID, + partner: { id: 'pn_1', name: 'Partner', image: null }, }), ), ); @@ -333,7 +387,7 @@ describe('identity extension', () => { it('keeps dub_id unchanged when identification fails', async () => { identify.mockResolvedValue(null); - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); runScript({ @@ -354,7 +408,7 @@ describe('identity extension', () => { setTimeout(() => node.onerror()); return node; }); - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript(); @@ -363,7 +417,7 @@ describe('identity extension', () => { }); it('identifies after a client-side navigation to a matching path', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript({ 'data-identity-paths': JSON.stringify(['/signup']), @@ -380,7 +434,7 @@ describe('identity extension', () => { }); it('identifies when going back to a matching path', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript({ 'data-identity-paths': JSON.stringify(['/signup']), @@ -396,7 +450,7 @@ describe('identity extension', () => { }); it('ignores history updates that keep the same path', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); runScript({ @@ -407,7 +461,7 @@ describe('identity extension', () => { }); clearCookies(); - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); window.history.replaceState(null, '', '/signup?step=2'); await flush(); @@ -415,7 +469,7 @@ describe('identity extension', () => { }); it('exposes trackIdentity on window.dubAnalytics without paths', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript(); await window.dubAnalytics.trackIdentity(); @@ -425,7 +479,7 @@ describe('identity extension', () => { }); it('runs a trackIdentity call queued before the script loaded', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); window.dubAnalytics('trackIdentity'); runScript(); @@ -436,7 +490,7 @@ describe('identity extension', () => { }); it('shares one identification between concurrent calls', async () => { - document.cookie = `dub_id=${CLICK_ID}; path=/`; + setPartnerClick(); runScript(); await Promise.all([ From 5151467ebc5606bf61bdfc6ffb35032597abc7ac Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:10:52 -0500 Subject: [PATCH 40/55] Document that trackIdentity needs a ?via= partner click --- packages/web/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/web/README.md b/packages/web/README.md index aeda3dc..ff08091 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -92,7 +92,9 @@ Identifies the visitor's device on the given paths and links it to their Dub cli A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. -It only runs for visitors with a `dub_id` cookie, once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` and `trackSale` send the full value, so Dub can link the customer to the device; pass the cookie as is when you track conversions from your server too. The script strips the suffix for outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. +It only runs for partner clicks tracked with `?via=` (so set `domainsConfig.refer`). That click sets the `dub_partner_data` cookie, and the script identifies only while that cookie belongs to the click in `dub_id`. Ad and site-visit clicks are skipped, so they never use Fingerprint. + +It runs once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` and `trackSale` send the full value, so Dub can link the customer to the device; pass the cookie as is when you track conversions from your server too. The script strips the suffix for outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. Identification needs Sealed Client Results turned off in the Fingerprint workspace, so the agent returns the visitor ID. From 20fb32f61ec0f6c92102d7ac43993253f2696c5c Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:40:57 -0500 Subject: [PATCH 41/55] Suffix dub_id in the scope where the click cookie was set A click on example.com and a signup on app.example.com left a bare dub_id on the parent domain. The script then read the bare value, so it called Fingerprint on every visit and conversions lost the visitorId. It now writes each domain level, most specific first, until no bare copy is left. --- packages/script/src/base.js | 5 +- .../extensions/identity-cookie-scope.test.js | 108 ++++++++++++++++++ packages/script/src/extensions/identity.js | 33 +++++- 3 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 packages/script/src/extensions/identity-cookie-scope.test.js diff --git a/packages/script/src/base.js b/packages/script/src/base.js index c215bc7..0dd4085 100644 --- a/packages/script/src/base.js +++ b/packages/script/src/base.js @@ -147,8 +147,9 @@ .find(([k]) => k === key)?.[1]; }, - set(key, value) { - const cookieString = Object.entries(COOKIE_OPTIONS) + // options override COOKIE_OPTIONS for this write, and a falsy value drops that attribute + set(key, value, options = {}) { + const cookieString = Object.entries({ ...COOKIE_OPTIONS, ...options }) .filter(([, v]) => v) .map(([k, v]) => `${k}=${v}`) .join('; '); diff --git a/packages/script/src/extensions/identity-cookie-scope.test.js b/packages/script/src/extensions/identity-cookie-scope.test.js new file mode 100644 index 0000000..7bf86be --- /dev/null +++ b/packages/script/src/extensions/identity-cookie-scope.test.js @@ -0,0 +1,108 @@ +// @vitest-environment-options {"url": "https://app.example.com/signup"} +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +const SOURCE = [ + readFileSync(join(__dirname, '../base.js'), 'utf8'), + readFileSync(join(__dirname, 'identity.js'), 'utf8'), +].join('\n'); +const CLICK_ID = 'kVrpHmuNu8Q9VpBG'; +const VISITOR_ID = 'Uxk0Swb1Ofgfq2Jcg1cV'; +const IDENTIFIED_CLICK_ID = `${CLICK_ID}_${VISITOR_ID}`; +const identify = vi.fn(); + +function runScript() { + const script = document.createElement('script'); + script.src = 'https://www.dubcdn.com/analytics/script.identity.js'; + + Object.defineProperty(document, 'currentScript', { + configurable: true, + get: () => script, + }); + + new Function(SOURCE)(); +} + +function stubDubAnalytics() { + window.dubAnalytics = function () { + (window.dubAnalytics.q = window.dubAnalytics.q || []).push(arguments); + }; +} + +// A ?via= partner click on the given domain sets dub_id and dub_partner_data there +function setPartnerClick(domain) { + document.cookie = `dub_id=${CLICK_ID}; path=/; domain=${domain}`; + document.cookie = `dub_partner_data=${JSON.stringify({ + clickId: CLICK_ID, + partner: { id: 'pn_1', name: 'Partner', image: null }, + })}; path=/; domain=${domain}`; +} + +function dubIdValues() { + return document.cookie + .split(';') + .map((cookie) => cookie.trim().split('=')) + .filter(([name]) => name === 'dub_id') + .map(([, value]) => value); +} + +function clearCookies() { + ['', '; domain=.app.example.com', '; domain=.example.com'].forEach( + (scope) => { + ['dub_id', 'dub_partner_data'].forEach((name) => { + document.cookie = `${name}=; path=/; max-age=0${scope}`; + }); + }, + ); +} + +describe('identity extension cookie scope', () => { + beforeEach(() => { + clearCookies(); + stubDubAnalytics(); + identify.mockResolvedValue(VISITOR_ID); + + vi.spyOn(document.head, 'appendChild').mockImplementation((node) => { + window._dubIdentity = { identify }; + setTimeout(() => node.onload()); + return node; + }); + }); + + afterEach(() => { + clearCookies(); + delete window._dubIdentity; + vi.restoreAllMocks(); + vi.clearAllMocks(); + }); + + it('suffixes a dub_id set on the parent domain, so no bare copy is left', async () => { + setPartnerClick('.example.com'); + + runScript(); + await window.dubAnalytics.trackIdentity(); + + expect(dubIdValues()).not.toContain(CLICK_ID); + expect(window._dubAnalytics.c.get('dub_id')).toBe(IDENTIFIED_CLICK_ID); + }); + + it('identifies a parent domain click only once', async () => { + setPartnerClick('.example.com'); + + runScript(); + await window.dubAnalytics.trackIdentity(); + await window.dubAnalytics.trackIdentity(); + + expect(identify).toHaveBeenCalledTimes(1); + }); + + it('keeps a dub_id set on this subdomain to one cookie', async () => { + setPartnerClick('.app.example.com'); + + runScript(); + await window.dubAnalytics.trackIdentity(); + + expect(dubIdValues()).toEqual([IDENTIFIED_CLICK_ID]); + }); +}); diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index 4e6e678..a21cd9f 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -3,6 +3,7 @@ const initIdentity = () => { a: API_HOST, c: cookieManager, i: DUB_ID_VAR, + h: HOSTNAME, s: script, p: getPendingClick, } = window._dubAnalytics || {}; @@ -80,6 +81,36 @@ const initIdentity = () => { } } + // The cookie domains this page can write, most specific first: host-only, .app.example.com, .example.com + function cookieDomains() { + const parts = HOSTNAME.split('.'); + + return [ + undefined, + ...parts.slice(0, -1).map((_, i) => `.${parts.slice(i).join('.')}`), + ]; + } + + function hasCookie(name, value) { + return document.cookie + .split(';') + .some((cookie) => cookie.trim() === `${name}=${value}`); + } + + // dub_id can come from a parent domain, for a click on example.com and a signup on app.example.com. + // So also write each domain level until no bare copy is left, and stop there to keep the original scope. + function setIdentifiedClickId(clickId, visitorId) { + const identifiedClickId = `${clickId}_${visitorId}`; + + cookieManager.set(DUB_ID_VAR, identifiedClickId); + + for (const domain of cookieDomains()) { + if (!hasCookie(DUB_ID_VAR, clickId)) return; + + cookieManager.set(DUB_ID_VAR, identifiedClickId, { domain }); + } + } + // Links the visitor's device to their click once, then suffixes dub_id with the visitorId async function identifyClick() { await getPendingClick().catch(() => undefined); @@ -104,7 +135,7 @@ const initIdentity = () => { // Skip when a new click replaced dub_id while identifying if (visitorId && cookieManager.get(DUB_ID_VAR) === clickId) { - cookieManager.set(DUB_ID_VAR, `${clickId}_${visitorId}`); + setIdentifiedClickId(clickId, visitorId); } } From 7be07dd3e5e059ed1f437eb43f3351c0efdaf20a Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:40:57 -0500 Subject: [PATCH 42/55] Document that a pending trackIdentity call can't be canceled --- packages/web/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web/README.md b/packages/web/README.md index ff08091..62d78b5 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -104,7 +104,7 @@ Identification needs Sealed Client Results turned off in the Fingerprint workspa To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). -Where the law requires consent for device fingerprinting, use `paths: []` and call `trackIdentity()` only after the visitor gives consent. The script has no consent or opt-out setting of its own. +Where the law requires consent for device fingerprinting, use `paths: []` and call `trackIdentity()` only after the visitor gives consent. The script has no consent or opt-out setting of its own. A call first waits for a pending `?via=` click, and it can't be canceled, so identification can still start if consent is withdrawn during that wait. ```tsx const { trackIdentity } = useAnalytics(); From 929a45439f7ca6935cf33eaf9e825c011be7ba15 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:47:09 -0500 Subject: [PATCH 43/55] Start the dub_id suffix write at the host-only scope The first write used the default cookie domain, which is .example.com on www.example.com, so a host-only dub_id got a parent-domain copy. The write now starts at host-only and widens only while a bare copy is left. --- .../extensions/identity-cookie-scope.test.js | 24 +++++++++++++++++++ packages/script/src/extensions/identity.js | 5 ++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/script/src/extensions/identity-cookie-scope.test.js b/packages/script/src/extensions/identity-cookie-scope.test.js index 7bf86be..29e7701 100644 --- a/packages/script/src/extensions/identity-cookie-scope.test.js +++ b/packages/script/src/extensions/identity-cookie-scope.test.js @@ -97,6 +97,30 @@ describe('identity extension cookie scope', () => { expect(identify).toHaveBeenCalledTimes(1); }); + it('keeps a host-only dub_id on www to one cookie, with no parent-domain copy', async () => { + // eslint-disable-next-line no-undef + jsdom.reconfigure({ url: 'https://www.example.com/signup' }); + + try { + document.cookie = `dub_id=${CLICK_ID}; path=/`; + document.cookie = `dub_partner_data=${JSON.stringify({ + clickId: CLICK_ID, + partner: { id: 'pn_1', name: 'Partner', image: null }, + })}; path=/`; + + runScript(); + await window.dubAnalytics.trackIdentity(); + + expect(dubIdValues()).toEqual([IDENTIFIED_CLICK_ID]); + } finally { + ['dub_id', 'dub_partner_data'].forEach((name) => { + document.cookie = `${name}=; path=/; max-age=0`; + }); + // eslint-disable-next-line no-undef + jsdom.reconfigure({ url: 'https://app.example.com/signup' }); + } + }); + it('keeps a dub_id set on this subdomain to one cookie', async () => { setPartnerClick('.app.example.com'); diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index a21cd9f..630eab7 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -98,12 +98,11 @@ const initIdentity = () => { } // dub_id can come from a parent domain, for a click on example.com and a signup on app.example.com. - // So also write each domain level until no bare copy is left, and stop there to keep the original scope. + // So write each domain level, most specific first, and stop when no bare copy is left to keep the original scope. + // The default COOKIE_OPTIONS domain is not used here, because on www.example.com it is .example.com. function setIdentifiedClickId(clickId, visitorId) { const identifiedClickId = `${clickId}_${visitorId}`; - cookieManager.set(DUB_ID_VAR, identifiedClickId); - for (const domain of cookieDomains()) { if (!hasCookie(DUB_ID_VAR, clickId)) return; From 8140358fd891dcfd18d90a21b0b42e717fb35337 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 16:59:49 -0500 Subject: [PATCH 44/55] Run the analytics script unit tests in CI --- .github/workflows/playwright.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index af111a6..16ff0e2 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -33,6 +33,9 @@ jobs: - name: Build the analytics script run: pnpm --filter @dub/analytics-script build + - name: Run the analytics script unit tests + run: pnpm --filter @dub/analytics-script test + - name: Serve the analytics script working-directory: packages/script/dist run: nohup python3 -m http.server 4000 > /dev/null 2>&1 & From ab0e29e8692ea0dc99d0dbbf389b2aed1cbf79a6 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:01:13 -0500 Subject: [PATCH 45/55] Add a Playwright spec for the identity variant It loads script.identity.js from the CI build on a test origin with a stubbed agent, and checks that a ?via= partner click gets the visitorId suffix and a click without partner data never loads the agent. --- apps/nextjs/tests/identity.spec.ts | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 apps/nextjs/tests/identity.spec.ts diff --git a/apps/nextjs/tests/identity.spec.ts b/apps/nextjs/tests/identity.spec.ts new file mode 100644 index 0000000..af07807 --- /dev/null +++ b/apps/nextjs/tests/identity.spec.ts @@ -0,0 +1,102 @@ +import { DUB_ANALYTICS_SCRIPT_URL } from '@/app/constants'; +import { expect, test, type Page } from '@playwright/test'; + +// The identity variant from the same build as the other specs +const IDENTITY_SCRIPT_URL = DUB_ANALYTICS_SCRIPT_URL.replace( + /script[^/]*\.js$/, + 'script.identity.js', +); +const SITE = 'http://identity.test'; +const CLICK_ID = 'idE2EClick01'; +const VISITOR_ID = 'idE2EVisitor01'; + +// Serves a page on a test origin that loads the identity variant for /signup +async function serveSite(page: Page) { + await page.route(`${SITE}/**`, (route) => + route.fulfill({ + contentType: 'text/html', + body: ` + + + + + + Identity test + `, + }), + ); +} + +// Stubs the Fingerprint agent, so the spec checks the script without calling Fingerprint or Dub +async function stubIdentityAgent(page: Page) { + const agentRequests: string[] = []; + + await page.route('**/analytics/identity-agent.js', (route) => { + agentRequests.push(route.request().url()); + + return route.fulfill({ + contentType: 'application/javascript', + body: `window._dubIdentity = { identify: async () => '${VISITOR_ID}' };`, + }); + }); + + return agentRequests; +} + +async function getDubId(page: Page) { + const cookies = await page.context().cookies(SITE); + + return cookies.find((cookie) => cookie.name === 'dub_id')?.value; +} + +test.describe('Identity tracking', () => { + test('identifies a ?via= partner click on a matching path', async ({ + page, + }) => { + await serveSite(page); + const agentRequests = await stubIdentityAgent(page); + + await page.route('**/track/click', (route) => + route.fulfill({ + contentType: 'application/json', + body: JSON.stringify({ + clickId: CLICK_ID, + partner: { id: 'pn_e2e', name: 'Partner', image: null }, + discount: null, + }), + }), + ); + + await page.goto(`${SITE}/signup?via=partner`); + + await expect.poll(() => getDubId(page)).toBe(`${CLICK_ID}_${VISITOR_ID}`); + expect(agentRequests).toHaveLength(1); + }); + + test('never loads the agent for a click without partner data', async ({ + page, + }) => { + await serveSite(page); + const agentRequests = await stubIdentityAgent(page); + + await page.goto(`${SITE}/signup?dub_id=${CLICK_ID}`); + await expect.poll(() => getDubId(page)).toBe(CLICK_ID); + + await page.evaluate(() => (window as any).dubAnalytics.trackIdentity()); + + expect(agentRequests).toHaveLength(0); + expect(await getDubId(page)).toBe(CLICK_ID); + }); +}); From 65fa0b6ed960f3f30e0b2de7008f802f247b33b6 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:01:23 -0500 Subject: [PATCH 46/55] Say in the trackIdentity JSDoc that it needs a ?via= partner click --- packages/web/src/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 8d21a78..4a585d9 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -156,8 +156,8 @@ export interface AnalyticsProps { /** * Identify the visitor's device on these paths and link it to their Dub click, for partner - * risk monitoring. Only runs for visitors with a `dub_id` cookie. - * Paths match exactly; a trailing `/*` also matches everything under the path (e.g. `/checkout/*`). + * risk monitoring. Only runs for partner clicks tracked with `?via=`, so set `domainsConfig.refer`. + * Paths match exactly. A trailing `/*` also matches everything under the path (e.g. `/checkout/*`). */ trackIdentity?: { paths: string[]; From 7fdee976ac0619a8de39dcbb4deb474f425850b5 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:02:31 -0500 Subject: [PATCH 47/55] Share the partner cookie name from base.js with the identity extension --- packages/script/src/base.js | 1 + packages/script/src/extensions/identity.js | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/script/src/base.js b/packages/script/src/base.js index 0dd4085..e7c4a7e 100644 --- a/packages/script/src/base.js +++ b/packages/script/src/base.js @@ -293,6 +293,7 @@ c: cookieManager, qm: queueManager, i: DUB_ID_VAR, + pc: DUB_PARTNER_COOKIE, h: HOSTNAME, a: API_HOST, d: SHORT_DOMAIN, diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index 630eab7..7fb076c 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -3,14 +3,12 @@ const initIdentity = () => { a: API_HOST, c: cookieManager, i: DUB_ID_VAR, + pc: DUB_PARTNER_COOKIE, h: HOSTNAME, s: script, p: getPendingClick, } = window._dubAnalytics || {}; - // Same name as DUB_PARTNER_COOKIE in base.js - const DUB_PARTNER_COOKIE = 'dub_partner_data'; - const IDENTITY_PATHS = (() => { const identityPaths = script.getAttribute('data-identity-paths'); From b534978b68bc6c6b823c064d25f05d9631a03d6a Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:03:12 -0500 Subject: [PATCH 48/55] Wait for the script server before the Playwright tests --- .github/workflows/playwright.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 16ff0e2..8bf0372 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -38,7 +38,9 @@ jobs: - name: Serve the analytics script working-directory: packages/script/dist - run: nohup python3 -m http.server 4000 > /dev/null 2>&1 & + run: | + nohup python3 -m http.server 4000 > /dev/null 2>&1 & + curl --silent --fail --retry 10 --retry-connrefused --retry-delay 1 --output /dev/null http://localhost:4000/analytics/script.js - name: Install Playwright working-directory: apps/nextjs From d2dbd4c5904ddef7918a003a3af5b46e31328c13 Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:03:23 -0500 Subject: [PATCH 49/55] Remove the Playwright install step that pnpm install already covers --- .github/workflows/playwright.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 8bf0372..74de9cd 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -42,10 +42,6 @@ jobs: nohup python3 -m http.server 4000 > /dev/null 2>&1 & curl --silent --fail --retry 10 --retry-connrefused --retry-delay 1 --output /dev/null http://localhost:4000/analytics/script.js - - name: Install Playwright - working-directory: apps/nextjs - run: pnpm add -D @playwright/test - - name: Install Playwright Browsers working-directory: apps/nextjs run: pnpm exec playwright install chromium --with-deps From a8c60da575f77c1f7f9189697891df37a0d2ff6b Mon Sep 17 00:00:00 2001 From: Rafi Date: Fri, 6 Nov 2026 17:08:01 -0500 Subject: [PATCH 50/55] Serve the script from the test origin in the identity spec Newer Chromium blocks a public origin from loading a script from localhost, so CI with Playwright 1.65 never ran the script. The spec now fetches the build and serves it from identity.test. --- apps/nextjs/tests/identity.spec.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/nextjs/tests/identity.spec.ts b/apps/nextjs/tests/identity.spec.ts index af07807..cd0b2d3 100644 --- a/apps/nextjs/tests/identity.spec.ts +++ b/apps/nextjs/tests/identity.spec.ts @@ -1,11 +1,8 @@ import { DUB_ANALYTICS_SCRIPT_URL } from '@/app/constants'; import { expect, test, type Page } from '@playwright/test'; -// The identity variant from the same build as the other specs -const IDENTITY_SCRIPT_URL = DUB_ANALYTICS_SCRIPT_URL.replace( - /script[^/]*\.js$/, - 'script.identity.js', -); +// The folder of the build the other specs use +const BUILD_URL = DUB_ANALYTICS_SCRIPT_URL.replace(/script[^/]*\.js$/, ''); const SITE = 'http://identity.test'; const CLICK_ID = 'idE2EClick01'; const VISITOR_ID = 'idE2EVisitor01'; @@ -27,7 +24,7 @@ async function serveSite(page: Page) { })(window, 'dubAnalytics'); Identity test diff --git a/packages/script/src/extensions/identity.js b/packages/script/src/extensions/identity.js index 7fb076c..a1cdf66 100644 --- a/packages/script/src/extensions/identity.js +++ b/packages/script/src/extensions/identity.js @@ -10,7 +10,7 @@ const initIdentity = () => { } = window._dubAnalytics || {}; const IDENTITY_PATHS = (() => { - const identityPaths = script.getAttribute('data-identity-paths'); + const identityPaths = script.getAttribute('data-track-identity-paths'); if (!identityPaths) return []; @@ -22,7 +22,7 @@ const initIdentity = () => { : []; } catch (error) { console.warn( - '[dubAnalytics] Failed to parse data-identity-paths.', + '[dubAnalytics] Failed to parse data-track-identity-paths.', error, ); return []; diff --git a/packages/script/src/extensions/identity.test.js b/packages/script/src/extensions/identity.test.js index e7732f5..a13c754 100644 --- a/packages/script/src/extensions/identity.test.js +++ b/packages/script/src/extensions/identity.test.js @@ -131,7 +131,7 @@ describe('identity extension', () => { runScript({ 'data-api-host': 'https://api.example.com', - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { @@ -157,7 +157,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', pathname); runScript({ - 'data-identity-paths': JSON.stringify(paths), + 'data-track-identity-paths': JSON.stringify(paths), }); await vi.waitFor(() => { @@ -175,7 +175,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', pathname); runScript({ - 'data-identity-paths': JSON.stringify(paths), + 'data-track-identity-paths': JSON.stringify(paths), }); await flush(); @@ -188,7 +188,7 @@ describe('identity extension', () => { runScript( { - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }, BASE_SOURCE, ); @@ -198,7 +198,7 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); - it('does nothing without data-identity-paths', async () => { + it('does nothing without data-track-identity-paths', async () => { setPartnerClick(); runScript(); @@ -207,18 +207,18 @@ describe('identity extension', () => { expect(loadedIdentityScripts()).toEqual([]); }); - it('ignores data-identity-paths that is not an array of paths', async () => { + it('ignores data-track-identity-paths that is not an array of paths', async () => { setPartnerClick(); replaceState.call(window.history, null, '', '/signup'); expect(() => runScript({ - 'data-identity-paths': JSON.stringify('/signup'), + 'data-track-identity-paths': JSON.stringify('/signup'), }), ).not.toThrow(); expect(() => runScript({ - 'data-identity-paths': JSON.stringify([42, '/signup']), + 'data-track-identity-paths': JSON.stringify([42, '/signup']), }), ).not.toThrow(); @@ -231,7 +231,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -243,7 +243,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -259,7 +259,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -281,7 +281,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -298,7 +298,7 @@ describe('identity extension', () => { ); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { @@ -322,7 +322,7 @@ describe('identity extension', () => { 'data-domains': JSON.stringify({ refer: 'dub.sh', }), - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { @@ -361,7 +361,7 @@ describe('identity extension', () => { 'data-domains': JSON.stringify({ refer: 'dub.sh', }), - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -391,7 +391,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { @@ -420,7 +420,7 @@ describe('identity extension', () => { setPartnerClick(); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -437,7 +437,7 @@ describe('identity extension', () => { setPartnerClick(); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await flush(); @@ -454,7 +454,7 @@ describe('identity extension', () => { replaceState.call(window.history, null, '', '/signup'); runScript({ - 'data-identity-paths': JSON.stringify(['/signup']), + 'data-track-identity-paths': JSON.stringify(['/signup']), }); await vi.waitFor(() => { expect(identify).toHaveBeenCalledTimes(1); From 92b5af5e5f181db6622cd26d4462dc6589747bcd Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 9 Nov 2026 15:34:01 -0500 Subject: [PATCH 52/55] Replace the trackIdentity prop object with a trackIdentityPaths array --- packages/web/src/generic.ts | 8 ++++---- packages/web/src/types.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/web/src/generic.ts b/packages/web/src/generic.ts index 90a2422..b096091 100644 --- a/packages/web/src/generic.ts +++ b/packages/web/src/generic.ts @@ -35,7 +35,7 @@ function inject(props: AnalyticsProps): void { if (props.domainsConfig?.site) features.push('site-visit'); if (props.domainsConfig?.outbound) features.push('outbound-domains'); if (props.publishableKey) features.push('conversion-tracking'); - if (props.trackIdentity) features.push('identity'); + if (props.trackIdentityPaths) features.push('identity'); const src = props.scriptProps?.src || @@ -86,10 +86,10 @@ function inject(props: AnalyticsProps): void { script.setAttribute('data-query-params', JSON.stringify(props.queryParams)); } - if (props.trackIdentity) { + if (props.trackIdentityPaths) { script.setAttribute( - 'data-identity-paths', - JSON.stringify(props.trackIdentity.paths), + 'data-track-identity-paths', + JSON.stringify(props.trackIdentityPaths), ); } diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index 4a585d9..d477654 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -158,10 +158,9 @@ export interface AnalyticsProps { * Identify the visitor's device on these paths and link it to their Dub click, for partner * risk monitoring. Only runs for partner clicks tracked with `?via=`, so set `domainsConfig.refer`. * Paths match exactly. A trailing `/*` also matches everything under the path (e.g. `/checkout/*`). + * An empty list loads the identity variant without automatic identification, for `trackIdentity()` calls. */ - trackIdentity?: { - paths: string[]; - }; + trackIdentityPaths?: string[]; /** * Custom properties to pass to the script. From 407a3e28fa4a2a8dd7630042d86f6db1c1dee601 Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 9 Nov 2026 15:34:01 -0500 Subject: [PATCH 53/55] Document trackIdentityPaths and data-track-identity-paths --- packages/web/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index 62d78b5..ee8e648 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -86,7 +86,7 @@ import { Analytics as DubAnalytics } from "@dub/analytics" The query parameter to listen to for client-side click-tracking (e.g. `?via=john`, `?ref=jane`). The default is `via`. -### `trackIdentity` +### `trackIdentityPaths` Identifies the visitor's device on the given paths and links it to their Dub click, for partner risk monitoring. @@ -99,12 +99,12 @@ It runs once per click: after identifying, it appends the device's visitor ID to Identification needs Sealed Client Results turned off in the Fingerprint workspace, so the agent returns the visitor ID. ```tsx - + ``` -To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` rules, and needs the `trackIdentity` prop to load the identity variant (`paths: []` turns off automatic identification). +To identify conditionally instead, call `trackIdentity` yourself. It follows the same `dub_id` rules, and needs the `trackIdentityPaths` prop to load the identity variant (`trackIdentityPaths={[]}` turns off automatic identification). -Where the law requires consent for device fingerprinting, use `paths: []` and call `trackIdentity()` only after the visitor gives consent. The script has no consent or opt-out setting of its own. A call first waits for a pending `?via=` click, and it can't be canceled, so identification can still start if consent is withdrawn during that wait. +Where the law requires consent for device fingerprinting, use `trackIdentityPaths={[]}` and call `trackIdentity()` only after the visitor gives consent. The script has no consent or opt-out setting of its own. A call first waits for a pending `?via=` click, and it can't be canceled, so identification can still start if consent is withdrawn during that wait. ```tsx const { trackIdentity } = useAnalytics(); @@ -112,12 +112,12 @@ const { trackIdentity } = useAnalytics(); await trackIdentity(); ``` -Without React, use the `identity` script variant (`script.identity.js`, or combined like `script.site-visit.identity.js`). Set the paths with a `data-identity-paths` attribute, and call `dubAnalytics.trackIdentity()`. To queue calls made before the script loads, add `trackIdentity` to the snippet's method list. +Without React, use the `identity` script variant (`script.identity.js`, or combined like `script.site-visit.identity.js`). Set the paths with a `data-track-identity-paths` attribute, and call `dubAnalytics.trackIdentity()`. To queue calls made before the script loads, add `trackIdentity` to the snippet's method list. ```html ``` From 816ce5ff620bed18314a5a43f8218eadc1ec3518 Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 9 Nov 2026 16:12:15 -0500 Subject: [PATCH 54/55] Limit the Playwright workflow token to read access --- .github/workflows/playwright.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 74de9cd..aec4d09 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -6,6 +6,9 @@ on: push: branches: [main] +permissions: + contents: read + jobs: test: timeout-minutes: 60 From 696ad5ac33955213cbc1a63f37824f6789c8ee4a Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 9 Nov 2026 16:12:24 -0500 Subject: [PATCH 55/55] Say that trackIdentityPaths works with any client-side partner query param --- packages/web/README.md | 2 +- packages/web/src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web/README.md b/packages/web/README.md index ee8e648..d91890c 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -92,7 +92,7 @@ Identifies the visitor's device on the given paths and links it to their Dub cli A path matches exactly (a trailing slash is ignored). A trailing `/*` also matches everything under the path, so `/checkout/*` matches `/checkout` and `/checkout/plan`. It runs on the first page load and on client-side navigation to a matching path. -It only runs for partner clicks tracked with `?via=` (so set `domainsConfig.refer`). That click sets the `dub_partner_data` cookie, and the script identifies only while that cookie belongs to the click in `dub_id`. Ad and site-visit clicks are skipped, so they never use Fingerprint. +It only runs for client-side partner clicks, tracked with `?via=` or the parameter you set in `queryParam` (so set `domainsConfig.refer`). That click sets the `dub_partner_data` cookie, and the script identifies only while that cookie belongs to the click in `dub_id`. Ad and site-visit clicks are skipped, so they never use Fingerprint. It runs once per click: after identifying, it appends the device's visitor ID to the cookie (`dub_id=_`). A new click replaces the cookie and gets identified again. `trackLead` and `trackSale` send the full value, so Dub can link the customer to the device; pass the cookie as is when you track conversions from your server too. The script strips the suffix for outbound links, and anywhere else you read the `dub_id` cookie yourself, the click ID is the part before `_`. The device identification agent is loaded only when identification runs, and failures never throw or block the page. diff --git a/packages/web/src/types.ts b/packages/web/src/types.ts index d477654..6fa13ad 100644 --- a/packages/web/src/types.ts +++ b/packages/web/src/types.ts @@ -156,7 +156,7 @@ export interface AnalyticsProps { /** * Identify the visitor's device on these paths and link it to their Dub click, for partner - * risk monitoring. Only runs for partner clicks tracked with `?via=`, so set `domainsConfig.refer`. + * risk monitoring. Only runs for client-side partner clicks (`?via=` or your `queryParam`), so set `domainsConfig.refer`. * Paths match exactly. A trailing `/*` also matches everything under the path (e.g. `/checkout/*`). * An empty list loads the identity variant without automatic identification, for `trackIdentity()` calls. */