Skip to content

Commit 008b6ea

Browse files
bkboothclaude
andauthored
feat(pixel): remove identify() from pixel tracker (#2846)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05eafd9 commit 008b6ea

File tree

5 files changed

+8
-101
lines changed

5 files changed

+8
-101
lines changed

packages/audience/pixel/src/bootstrap.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55

66
const mockInit = jest.fn();
77
const mockPage = jest.fn();
8-
const mockIdentify = jest.fn();
98
const mockSetConsent = jest.fn();
109
const mockDestroy = jest.fn();
1110

1211
jest.mock('./pixel', () => ({
1312
Pixel: jest.fn().mockImplementation(() => ({
1413
init: mockInit,
1514
page: mockPage,
16-
identify: mockIdentify,
1715
setConsent: mockSetConsent,
1816
destroy: mockDestroy,
1917
})),
@@ -65,14 +63,12 @@ describe('bootstrap', () => {
6563
(window as Record<string, unknown>).__imtbl = [
6664
['init', { key: 'pk_test' }],
6765
['consent', 'full'],
68-
['identify', 'user-1', 'passport', { email: 'a@b.com' }],
6966
];
7067

7168
require('./bootstrap');
7269

7370
expect(mockInit).toHaveBeenCalledWith({ key: 'pk_test' });
7471
expect(mockSetConsent).toHaveBeenCalledWith('full');
75-
expect(mockIdentify).toHaveBeenCalledWith('user-1', 'passport', { email: 'a@b.com' });
7672
});
7773

7874
it('installs loader and handles new commands after load', () => {

packages/audience/pixel/src/bootstrap.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ function handleCommand(command: Command): void {
2323
case 'page':
2424
pixel.page(args[0] as Parameters<Pixel['page']>[0]);
2525
break;
26-
case 'identify':
27-
pixel.identify(
28-
args[0] as string,
29-
args[1] as Parameters<Pixel['identify']>[1],
30-
args[2] as Parameters<Pixel['identify']>[2],
31-
);
32-
break;
3326
case 'consent':
3427
pixel.setConsent(args[0] as Parameters<Pixel['setConsent']>[0]);
3528
break;

packages/audience/pixel/src/loader.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ describe('createLoader', () => {
1818
const loader = createLoader(handler);
1919

2020
loader.push(['init', { key: 'pk_123' }]);
21-
loader.push(['identify', 'user-1']);
21+
loader.push(['page', { url: '/home' }]);
2222

2323
expect(handler).toHaveBeenCalledTimes(2);
2424
expect(handler).toHaveBeenCalledWith(['init', { key: 'pk_123' }]);
25-
expect(handler).toHaveBeenCalledWith(['identify', 'user-1']);
25+
expect(handler).toHaveBeenCalledWith(['page', { url: '/home' }]);
2626
});
2727

2828
it('replays queued commands from the stub array', () => {
@@ -51,9 +51,9 @@ describe('createLoader', () => {
5151
expect(handler).toHaveBeenCalledTimes(1);
5252

5353
// New command via push
54-
loader.push(['identify', 'user-2']);
54+
loader.push(['page', { url: '/about' }]);
5555
expect(handler).toHaveBeenCalledTimes(2);
56-
expect(handler).toHaveBeenLastCalledWith(['identify', 'user-2']);
56+
expect(handler).toHaveBeenLastCalledWith(['page', { url: '/about' }]);
5757
});
5858

5959
it('handles empty window.__imtbl gracefully', () => {

packages/audience/pixel/src/pixel.test.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -230,62 +230,6 @@ describe('Pixel', () => {
230230
});
231231
});
232232

233-
describe('identify', () => {
234-
it('enqueues identify message with identityType at full consent', () => {
235-
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
236-
237-
const pixel = new Pixel();
238-
activePixel = pixel;
239-
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
240-
mockEnqueue.mockClear();
241-
242-
pixel.identify('user-1', 'passport', { email: 'test@example.com' });
243-
244-
expect(mockEnqueue).toHaveBeenCalledWith(
245-
expect.objectContaining({
246-
type: 'identify',
247-
userId: 'user-1',
248-
identityType: 'passport',
249-
surface: 'pixel',
250-
traits: expect.objectContaining({
251-
email: 'test@example.com',
252-
sessionId: 'session-abc',
253-
}),
254-
}),
255-
);
256-
});
257-
258-
it('enqueues identify message without traits', () => {
259-
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
260-
261-
const pixel = new Pixel();
262-
activePixel = pixel;
263-
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
264-
mockEnqueue.mockClear();
265-
266-
pixel.identify('steam-id-123', 'steam');
267-
268-
expect(mockEnqueue).toHaveBeenCalledWith(
269-
expect.objectContaining({
270-
type: 'identify',
271-
userId: 'steam-id-123',
272-
identityType: 'steam',
273-
}),
274-
);
275-
});
276-
277-
it('does not enqueue identify at anonymous consent', () => {
278-
const pixel = new Pixel();
279-
activePixel = pixel;
280-
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'anonymous' });
281-
282-
pixel.identify('user-1', 'passport');
283-
// Only the auto page view + session_start, no identify
284-
const calls = mockEnqueue.mock.calls.map((c: unknown[]) => (c[0] as Record<string, unknown>));
285-
expect(calls.find((c) => c.type === 'identify')).toBeUndefined();
286-
});
287-
});
288-
289233
describe('session_end', () => {
290234
it('fires session_end on pagehide when session is active', () => {
291235
const pixel = new Pixel();

packages/audience/pixel/src/pixel.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import type {
33
ConsentLevel,
44
PageMessage,
55
TrackMessage,
6-
IdentifyMessage,
7-
UserTraits,
86
ConsentManager,
97
CmpDetector,
10-
IdentityType,
118
} from '@imtbl/audience-core';
129
import {
1310
MessageQueue,
@@ -53,8 +50,6 @@ export class Pixel {
5350

5451
private anonymousId = '';
5552

56-
private userId: string | undefined;
57-
5853
private sessionId: string | undefined;
5954

6055
private sessionStartTime: number | undefined;
@@ -160,28 +155,7 @@ export class Pixel {
160155
sessionId,
161156
...properties,
162157
},
163-
userId: this.consent!.level === 'full' ? this.userId : undefined,
164-
};
165-
166-
this.queue!.enqueue(message);
167-
}
168-
169-
identify(userId: string, identityType: IdentityType, traits?: UserTraits): void {
170-
if (!this.isReady() || this.consent!.level !== 'full') return;
171-
172-
this.userId = userId;
173-
const { sessionId, isNew } = getOrCreateSession(this.domain);
174-
this.refreshSession(sessionId, isNew);
175-
176-
const message: IdentifyMessage = {
177-
...this.buildBase(),
178-
type: 'identify',
179-
userId,
180-
identityType,
181-
traits: {
182-
...traits,
183-
sessionId,
184-
} as UserTraits,
158+
userId: undefined,
185159
};
186160

187161
this.queue!.enqueue(message);
@@ -256,7 +230,7 @@ export class Pixel {
256230
type: 'track',
257231
eventName,
258232
properties: { ...properties, sessionId },
259-
userId: this.consent!.level === 'full' ? this.userId : undefined,
233+
userId: undefined,
260234
};
261235

262236
this.queue!.enqueue(message);
@@ -280,7 +254,7 @@ export class Pixel {
280254
type: 'track',
281255
eventName: 'session_start',
282256
properties: { sessionId },
283-
userId: this.consent!.level === 'full' ? this.userId : undefined,
257+
userId: undefined,
284258
};
285259

286260
this.queue!.enqueue(message);
@@ -301,7 +275,7 @@ export class Pixel {
301275
sessionId: this.sessionId,
302276
duration,
303277
},
304-
userId: this.consent!.level === 'full' ? this.userId : undefined,
278+
userId: undefined,
305279
};
306280

307281
this.queue!.enqueue(message);

0 commit comments

Comments
 (0)