Skip to content

Commit c54a577

Browse files
bkboothclaude
andauthored
feat(pixel): add identityType parameter to identify() (#2840)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 01a67ef commit c54a577

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ describe('bootstrap', () => {
6565
(window as Record<string, unknown>).__imtbl = [
6666
['init', { key: 'pk_test' }],
6767
['consent', 'full'],
68-
['identify', 'user-1', { email: 'a@b.com' }],
68+
['identify', 'user-1', 'passport', { email: 'a@b.com' }],
6969
];
7070

7171
require('./bootstrap');
7272

7373
expect(mockInit).toHaveBeenCalledWith({ key: 'pk_test' });
7474
expect(mockSetConsent).toHaveBeenCalledWith('full');
75-
expect(mockIdentify).toHaveBeenCalledWith('user-1', { email: 'a@b.com' });
75+
expect(mockIdentify).toHaveBeenCalledWith('user-1', 'passport', { email: 'a@b.com' });
7676
});
7777

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

packages/audience/pixel/src/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function handleCommand(command: Command): void {
2727
pixel.identify(
2828
args[0] as string,
2929
args[1] as Parameters<Pixel['identify']>[1],
30+
args[2] as Parameters<Pixel['identify']>[2],
3031
);
3132
break;
3233
case 'consent':

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,21 @@ describe('Pixel', () => {
226226
});
227227

228228
describe('identify', () => {
229-
it('enqueues identify message at full consent', () => {
229+
it('enqueues identify message with identityType at full consent', () => {
230230
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
231231

232232
const pixel = new Pixel();
233233
activePixel = pixel;
234234
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
235235
mockEnqueue.mockClear();
236236

237-
pixel.identify('user-1', { email: 'test@example.com' });
237+
pixel.identify('user-1', 'passport', { email: 'test@example.com' });
238238

239239
expect(mockEnqueue).toHaveBeenCalledWith(
240240
expect.objectContaining({
241241
type: 'identify',
242242
userId: 'user-1',
243+
identityType: 'passport',
243244
surface: 'pixel',
244245
traits: expect.objectContaining({
245246
email: 'test@example.com',
@@ -249,12 +250,31 @@ describe('Pixel', () => {
249250
);
250251
});
251252

253+
it('enqueues identify message without traits', () => {
254+
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
255+
256+
const pixel = new Pixel();
257+
activePixel = pixel;
258+
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
259+
mockEnqueue.mockClear();
260+
261+
pixel.identify('steam-id-123', 'steam');
262+
263+
expect(mockEnqueue).toHaveBeenCalledWith(
264+
expect.objectContaining({
265+
type: 'identify',
266+
userId: 'steam-id-123',
267+
identityType: 'steam',
268+
}),
269+
);
270+
});
271+
252272
it('does not enqueue identify at anonymous consent', () => {
253273
const pixel = new Pixel();
254274
activePixel = pixel;
255275
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'anonymous' });
256276

257-
pixel.identify('user-1');
277+
pixel.identify('user-1', 'passport');
258278
// Only the auto page view + session_start, no identify
259279
const calls = mockEnqueue.mock.calls.map((c: unknown[]) => (c[0] as Record<string, unknown>));
260280
expect(calls.find((c) => c.type === 'identify')).toBeUndefined();

packages/audience/pixel/src/pixel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
IdentifyMessage,
77
UserTraits,
88
ConsentManager,
9+
IdentityType,
910
} from '@imtbl/audience-core';
1011
import {
1112
MessageQueue,
@@ -148,7 +149,7 @@ export class Pixel {
148149
this.queue!.enqueue(message);
149150
}
150151

151-
identify(userId: string, traits?: UserTraits): void {
152+
identify(userId: string, identityType: IdentityType, traits?: UserTraits): void {
152153
if (!this.isReady() || this.consent!.level !== 'full') return;
153154

154155
this.userId = userId;
@@ -159,6 +160,7 @@ export class Pixel {
159160
...this.buildBase(),
160161
type: 'identify',
161162
userId,
163+
identityType,
162164
traits: {
163165
...traits,
164166
sessionId,

0 commit comments

Comments
 (0)