Skip to content

Commit d7da4ba

Browse files
refactor(pixel): use consent queries in autocapture + fix SnippetOptions type
autocapture.ts — replace 3 consent string comparisons: - form submit guard: getConsent() === 'none' → !canTrack(getConsent()) - email hash gate: consent === 'full' → includesUserId(consent) - link click guard: getConsent() === 'none' → !canTrack(getConsent()) snippet.ts — replace inline literal union 'none' | 'anonymous' | 'full' with the ConsentLevel type from @imtbl/audience-core. This was the one place consent values were defined outside the single source of truth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c83503c commit d7da4ba

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

packages/audience/pixel/src/autocapture.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ConsentLevel } from '@imtbl/audience-core';
2+
import { canTrack, includesUserId } from '@imtbl/audience-core';
23

34
export interface AutocaptureOptions {
45
/** Enable form submission auto-capture. Default: true */
@@ -68,7 +69,7 @@ export function setupAutocapture(
6869

6970
if (options.forms !== false) {
7071
const onSubmit = (e: Event): void => {
71-
if (getConsent() === 'none') return;
72+
if (!canTrack(getConsent())) return;
7273

7374
const form = e.target as HTMLFormElement;
7475
if (!form || form.tagName !== 'FORM') return;
@@ -81,7 +82,7 @@ export function setupAutocapture(
8182
};
8283

8384
const consent = getConsent();
84-
if (consent === 'full') {
85+
if (includesUserId(consent)) {
8586
const email = findEmail(form);
8687
if (email) {
8788
// Hash before enqueuing — raw email never enters the queue.
@@ -109,7 +110,7 @@ export function setupAutocapture(
109110

110111
if (options.clicks !== false) {
111112
const onClick = (e: Event): void => {
112-
if (getConsent() === 'none') return;
113+
if (!canTrack(getConsent())) return;
113114

114115
const target = e.target as HTMLElement;
115116
const anchor = target.closest?.('a') as HTMLAnchorElement | null;

packages/audience/pixel/src/snippet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import type { ConsentLevel } from '@imtbl/audience-core';
2+
13
const DEFAULT_CDN_URL = 'https://cdn.immutable.com/pixel/v1/imtbl.js';
24

35
export interface SnippetOptions {
46
key: string;
57
cdnUrl?: string;
6-
consent?: 'none' | 'anonymous' | 'full';
8+
consent?: ConsentLevel;
79
}
810

911
export function generateSnippet(options: SnippetOptions): string {

0 commit comments

Comments
 (0)