Skip to content

feat(audience): add @imtbl/audience-web-sdk#2818

Closed
ImmutableJeffrey wants to merge 19 commits into
mainfrom
feat/audience-web-sdk
Closed

feat(audience): add @imtbl/audience-web-sdk#2818
ImmutableJeffrey wants to merge 19 commits into
mainfrom
feat/audience-web-sdk

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor

Summary

Audience web SDK (packages/audience/web/) — explicit, typed, consent-aware event tracking and identity management for studio web surfaces. Sits alongside the pixel (same cookies, same backend, different surface discriminator).

  • ImmutableWebSDK class: init, page, track (typed + custom), identify (known + anonymous), alias, setConsent, reset, flush, shutdown
  • Wire format matches backend OAS exactly (eventTimestamp, eventName, identityType, fromId/fromType/toId/toType)
  • Three-tier consent (none/anonymous/full) with server sync via PUT/GET tracking-consent, DNT/GPC enforcement
  • SPA route detection (pushState/replaceState patching, 100ms dedup)
  • Attribution parsing (UTMs, click IDs, sessionStorage persistence)
  • CDN bundle (4.0 KB gzipped IIFE, window.ImmutableWebSDK)
  • Client-side validation (timestamp range, alias identity, maxLength truncation)
  • Demo page for end-to-end testing against local/dev/sandbox

Also includes @imtbl/audience shared SDK with backend-aligned wire format (eventTimestamp, eventName, identityType, fromId/fromType/toId/toType, surface field).

Stats

  • 120 tests (82 web + 38 shared SDK)
  • 3.6 KB gzipped (npm ESM) / 4.0 KB gzipped (CDN IIFE)
  • 4 rounds of code review, 17 findings fixed

Test plan

  • cd packages/audience/web && pnpm test — 82 tests pass
  • cd packages/audience/sdk && pnpm test — 38 tests pass
  • cd packages/audience/web && pnpm build — ESM + CJS + CDN bundles produced
  • cd packages/audience/web && pnpm typecheck — clean
  • Demo page: pnpm demo → select dev environment → fire events → verify in Network tab

🤖 Generated with Claude Code

@ImmutableJeffrey ImmutableJeffrey requested review from a team as code owners April 4, 2026 03:51
@ImmutableJeffrey ImmutableJeffrey changed the title feat: add @imtbl/audience-web-sdk feat(audience): add @imtbl/audience-web-sdk Apr 4, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 4, 2026

View your CI Pipeline Execution ↗ for commit 8df80cc

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 2s View ↗
nx affected -t build,lint,test ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-04 14:42:56 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 4, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 0eb5eb3

Command Status Duration Result
nx affected -t build,lint,test ❌ Failed 25s View ↗
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-04 04:16:17 UTC

ImmutableJeffrey and others added 18 commits April 4, 2026 18:28
Foundation package at packages/audience/sdk/ with typed events,
message queue, transport, and browser context collection.
Wire format aligned with backend OAS.

Also excludes flaky x-client integration tests that hit live APIs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New @imtbl/audience-web-sdk package wired into the monorepo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
init, page, track, identify (known + anonymous), alias, setConsent,
reset, flush, shutdown. Consent-aware gating. Server reconciliation on init.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Self-contained IIFE (4.0 KB gzipped). window.ImmutableWebSDK global.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cookie, queue, transport, context, validation modules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
120 tests total (82 web + 38 shared SDK).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Interactive page with dark/light mode toggle (onyx theme).
Exercises every API method against local, dev, or sandbox backend.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Install, init, consent, events, identity, CDN usage, cookies, wire format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The no-bitwise disable was left over from a previous version.
The current code uses Math.trunc and modulo, no bitwise ops.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of this is already in audience/core. queue, storage etc as pixel will use it too

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor Author

Superseded by stacked PRs #2819#2820#2821#2822. Same web SDK, rearchitected to use contract-only core and broken into reviewable pieces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants