Skip to content

Commit 51ead4b

Browse files
bkboothclaude
andcommitted
feat(pixel): add identityType parameter to identify()
Add required identityType parameter (second arg) to Pixel.identify() so the backend can distinguish which identity system a user ID belongs to (passport, steam, epic, etc.). Uses the shared IdentityType union from @imtbl/audience-core for parity with the web SDK. Closes SDK-77 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f390789 commit 51ead4b

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

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

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

221221
describe('identify', () => {
222-
it('enqueues identify message at full consent', () => {
222+
it('enqueues identify message with identityType at full consent', () => {
223223
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
224224

225225
const pixel = new Pixel();
226226
activePixel = pixel;
227227
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
228228
mockEnqueue.mockClear();
229229

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

232232
expect(mockEnqueue).toHaveBeenCalledWith(
233233
expect.objectContaining({
234234
type: 'identify',
235235
userId: 'user-1',
236+
identityType: 'passport',
236237
surface: 'pixel',
237238
traits: expect.objectContaining({
238239
email: 'test@example.com',
@@ -242,12 +243,31 @@ describe('Pixel', () => {
242243
);
243244
});
244245

246+
it('enqueues identify message without traits', () => {
247+
mockGetOrCreateSession.mockReturnValue({ sessionId: 'session-abc', isNew: false });
248+
249+
const pixel = new Pixel();
250+
activePixel = pixel;
251+
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'full' });
252+
mockEnqueue.mockClear();
253+
254+
pixel.identify('steam-id-123', 'steam');
255+
256+
expect(mockEnqueue).toHaveBeenCalledWith(
257+
expect.objectContaining({
258+
type: 'identify',
259+
userId: 'steam-id-123',
260+
identityType: 'steam',
261+
}),
262+
);
263+
});
264+
245265
it('does not enqueue identify at anonymous consent', () => {
246266
const pixel = new Pixel();
247267
activePixel = pixel;
248268
pixel.init({ key: 'pk_test', environment: 'dev', consent: 'anonymous' });
249269

250-
pixel.identify('user-1');
270+
pixel.identify('user-1', 'passport');
251271
// Only the auto page view + session_start, no identify
252272
const calls = mockEnqueue.mock.calls.map((c: unknown[]) => (c[0] as Record<string, unknown>));
253273
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,
@@ -147,7 +148,7 @@ export class Pixel {
147148
this.queue!.enqueue(message);
148149
}
149150

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

153154
this.userId = userId;
@@ -158,6 +159,7 @@ export class Pixel {
158159
...this.buildBase(),
159160
type: 'identify',
160161
userId,
162+
identityType,
161163
traits: {
162164
...traits,
163165
sessionId,

0 commit comments

Comments
 (0)