Skip to content

Commit c180628

Browse files
eyas-ranjoussa1omon
authored and
sa1omon
committed
[feature] Add a config list of submodules that require refreshing the stored ID after each bid request (prebid#4325)
* add a feature to always refresh stored id on each bid request for submodules that require that * update test comments
1 parent 201340e commit c180628

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

modules/userId/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ function initSubmodules(submodules, consentData) {
386386
refreshNeeded = storedDate && (Date.now() - storedDate.getTime() > submodule.config.storage.refreshInSeconds * 1000);
387387
}
388388

389+
if (CONSTANTS.SUBMODULES_THAT_ALWAYS_REFRESH_ID[submodule.config.name] === true) {
390+
refreshNeeded = true;
391+
}
392+
389393
if (!storedId || refreshNeeded) {
390394
// No previously saved id. Request one from submodule.
391395
response = submodule.submodule.getId(submodule.config.params, consentData, storedId);

src/constants.json

+3
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@
9595
"BID_STATUS" : {
9696
"BID_TARGETING_SET": "targetingSet",
9797
"RENDERED": "rendered"
98+
},
99+
"SUBMODULES_THAT_ALWAYS_REFRESH_ID": {
100+
"parrableId": true
98101
}
99102
}

test/spec/modules/userId_spec.js

+70
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ describe('User ID', function() {
985985
sinon.stub(utils, 'triggerPixel');
986986
utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE);
987987
utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE);
988+
utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE);
988989
});
989990

990991
afterEach(function() {
@@ -993,6 +994,7 @@ describe('User ID', function() {
993994
utils.triggerPixel.restore();
994995
utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE);
995996
utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE);
997+
utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE);
996998
});
997999

9981000
it('pubcid callback with url', function () {
@@ -1042,5 +1044,73 @@ describe('User ID', function() {
10421044
events.emit(CONSTANTS.EVENTS.AUCTION_END, {});
10431045
expect(requests[0].url).to.equal('//match.adsrvr.org/track/rid?ttd_pid=rubicon&fmt=json');
10441046
});
1047+
1048+
it('callback for submodules that always need to refresh stored id', function(done) {
1049+
let adUnits = [getAdUnitMock()];
1050+
let innerAdUnits;
1051+
const parrableStoredId = '01.1111111111.test-eid';
1052+
const parrableRefreshedId = '02.2222222222.test-eid';
1053+
utils.setCookie('_parrable_eid', parrableStoredId, (new Date(Date.now() + 5000).toUTCString()));
1054+
1055+
const parrableIdSubmoduleMock = {
1056+
name: 'parrableId',
1057+
decode: function(value) {
1058+
return { 'parrableid': value };
1059+
},
1060+
getId: function() {
1061+
return {
1062+
callback: function(cb) {
1063+
cb(parrableRefreshedId);
1064+
}
1065+
};
1066+
}
1067+
};
1068+
1069+
const parrableConfigMock = {
1070+
userSync: {
1071+
syncDelay: 0,
1072+
userIds: [{
1073+
name: 'parrableId',
1074+
storage: {
1075+
type: 'cookie',
1076+
name: '_parrable_eid'
1077+
}
1078+
}]
1079+
}
1080+
};
1081+
1082+
setSubmoduleRegistry([parrableIdSubmoduleMock]);
1083+
attachIdSystem(parrableIdSubmoduleMock);
1084+
init(config);
1085+
config.setConfig(parrableConfigMock);
1086+
1087+
// make first bid request, should use stored id value
1088+
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
1089+
innerAdUnits.forEach(unit => {
1090+
unit.bids.forEach(bid => {
1091+
expect(bid).to.have.deep.nested.property('userId.parrableid');
1092+
expect(bid.userId.parrableid).to.equal(parrableStoredId);
1093+
});
1094+
});
1095+
1096+
// attach a handler for auction end event to run the second bid request
1097+
events.on(CONSTANTS.EVENTS.AUCTION_END, function handler(submodule) {
1098+
if (submodule === 'parrableIdSubmoduleMock') {
1099+
// make the second bid request, id should have been refreshed
1100+
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
1101+
innerAdUnits.forEach(unit => {
1102+
unit.bids.forEach(bid => {
1103+
expect(bid).to.have.deep.nested.property('userId.parrableid');
1104+
expect(bid.userId.parrableid).to.equal(parrableRefreshedId);
1105+
});
1106+
});
1107+
events.off(CONSTANTS.EVENTS.AUCTION_END, handler);
1108+
done();
1109+
}
1110+
});
1111+
1112+
// emit an auction end event to run the submodule callback
1113+
events.emit(CONSTANTS.EVENTS.AUCTION_END, 'parrableIdSubmoduleMock');
1114+
});
10451115
});
10461116
});

0 commit comments

Comments
 (0)