Skip to content

Commit c4f021a

Browse files
committed
add constructor in cookieSyncManager, links docs in privacyManager, clean up tests
1 parent c6751c0 commit c4f021a

7 files changed

Lines changed: 32 additions & 45 deletions

File tree

src/cookieSyncManager.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ export default function CookieSyncManager(
109109
return;
110110
}
111111

112-
// For Rokt, check noTargeting privacy flag before performing cookie sync
113-
if (moduleId === PARTNER_MODULE_IDS.Rokt) {
114-
if (mpInstance._PrivacyManager.getNoTargeting()) {
115-
return;
116-
}
112+
// For Rokt, block cookie sync when noTargeting privacy flag is true
113+
if (moduleId === PARTNER_MODULE_IDS.Rokt && mpInstance._PrivacyManager.getNoTargeting()) {
114+
return;
117115
}
118116

119117
const { isEnabledForUserConsent } = mpInstance._Consent;

src/mp-instance.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
127127
this._ForwardingStatsUploader = new ForwardingStatsUploader(this);
128128
this._Consent = new Consent(this);
129129
this._IdentityAPIClient = new IdentityAPIClient(this);
130-
this._PrivacyManager = new PrivacyManager();
131130
this._preInit = {
132131
readyQueue: [],
133132
integrationDelays: {},
@@ -1559,7 +1558,10 @@ function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
15591558

15601559
// Initialize PrivacyManager with privacy flags from launcherOptions
15611560
const { noFunctional, noTargeting } = config?.launcherOptions ?? {};
1562-
mpInstance._PrivacyManager.init({ noFunctional, noTargeting }, mpInstance.Logger);
1561+
mpInstance._PrivacyManager = new PrivacyManager(
1562+
{ noFunctional, noTargeting },
1563+
mpInstance.Logger
1564+
);
15631565

15641566
// Check to see if localStorage is available before main configuration runs
15651567
// since we will need this for the current implementation of user persistence

src/privacyManager.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SDKLoggerApi } from './sdkRuntimeModels';
22

33
/**
4-
* Privacy flags that control SDK behavior based on user consent choices.
4+
* Privacy flags control SDK behavior based on user consent preferences for Rokt integration.
5+
* @see https://docs.rokt.com/developers/integration-guides/web/cookie-consent-flags/
56
*/
67
export interface IPrivacyFlags {
78
/**
@@ -19,13 +20,6 @@ export interface IPrivacyFlags {
1920
}
2021

2122
export interface IPrivacyManager {
22-
/**
23-
* Initializes the PrivacyManager with privacy flags from configuration.
24-
* @param flags - Privacy flags from launcherOptions
25-
* @param logger - Optional logger for verbose output
26-
*/
27-
init: (flags?: Partial<IPrivacyFlags>, logger?: SDKLoggerApi) => void;
28-
2923
/**
3024
* Targeting is allowed when noTargeting is false (default)
3125
*/
@@ -52,10 +46,7 @@ export default class PrivacyManager implements IPrivacyManager {
5246
noTargeting: false,
5347
};
5448

55-
/**
56-
* Initializes privacy flags from configuration
57-
*/
58-
init(flags?: Partial<IPrivacyFlags>, logger?: SDKLoggerApi): void {
49+
constructor(flags?: Partial<IPrivacyFlags>, logger?: SDKLoggerApi) {
5950
if (!flags) {
6051
logger?.verbose('PrivacyManager: No privacy flags provided, using defaults');
6152
return;

test/jest/cookieSyncManager.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ describe('CookieSyncManager', () => {
454454
});
455455

456456
it('should allow cookie sync when noTargeting is false by default', () => {
457-
const privacyManager = new PrivacyManager();
458-
privacyManager.init(); // Initialize with defaults
457+
const privacyManager = new PrivacyManager(); // Defaults to noTargeting: false
459458

460459
const mockMPInstance = ({
461460
_Store: {

test/jest/privacyManager.spec.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import PrivacyManager from '../../src/privacyManager';
22
import { SDKLoggerApi } from '../../src/sdkRuntimeModels';
33

44
describe('PrivacyManager', () => {
5-
let privacyManager: PrivacyManager;
65
let mockLogger: SDKLoggerApi;
76

87
beforeEach(() => {
@@ -11,13 +10,11 @@ describe('PrivacyManager', () => {
1110
warning: jest.fn(),
1211
error: jest.fn(),
1312
} as unknown as SDKLoggerApi;
14-
15-
privacyManager = new PrivacyManager();
1613
});
1714

18-
describe('#init', () => {
15+
describe('#constructor', () => {
1916
it('should default flags to false when not provided', () => {
20-
privacyManager.init(undefined, mockLogger);
17+
const privacyManager = new PrivacyManager(undefined, mockLogger);
2118

2219
expect(privacyManager.getNoFunctional()).toBe(false);
2320
expect(privacyManager.getNoTargeting()).toBe(false);
@@ -27,7 +24,7 @@ describe('PrivacyManager', () => {
2724
});
2825

2926
it('should set flags when passed and log', () => {
30-
privacyManager.init({ noFunctional: true, noTargeting: true }, mockLogger);
27+
const privacyManager = new PrivacyManager({ noFunctional: true, noTargeting: true }, mockLogger);
3128

3229
expect(privacyManager.getNoFunctional()).toBe(true);
3330
expect(privacyManager.getNoTargeting()).toBe(true);
@@ -36,7 +33,7 @@ describe('PrivacyManager', () => {
3633
});
3734

3835
it('should ignore non-boolean values', () => {
39-
privacyManager.init({
36+
const privacyManager = new PrivacyManager({
4037
noFunctional: 'true' as unknown as boolean,
4138
noTargeting: 1 as unknown as boolean,
4239
}, mockLogger);
@@ -46,23 +43,23 @@ describe('PrivacyManager', () => {
4643
});
4744

4845
it('should work without a logger', () => {
49-
privacyManager.init({ noTargeting: true });
46+
const privacyManager = new PrivacyManager({ noTargeting: true });
5047

5148
expect(privacyManager.getNoTargeting()).toBe(true);
5249
});
5350
});
5451

5552
describe('#getNoFunctional', () => {
5653
it('should return the noFunctional flag value', () => {
57-
privacyManager.init({ noFunctional: true });
54+
const privacyManager = new PrivacyManager({ noFunctional: true });
5855

5956
expect(privacyManager.getNoFunctional()).toBe(true);
6057
});
6158
});
6259

6360
describe('#getNoTargeting', () => {
6461
it('should return the noTargeting flag value', () => {
65-
privacyManager.init({ noTargeting: true });
62+
const privacyManager = new PrivacyManager({ noTargeting: true });
6663

6764
expect(privacyManager.getNoTargeting()).toBe(true);
6865
});

test/jest/roktManager.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,8 @@ describe('RoktManager', () => {
437437
);
438438
expect(roktManager['mappedEmailShaIdentityType']).toBe('other5');
439439
});
440-
});
441440

442-
describe('Rokt privacy flags', () => {
443-
it('should store noTargeting and noFunctional', () => {
441+
it('should pass through Rokt privacy flags (noTargeting and noFunctional) from launcher options', () => {
444442
roktManager.init(
445443
{} as IKitConfigs,
446444
{} as IMParticleUser,

test/src/tests-cookie-syncing.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Utils from './config/utils';
44
import fetchMock from 'fetch-mock/esm/client';
55
import { urls, testMPID, MPConfig, v4LSKey, apiKey } from './config/constants';
66
import { IMParticleUser } from '../../src/identity-user-interfaces';
7-
import { IPixelConfiguration } from '../../src/cookieSyncManager';
7+
import { IPixelConfiguration, PARTNER_MODULE_IDS } from '../../src/cookieSyncManager';
88
import { IConsentRules } from '../../src/consent';
99
import { IMParticleInstanceManager } from '../../src/sdkRuntimeModels';
1010
const {
@@ -1137,9 +1137,11 @@ describe('cookie syncing', function() {
11371137
});
11381138

11391139
describe('Rokt privacy flag', function() {
1140+
const roktModuleId = PARTNER_MODULE_IDS.Rokt.toString();
1141+
11401142
const roktPixelSettings: IPixelConfiguration = {
11411143
name: 'Rokt',
1142-
moduleId: 1277,
1144+
moduleId: PARTNER_MODULE_IDS.Rokt,
11431145
esId: 83009,
11441146
isDebug: false,
11451147
isProduction: true,
@@ -1201,8 +1203,8 @@ describe('cookie syncing', function() {
12011203
const spy = await initWithSpy();
12021204

12031205
expect(spy.calledOnce).to.equal(true);
1204-
expect(spy.firstCall.args[1]).to.equal('1277');
1205-
getLocalStorageData()[testMPID].csd.should.have.property('1277');
1206+
expect(spy.firstCall.args[1]).to.equal(roktModuleId);
1207+
getLocalStorageData()[testMPID].csd.should.have.property(roktModuleId);
12061208
spy.restore();
12071209
});
12081210

@@ -1212,7 +1214,7 @@ describe('cookie syncing', function() {
12121214

12131215
await initAndWait();
12141216

1215-
getLocalStorageData()[testMPID].csd.should.have.property('1277');
1217+
getLocalStorageData()[testMPID].csd.should.have.property(roktModuleId);
12161218
});
12171219

12181220
it('should allow Rokt cookie sync when noTargeting is non-boolean value', async () => {
@@ -1221,7 +1223,7 @@ describe('cookie syncing', function() {
12211223

12221224
await initAndWait();
12231225

1224-
getLocalStorageData()[testMPID].csd.should.have.property('1277');
1226+
getLocalStorageData()[testMPID].csd.should.have.property(roktModuleId);
12251227
});
12261228

12271229
it('should block only Rokt while allowing other partners when noTargeting is true', async () => {
@@ -1232,12 +1234,12 @@ describe('cookie syncing', function() {
12321234

12331235
expect(spy.calledOnce).to.equal(true);
12341236
expect(spy.firstCall.args[1]).to.equal('5');
1235-
expect(getLocalStorageData()[testMPID].csd).to.not.have.property('1277');
1237+
expect(getLocalStorageData()[testMPID].csd).to.not.have.property(roktModuleId);
12361238
getLocalStorageData()[testMPID].csd.should.have.property('5');
12371239
spy.restore();
12381240
});
12391241

1240-
it('should block Rokt when noTargeting is true and if consent rules allow it', async () => {
1242+
it('should block Rokt when noTargeting is true even if consent rules allow it', async () => {
12411243
const roktWithConsent = {
12421244
...roktPixelSettings,
12431245
filteringConsentRuleValues: createConsentRules('targeting'),
@@ -1302,8 +1304,8 @@ describe('cookie syncing', function() {
13021304
await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'newMPID');
13031305

13041306
const data = getLocalStorageData();
1305-
data[testMPID].csd.should.have.property('1277');
1306-
data['newMPID'].csd.should.have.property('1277');
1307+
data[testMPID].csd.should.have.property(roktModuleId);
1308+
data['newMPID'].csd.should.have.property(roktModuleId);
13071309
});
13081310

13091311
it('should not block Rokt cookie sync when only noFunctional is true', async () => {
@@ -1312,7 +1314,7 @@ describe('cookie syncing', function() {
13121314

13131315
await initAndWait();
13141316

1315-
getLocalStorageData()[testMPID].csd.should.have.property('1277');
1317+
getLocalStorageData()[testMPID].csd.should.have.property(roktModuleId);
13161318
});
13171319
});
13181320
});

0 commit comments

Comments
 (0)