Skip to content

feat(audience): fix core and add @imtbl/audience-web-sdk#2823

Closed
ImmutableJeffrey wants to merge 4 commits into
mainfrom
feat/audience-core-fixes-and-web-sdk
Closed

feat(audience): fix core and add @imtbl/audience-web-sdk#2823
ImmutableJeffrey wants to merge 4 commits into
mainfrom
feat/audience-core-fixes-and-web-sdk

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor

Summary

Fixes core bugs and adds the web SDK, built on core with no duplicated primitives. Scoped to v1 per Event Reference.

Review commit-by-commit — each commit is a reviewable unit:

  1. Core fixes (613d44d) — bug fixes (UUID, sendBeacon→keepalive, batch cap) + new capabilities (cookie exports, context params, queue purge/transform, validation)
  2. Web SDK scaffold + consent (739a16a) — package setup, ConsentManager with DNT/GPC, session/consent cookies
  3. SDK class (68de603) — ImmutableWebSDK with track/page/identify/alias/setConsent/reset/shutdown, session lifecycle
  4. Attribution + CDN + demo (50d982f) — UTM/click ID/referral parsing, CDN IIFE bundle, interactive demo, README

What's NOT in this PR (by design)

  • No typed events (Natalie to define predefined events)
  • No SPA auto-detection (deferred from v1 per Event Ref)
  • No @imtbl/audience SDK changes

Open questions

  • 400s on sandbox — all requests to api.sandbox.immutable.com return 400 with empty body. Is the audience service deployed to sandbox? Is the publishable key enrolled?
  • camelCase wire format — OAS uses camelCase, SPEC doc uses snake_case. OAS is source of truth?

Test plan

  • 99 tests pass (54 core + 45 web): cd packages/audience/core && pnpm test + cd packages/audience/web && pnpm test
  • Both packages build: pnpm build in each
  • Demo page works: cd packages/audience/web && pnpm demohttp://localhost:3456/web/demo/index.html
  • Verify events reach backend once 400 issue resolved

🤖 Generated with Claude Code

ImmutableJeffrey and others added 4 commits April 5, 2026 21:58
Bug fixes:
- Fix generateId fallback to UUID v4 format (backend requires UUID)
- Replace sendBeacon with fetch+keepalive (sendBeacon can't set auth header)
- Cap batch size at 100 messages per flush (backend maxItems limit)

New capabilities:
- Export getCookie/setCookie/deleteCookie; add domain param for cross-subdomain
- Parameterize collectContext(library, version) for multi-surface support
- Add queue.purge(), transform(), flushUnload(), onFlush, staleFilter
- Add queue storagePrefix option for per-surface localStorage isolation
- Add transport keepalive option
- Add ConsentLevel, ConsentStatus, SESSION_COOKIE, CONSENT_COOKIE shared types
- Add validation module (isTimestampValid, isAliasValid, truncate)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…kies

- Package scaffold: package.json, tsconfig, eslint, jest config
- Add to pnpm-workspace.yaml
- WebSDKConfig type, library name/version constants
- Context wrapper (passes web SDK name to core's collectContext)
- Cookie helpers: session ID (30min rolling), consent cookie (1yr)
- ConsentManager: 3-tier consent, DNT/GPC detection, server sync
- Debug logger for dev mode

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ifecycle

- SDK class: init, track, page, identify, alias, setConsent, reset, shutdown
- Auto-tracked session_start on new session, session_end on shutdown
- Consent-aware: none=inert, anonymous=no PII, full=all events
- Consent downgrade purges identify/alias, strips userId
- Uses core's MessageQueue with httpTransport and __imtbl_web_ storage prefix
- 45 tests covering all methods and consent transitions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Attribution: UTM params, click IDs (gclid/fbclid/ttclid/msclkid/dclid/li_fat_id),
  ?ref= referral code, referrer, landing page — cached per session
- CDN IIFE entry point (window.ImmutableWebSDK), self-contained bundle
- Interactive demo page for end-to-end testing
- README with install, API reference, consent, cookies, CDN usage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey requested review from a team as code owners April 5, 2026 12:43
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.

1 participant