Skip to content

Commit 9e4d51c

Browse files
committed
rename privacyManager to cokkieConsentManager, remove logger from cookieConsent, update tests
1 parent ceeb09b commit 9e4d51c

6 files changed

Lines changed: 71 additions & 113 deletions

File tree

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { SDKLoggerApi } from './sdkRuntimeModels';
2-
import { isBoolean } from './utils';
3-
4-
51
/**
6-
* Privacy flags control SDK behavior based on user consent preferences for Rokt integration.
2+
* Cookie consent flags control SDK behavior based on user consent preferences for Rokt integration.
73
* @see https://docs.rokt.com/developers/integration-guides/web/cookie-consent-flags/
84
*/
9-
export interface IPrivacyFlags {
5+
export interface ICookieConsentFlags {
106
/**
117
* When true, indicates the user has opted out of functional cookies/tracking.
128
* Default: false (functional tracking is allowed)
@@ -21,7 +17,7 @@ export interface IPrivacyFlags {
2117
noTargeting: boolean;
2218
}
2319

24-
export interface IPrivacyManager {
20+
export interface ICookieConsentManager {
2521
/**
2622
* Targeting is allowed when noTargeting is false (default)
2723
*/
@@ -34,56 +30,43 @@ export interface IPrivacyManager {
3430
}
3531

3632
/**
37-
* PrivacyManager handles storage and access of privacy flags (noFunctional, noTargeting)
33+
* CookieConsentManager handles storage and access of consent flags (noFunctional, noTargeting)
3834
* that are passed via launcherOptions during SDK initialization.
3935
*
4036
* These flags allow Rokt integration to respect user privacy choices.
4137
*
4238
* Default behavior: Both flags default to false, meaning all features are allowed
4339
* unless explicitly opted out by the user.
4440
*/
45-
export default class PrivacyManager implements IPrivacyManager {
46-
private privacyFlags: IPrivacyFlags = {
41+
export default class CookieConsentManager implements ICookieConsentManager {
42+
private flags: ICookieConsentFlags = {
4743
noFunctional: false,
4844
noTargeting: false,
4945
};
5046

51-
constructor(flags?: Partial<IPrivacyFlags>, logger?: SDKLoggerApi) {
47+
constructor(flags?: Partial<ICookieConsentFlags>) {
5248
if (!flags) {
53-
logger?.verbose('PrivacyManager: No privacy flags provided, using defaults');
5449
return;
5550
}
5651

5752
const { noFunctional, noTargeting } = flags;
58-
59-
if (isBoolean(noFunctional)) {
60-
this.privacyFlags.noFunctional = noFunctional;
61-
logger?.verbose(`PrivacyManager: noFunctional set to ${noFunctional}`);
62-
} else if (noFunctional !== undefined) {
63-
logger?.error('PrivacyManager: noFunctional must be a boolean');
64-
}
65-
66-
if (isBoolean(noTargeting)) {
67-
this.privacyFlags.noTargeting = noTargeting;
68-
logger?.verbose(`PrivacyManager: noTargeting set to ${noTargeting}`);
69-
} else if (noTargeting !== undefined) {
70-
logger?.error('PrivacyManager: noTargeting must be a boolean');
71-
}
53+
this.flags.noFunctional = noFunctional === true;
54+
this.flags.noTargeting = noTargeting === true;
7255
}
7356

7457
/**
7558
* Returns true if third-party targeting is disabled.
7659
* Targeting is allowed when noTargeting is false (default).
7760
*/
7861
getNoTargeting(): boolean {
79-
return this.privacyFlags.noTargeting;
62+
return this.flags.noTargeting;
8063
}
8164

8265
/**
8366
* Returns true if functional tracking is disabled.
8467
* Functional tracking is allowed when noFunctional is false (default).
8568
*/
8669
getNoFunctional(): boolean {
87-
return this.privacyFlags.noFunctional;
70+
return this.flags.noFunctional;
8871
}
8972
}

src/cookieSyncManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default function CookieSyncManager(
110110
}
111111

112112
// For Rokt, block cookie sync when noTargeting privacy flag is true
113-
if (moduleId === PARTNER_MODULE_IDS.Rokt && mpInstance._PrivacyManager.getNoTargeting()) {
113+
if (moduleId === PARTNER_MODULE_IDS.Rokt && mpInstance._CookieConsentManager.getNoTargeting()) {
114114
return;
115115
}
116116

src/mp-instance.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { IPersistence } from './persistence.interfaces';
5151
import ForegroundTimer from './foregroundTimeTracker';
5252
import RoktManager, { IRoktOptions } from './roktManager';
5353
import filteredMparticleUser from './filteredMparticleUser';
54-
import PrivacyManager, { IPrivacyManager } from './privacyManager';
54+
import CookieConsentManager, { ICookieConsentManager } from './cookieConsentManager';
5555

5656
export interface IErrorLogMessage {
5757
message?: string;
@@ -83,7 +83,7 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
8383
_IntegrationCapture: IntegrationCapture;
8484
_NativeSdkHelpers: INativeSdkHelpers;
8585
_Persistence: IPersistence;
86-
_PrivacyManager: IPrivacyManager;
86+
_CookieConsentManager: ICookieConsentManager;
8787
_RoktManager: RoktManager;
8888
_SessionManager: ISessionManager;
8989
_ServerModel: IServerModel;
@@ -1556,12 +1556,9 @@ function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
15561556
window.mParticle.Store = mpInstance._Store;
15571557
mpInstance.Logger.verbose(StartingInitialization);
15581558

1559-
// Initialize PrivacyManager with privacy flags from launcherOptions
1559+
// Initialize CookieConsentManager with privacy flags from launcherOptions
15601560
const { noFunctional, noTargeting } = config?.launcherOptions ?? {};
1561-
mpInstance._PrivacyManager = new PrivacyManager(
1562-
{ noFunctional, noTargeting },
1563-
mpInstance.Logger
1564-
);
1561+
mpInstance._CookieConsentManager = new CookieConsentManager({ noFunctional, noTargeting });
15651562

15661563
// Check to see if localStorage is available before main configuration runs
15671564
// since we will need this for the current implementation of user persistence
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import CookieConsentManager from '../../src/cookieConsentManager';
2+
3+
describe('CookieConsentManager', () => {
4+
describe('#constructor', () => {
5+
it('should default flags to false when not provided', () => {
6+
const cookieConsentManager = new CookieConsentManager();
7+
8+
expect(cookieConsentManager.getNoFunctional()).toBe(false);
9+
expect(cookieConsentManager.getNoTargeting()).toBe(false);
10+
});
11+
12+
it('should set flags when passed', () => {
13+
const cookieConsentManager = new CookieConsentManager({ noFunctional: true, noTargeting: true });
14+
15+
expect(cookieConsentManager.getNoFunctional()).toBe(true);
16+
expect(cookieConsentManager.getNoTargeting()).toBe(true);
17+
});
18+
19+
it('should ignore non-boolean values', () => {
20+
const cookieConsentManager = new CookieConsentManager({
21+
noFunctional: 'true' as unknown as boolean,
22+
noTargeting: 1 as unknown as boolean,
23+
});
24+
25+
expect(cookieConsentManager.getNoFunctional()).toBe(false);
26+
expect(cookieConsentManager.getNoTargeting()).toBe(false);
27+
});
28+
});
29+
30+
describe('#getNoFunctional', () => {
31+
it('should return the noFunctional flag value', () => {
32+
const cookieConsentManager = new CookieConsentManager({ noFunctional: true });
33+
34+
expect(cookieConsentManager.getNoFunctional()).toBe(true);
35+
});
36+
});
37+
38+
describe('#getNoTargeting', () => {
39+
it('should return the noTargeting flag value', () => {
40+
const cookieConsentManager = new CookieConsentManager({ noTargeting: true });
41+
42+
expect(cookieConsentManager.getNoTargeting()).toBe(true);
43+
});
44+
});
45+
});

test/jest/cookieSyncManager.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CookieSyncManager, {
66
PARTNER_MODULE_IDS
77
} from '../../src/cookieSyncManager';
88
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
9-
import PrivacyManager from '../../src/privacyManager';
9+
import CookieConsentManager from '../../src/cookieConsentManager';
1010
import { testMPID } from '../src/config/constants';
1111

1212
const pixelSettings: IPixelConfiguration = {
@@ -407,7 +407,7 @@ describe('CookieSyncManager', () => {
407407
_Consent: {
408408
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
409409
},
410-
_PrivacyManager: {
410+
_CookieConsentManager: {
411411
getNoTargeting: jest.fn().mockReturnValue(true),
412412
},
413413
Identity: {
@@ -420,7 +420,7 @@ describe('CookieSyncManager', () => {
420420

421421
cookieSyncManager.attemptCookieSync(testMPID, true);
422422

423-
expect(mockMPInstance._PrivacyManager.getNoTargeting).toHaveBeenCalled();
423+
expect(mockMPInstance._CookieConsentManager.getNoTargeting).toHaveBeenCalled();
424424
expect(cookieSyncManager.performCookieSync).not.toHaveBeenCalled();
425425
});
426426

@@ -436,7 +436,7 @@ describe('CookieSyncManager', () => {
436436
_Consent: {
437437
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
438438
},
439-
_PrivacyManager: {
439+
_CookieConsentManager: {
440440
getNoTargeting: jest.fn().mockReturnValue(false),
441441
},
442442
Identity: {
@@ -449,12 +449,12 @@ describe('CookieSyncManager', () => {
449449

450450
cookieSyncManager.attemptCookieSync(testMPID, true);
451451

452-
expect(mockMPInstance._PrivacyManager.getNoTargeting).toHaveBeenCalled();
452+
expect(mockMPInstance._CookieConsentManager.getNoTargeting).toHaveBeenCalled();
453453
expect(cookieSyncManager.performCookieSync).toHaveBeenCalled();
454454
});
455455

456456
it('should allow cookie sync when noTargeting is false by default', () => {
457-
const privacyManager = new PrivacyManager(); // Defaults to noTargeting: false
457+
const cookieConsentManager = new CookieConsentManager(); // Defaults to noTargeting: false
458458

459459
const mockMPInstance = ({
460460
_Store: {
@@ -467,7 +467,7 @@ describe('CookieSyncManager', () => {
467467
_Consent: {
468468
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
469469
},
470-
_PrivacyManager: privacyManager,
470+
_CookieConsentManager: cookieConsentManager,
471471
Identity: {
472472
getCurrentUser: jest.fn().mockReturnValue({ getMPID: () => testMPID }),
473473
},
@@ -479,7 +479,7 @@ describe('CookieSyncManager', () => {
479479
cookieSyncManager.attemptCookieSync(testMPID, true);
480480

481481
// Default noTargeting is false, so cookie sync should be allowed
482-
expect(privacyManager.getNoTargeting()).toBe(false);
482+
expect(cookieConsentManager.getNoTargeting()).toBe(false);
483483
expect(cookieSyncManager.performCookieSync).toHaveBeenCalled();
484484
});
485485

@@ -495,7 +495,7 @@ describe('CookieSyncManager', () => {
495495
_Consent: {
496496
isEnabledForUserConsent: jest.fn().mockReturnValue(true),
497497
},
498-
_PrivacyManager: {
498+
_CookieConsentManager: {
499499
getNoTargeting: jest.fn().mockReturnValue(true),
500500
},
501501
Identity: {
@@ -509,7 +509,7 @@ describe('CookieSyncManager', () => {
509509
cookieSyncManager.attemptCookieSync(testMPID, true);
510510

511511
// Should not check noTargeting for non-Rokt partners
512-
expect(mockMPInstance._PrivacyManager.getNoTargeting).not.toHaveBeenCalled();
512+
expect(mockMPInstance._CookieConsentManager.getNoTargeting).not.toHaveBeenCalled();
513513
// Should still perform cookie sync
514514
expect(cookieSyncManager.performCookieSync).toHaveBeenCalled();
515515
});

test/jest/privacyManager.spec.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)