Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add a config list of submodules that require refreshing the stored ID after each bid request #4325

Merged
merged 2 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ function initSubmodules(submodules, consentData) {
refreshNeeded = storedDate && (Date.now() - storedDate.getTime() > submodule.config.storage.refreshInSeconds * 1000);
}

if (CONSTANTS.SUBMODULES_THAT_ALWAYS_REFRESH_ID[submodule.config.name] === true) {
refreshNeeded = true;
}

if (!storedId || refreshNeeded) {
// No previously saved id. Request one from submodule.
response = submodule.submodule.getId(submodule.config.params, consentData, storedId);
Expand Down
3 changes: 3 additions & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"BID_STATUS" : {
"BID_TARGETING_SET": "targetingSet",
"RENDERED": "rendered"
},
"SUBMODULES_THAT_ALWAYS_REFRESH_ID": {
"parrableId": true
}
}
70 changes: 70 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ describe('User ID', function() {
sinon.stub(utils, 'triggerPixel');
utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE);
utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE);
utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE);
});

afterEach(function() {
Expand All @@ -993,6 +994,7 @@ describe('User ID', function() {
utils.triggerPixel.restore();
utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE);
utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE);
utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE);
});

it('pubcid callback with url', function () {
Expand Down Expand Up @@ -1042,5 +1044,73 @@ describe('User ID', function() {
events.emit(CONSTANTS.EVENTS.AUCTION_END, {});
expect(requests[0].url).to.equal('//match.adsrvr.org/track/rid?ttd_pid=rubicon&fmt=json');
});

it('callback for submodules that always need to refresh stored id', function(done) {
let adUnits = [getAdUnitMock()];
let innerAdUnits;
const parrableStoredId = '01.1111111111.test-eid';
const parrableRefreshedId = '02.2222222222.test-eid';
utils.setCookie('_parrable_eid', parrableStoredId, (new Date(Date.now() + 5000).toUTCString()));

const parrableIdSubmoduleMock = {
name: 'parrableId',
decode: function(value) {
return { 'parrableid': value };
},
getId: function() {
return {
callback: function(cb) {
cb(parrableRefreshedId);
}
};
}
};

const parrableConfigMock = {
userSync: {
syncDelay: 0,
userIds: [{
name: 'parrableId',
storage: {
type: 'cookie',
name: '_parrable_eid'
}
}]
}
};

setSubmoduleRegistry([parrableIdSubmoduleMock]);
attachIdSystem(parrableIdSubmoduleMock);
init(config);
config.setConfig(parrableConfigMock);

// make first bid request, should use stored id value
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
innerAdUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property('userId.parrableid');
expect(bid.userId.parrableid).to.equal(parrableStoredId);
});
});

// attach a handler for auction end event to run the second bid request
events.on(CONSTANTS.EVENTS.AUCTION_END, function handler(submodule) {
if (submodule === 'parrableIdSubmoduleMock') {
// make the second bid request, id should have been refreshed
requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits});
innerAdUnits.forEach(unit => {
unit.bids.forEach(bid => {
expect(bid).to.have.deep.nested.property('userId.parrableid');
expect(bid.userId.parrableid).to.equal(parrableRefreshedId);
});
});
events.off(CONSTANTS.EVENTS.AUCTION_END, handler);
done();
}
});

// emit an auction end event to run the submodule callback
events.emit(CONSTANTS.EVENTS.AUCTION_END, 'parrableIdSubmoduleMock');
});
});
});