diff --git a/packages/audience/pixel/src/bootstrap.test.ts b/packages/audience/pixel/src/bootstrap.test.ts index f811564609..396fb2988a 100644 --- a/packages/audience/pixel/src/bootstrap.test.ts +++ b/packages/audience/pixel/src/bootstrap.test.ts @@ -65,14 +65,14 @@ describe('bootstrap', () => { (window as Record).__imtbl = [ ['init', { key: 'pk_test' }], ['consent', 'full'], - ['identify', 'user-1', { email: 'a@b.com' }], + ['identify', 'user-1', 'passport', { email: 'a@b.com' }], ]; require('./bootstrap'); expect(mockInit).toHaveBeenCalledWith({ key: 'pk_test' }); expect(mockSetConsent).toHaveBeenCalledWith('full'); - expect(mockIdentify).toHaveBeenCalledWith('user-1', { email: 'a@b.com' }); + expect(mockIdentify).toHaveBeenCalledWith('user-1', 'passport', { email: 'a@b.com' }); }); it('installs loader and handles new commands after load', () => { diff --git a/packages/audience/pixel/src/bootstrap.ts b/packages/audience/pixel/src/bootstrap.ts index 4d13470f7c..fe7b9ed06b 100644 --- a/packages/audience/pixel/src/bootstrap.ts +++ b/packages/audience/pixel/src/bootstrap.ts @@ -27,6 +27,7 @@ function handleCommand(command: Command): void { pixel.identify( args[0] as string, args[1] as Parameters[1], + args[2] as Parameters[2], ); break; case 'consent': diff --git a/packages/audience/pixel/src/pixel.test.ts b/packages/audience/pixel/src/pixel.test.ts index 4bb9785357..c2917b4816 100644 --- a/packages/audience/pixel/src/pixel.test.ts +++ b/packages/audience/pixel/src/pixel.test.ts @@ -219,7 +219,7 @@ describe('Pixel', () => { }); describe('identify', () => { - it('enqueues identify message at full consent', () => { + it('enqueues identify message with identityType at full consent', () => { mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false }); const pixel = new Pixel(); @@ -227,12 +227,13 @@ describe('Pixel', () => { pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' }); mockEnqueue.mockClear(); - pixel.identify('user-1', { email: 'test@example.com' }); + pixel.identify('user-1', 'passport', { email: 'test@example.com' }); expect(mockEnqueue).toHaveBeenCalledWith( expect.objectContaining({ type: 'identify', userId: 'user-1', + identityType: 'passport', surface: 'pixel', traits: expect.objectContaining({ email: 'test@example.com', @@ -242,12 +243,31 @@ describe('Pixel', () => { ); }); + it('enqueues identify message without traits', () => { + mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false }); + + const pixel = new Pixel(); + activePixel = pixel; + pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' }); + mockEnqueue.mockClear(); + + pixel.identify('steam-id-123', 'steam'); + + expect(mockEnqueue).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'identify', + userId: 'steam-id-123', + identityType: 'steam', + }), + ); + }); + it('does not enqueue identify at anonymous consent', () => { const pixel = new Pixel(); activePixel = pixel; pixel.init({ key: 'pk_test', environment: 'dev', consent: 'anonymous' }); - pixel.identify('user-1'); + pixel.identify('user-1', 'passport'); // Only the auto page view + session_start, no identify const calls = mockEnqueue.mock.calls.map((c: unknown[]) => (c[0] as Record)); expect(calls.find((c) => c.type === 'identify')).toBeUndefined(); diff --git a/packages/audience/pixel/src/pixel.ts b/packages/audience/pixel/src/pixel.ts index 99de797555..e816fb1d3b 100644 --- a/packages/audience/pixel/src/pixel.ts +++ b/packages/audience/pixel/src/pixel.ts @@ -6,6 +6,7 @@ import type { IdentifyMessage, UserTraits, ConsentManager, + IdentityType, } from '@imtbl/audience-core'; import { MessageQueue, @@ -147,7 +148,7 @@ export class Pixel { this.queue!.enqueue(message); } - identify(userId: string, traits?: UserTraits): void { + identify(userId: string, identityType: IdentityType, traits?: UserTraits): void { if (!this.isReady() || this.consent!.level !== 'full') return; this.userId = userId; @@ -158,6 +159,7 @@ export class Pixel { ...this.buildBase(), type: 'identify', userId, + identityType, traits: { ...traits, sessionId,