Skip to content

Commit 80e4c84

Browse files
jaeoptclauderaju-opti
authored
[AI-FSSDK] [FSSDK-12670] Block ODP identify event for single identifier (#1152)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Raju Ahmed <raju.ahmed@optimizely.com>
1 parent a2b378c commit 80e4c84

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

lib/message/log_message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const INVALIDATE_CMAB_CACHE = 'Invalidating CMAB cache for user %s and ru
6969
export const CMAB_CACHE_HIT = 'Cache hit for user %s and rule %s.';
7070
export const CMAB_CACHE_ATTRIBUTES_MISMATCH = 'CMAB cache attributes mismatch for user %s and rule %s, fetching new decision.';
7171
export const CMAB_CACHE_MISS = 'Cache miss for user %s and rule %s.';
72+
export const ODP_IDENTIFY_NOT_DISPATCHED= 'ODP identify event is not dispatched (fewer than 2 valid identifiers).'
7273

7374
export const messages: string[] = [];
7475

lib/odp/odp_manager.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ describe('DefaultOdpManager', () => {
618618
expect(identifiers).toEqual(new Map([['fs_user_id', 'user'], ['vuid', 'vuid_a']]));
619619
});
620620

621-
it('sends identified event when called with just fs_user_id in first parameter', async () => {
621+
it('does not send identified event when called with just fs_user_id (single identifier)', async () => {
622622
const eventManager = getMockOdpEventManager();
623623
eventManager.onRunning.mockReturnValue(Promise.resolve());
624624

@@ -634,12 +634,10 @@ describe('DefaultOdpManager', () => {
634634
await odpManager.onRunning();
635635

636636
odpManager.identifyUser('user');
637-
expect(mockSendEvents).toHaveBeenCalledOnce();
638-
const { identifiers } = mockSendEvents.mock.calls[0][0];
639-
expect(identifiers).toEqual(new Map([['fs_user_id', 'user']]));
637+
expect(mockSendEvents).not.toHaveBeenCalled();
640638
});
641639

642-
it('sends identified event when called with just vuid in first parameter', async () => {
640+
it('does not send identified event when called with just vuid (single identifier)', async () => {
643641
const eventManager = getMockOdpEventManager();
644642
eventManager.onRunning.mockReturnValue(Promise.resolve());
645643

@@ -655,9 +653,7 @@ describe('DefaultOdpManager', () => {
655653
await odpManager.onRunning();
656654

657655
odpManager.identifyUser('vuid_a');
658-
expect(mockSendEvents).toHaveBeenCalledOnce();
659-
const { identifiers } = mockSendEvents.mock.calls[0][0];
660-
expect(identifiers).toEqual(new Map([['vuid', 'vuid_a']]));
656+
expect(mockSendEvents).not.toHaveBeenCalled();
661657
});
662658

663659
it('should reject onRunning() if stopped in new state', async () => {

lib/odp/odp_manager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { v4 as uuidV4} from 'uuid';
18-
import { LoggerFacade } from '../logging/logger';
18+
import { LoggerFacade, LogLevel } from '../logging/logger';
1919

2020
import { OdpIntegrationConfig, odpIntegrationsAreEqual } from './odp_config';
2121
import { OdpEventManager } from './event_manager/odp_event_manager';
@@ -32,6 +32,7 @@ import { Maybe } from '../utils/type';
3232
import { sprintf } from '../utils/fns';
3333
import { SERVICE_STOPPED_BEFORE_RUNNING } from '../service';
3434
import { Platform } from '../platform_support';
35+
import { ODP_IDENTIFY_NOT_DISPATCHED } from '../message/log_message';
3536

3637
export interface OdpManager extends Service {
3738
updateConfig(odpIntegrationConfig: OdpIntegrationConfig): boolean;
@@ -212,7 +213,7 @@ export class DefaultOdpManager extends BaseService implements OdpManager {
212213

213214
identifyUser(userId: string, vuid?: string): void {
214215
const identifiers = new Map<string, string>();
215-
216+
216217
let finalUserId: Maybe<string> = userId;
217218
let finalVuid: Maybe<string> = vuid;
218219

@@ -229,6 +230,13 @@ export class DefaultOdpManager extends BaseService implements OdpManager {
229230
identifiers.set(ODP_USER_KEY.FS_USER_ID, finalUserId);
230231
}
231232

233+
// Identify requires 2+ identifiers to link (e.g., vuid + fs_user_id).
234+
// A single identifier has no cross-reference value and generates unnecessary traffic.
235+
if (identifiers.size < 2) {
236+
this.logger?.debug(ODP_IDENTIFY_NOT_DISPATCHED);
237+
return;
238+
}
239+
232240
const event = new OdpEvent(ODP_DEFAULT_EVENT_TYPE, ODP_EVENT_ACTION.IDENTIFIED, identifiers);
233241
this.sendEvent(event);
234242
}

0 commit comments

Comments
 (0)