Skip to content

feat(audience): fix core bugs and add capabilities for web SDK#2824

Merged
ImmutableJeffrey merged 1 commit intomainfrom
feat/audience-1-core-fixes
Apr 7, 2026
Merged

feat(audience): fix core bugs and add capabilities for web SDK#2824
ImmutableJeffrey merged 1 commit intomainfrom
feat/audience-1-core-fixes

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Contributor

Summary

Fixes bugs and adds capabilities to @imtbl/audience-core needed by the web SDK and pixel.

Bug fixes:

  • Fix generateId fallback to UUID v4 format (backend requires UUID)
  • Replace sendBeacon with fetch + keepalive (sendBeacon can't set the x-immutable-publishable-key header — every unload flush was silently rejected)
  • Cap batch size at 100 messages per flush (backend maxItems limit)

New capabilities:

  • Export getCookie/setCookie/deleteCookie; add domain param for cross-subdomain cookie sharing
  • Parameterize collectContext(library, version) so each surface identifies itself
  • Add queue.purge(), transform(), flushUnload(), onFlush, staleFilter
  • Add 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)

No breaking changes to existing core API. All new capabilities are additive (optional params, new exports, new options object on queue constructor).

Test plan

  • cd packages/audience/core && pnpm test — 54 tests pass
  • cd packages/audience/core && pnpm build — builds clean

🤖 Generated with Claude Code

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 5, 2026

View your CI Pipeline Execution ↗ for commit bad21ca

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

☁️ Nx Cloud last updated this comment at 2026-04-07 02:44:06 UTC

@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-1-core-fixes branch from 613d44d to 24a1dd6 Compare April 6, 2026 15:05
Comment thread packages/audience/core/src/config.ts Outdated
Comment thread pnpm-workspace.yaml Outdated
Comment thread packages/audience/core/src/context.ts Outdated
Comment thread packages/audience/core/src/queue.ts
Comment thread packages/audience/core/src/validation.ts
Comment thread packages/audience/core/src/queue.ts
Comment thread packages/audience/core/src/types.ts
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-1-core-fixes branch from 24a1dd6 to ac6023c Compare April 6, 2026 23:04
Comment thread pnpm-workspace.yaml Outdated
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-1-core-fixes branch 2 times, most recently from deb2408 to f54168f Compare April 7, 2026 01:10
Comment thread packages/audience/core/src/queue.ts
Comment thread packages/audience/core/src/validation.ts
Comment thread packages/audience/core/src/queue.ts
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-1-core-fixes branch from f54168f to 7c161d7 Compare April 7, 2026 01:48
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
- collectContext() now accepts optional library/version params (backward compatible)
- Add queue.purge(), transform(), flushUnload(), onFlush, staleFilter
- Add storage prefix param for per-surface localStorage isolation
- Add transport keepalive option
- Add ConsentLevel, ConsentStatus, SESSION_COOKIE shared types
- Add validation module (isTimestampValid, isAliasValid, truncate)
- Add packages/audience/sdk to pnpm workspace

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey force-pushed the feat/audience-1-core-fixes branch from 7c161d7 to bad21ca Compare April 7, 2026 02:19
@nattb8 nattb8 marked this pull request as ready for review April 7, 2026 02:44
@nattb8 nattb8 requested a review from a team as a code owner April 7, 2026 02:44
@ImmutableJeffrey ImmutableJeffrey added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit 911bed4 Apr 7, 2026
7 checks passed
@ImmutableJeffrey ImmutableJeffrey deleted the feat/audience-1-core-fixes branch April 7, 2026 03:01
bkbooth added a commit that referenced this pull request Apr 7, 2026
…r, and snippet

Add the pixel package scaffold and three self-contained modules that have
no dependency on PR #2824. The package builds to a single IIFE bundle
(dist/imtbl.js) targeting <10KB gzipped (currently 823 bytes).

Modules:
- attribution: UTM params, ad click IDs, referrer, landing page (session-cached)
- loader: command-queue pattern (window.__imtbl) with pre-load replay
- snippet: embeddable <script> tag generator for studio integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bkbooth added a commit that referenced this pull request Apr 7, 2026
…ion cookie

Wire the pixel to audience-core now that PR #2824 has merged:

- Consent state machine: three-level (none/anonymous/full), DNT/GPC detection,
  queue purge on downgrade to none, userId strip on downgrade to anonymous,
  fire-and-forget PUT to /v1/audience/tracking-consent
- Session cookie: _imtbl_sid with 30-min rolling expiry
- Pixel class: init creates MessageQueue with storagePrefix isolation,
  auto-fires PageMessage with attribution context, supports identify at
  full consent, setConsent, and destroy
- Build config: resolves audience-core from source via tsup alias for
  tree-shaken self-contained IIFE bundle (8.04 KB raw / 3.2 KB gzipped)
- Metrics stub: no-op stubs so the pixel bundle doesn't ship internal telemetry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bkbooth added a commit that referenced this pull request Apr 7, 2026
…ion cookie

Wire the pixel to audience-core now that PR #2824 has merged:

- Consent state machine: three-level (none/anonymous/full), DNT/GPC detection,
  queue purge on downgrade to none, userId strip on downgrade to anonymous,
  fire-and-forget PUT to /v1/audience/tracking-consent
- Session cookie: _imtbl_sid with 30-min rolling expiry
- Pixel class: init creates MessageQueue with storagePrefix isolation,
  auto-fires PageMessage with attribution context, supports identify at
  full consent, setConsent, and destroy
- Build config: resolves audience-core from source via tsup alias for
  tree-shaken self-contained IIFE bundle (8.04 KB raw / 3.2 KB gzipped)
- Metrics stub: no-op stubs so the pixel bundle doesn't ship internal telemetry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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