Skip to content

Commit

Permalink
UserID: call gpt setPublisherProvidedId only when PPID is available (
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored and JacobKlein26 committed Feb 8, 2023
1 parent 0c62844 commit f9b2f5f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
35 changes: 21 additions & 14 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ function processSubmoduleCallbacks(submodules, cb) {
}
// cache decoded value (this is copied to every adUnit bid)
submodule.idObj = submodule.submodule.decode(idObj, submodule.config);
updatePPID(submodule.idObj);
} else {
logInfo(`${MODULE_NAME}: ${submodule.submodule.name} - request id responded with an empty value`);
}
Expand Down Expand Up @@ -613,9 +614,9 @@ function idSystemInitializer({delay = GreedyPromise.timeout} = {}) {

let initIdSystem;

function getPPID() {
function getPPID(eids = getUserIdsAsEids() || []) {
// userSync.ppid should be one of the 'source' values in getUserIdsAsEids() eg pubcid.org or id5-sync.com
const matchingUserId = ppidSource && (getUserIdsAsEids() || []).find(userID => userID.source === ppidSource);
const matchingUserId = ppidSource && eids.find(userID => userID.source === ppidSource);
if (matchingUserId && typeof deepAccess(matchingUserId, 'uids.0.id') === 'string') {
const ppidValue = matchingUserId.uids[0].id.replace(/[\W_]/g, '');
if (ppidValue.length >= 32 && ppidValue.length <= 150) {
Expand All @@ -642,18 +643,6 @@ export const requestBidsHook = timedAuctionHook('userId', function requestBidsHo
]).then(() => {
// pass available user id data to bid adapters
addIdDataToAdUnitBids(reqBidsConfigObj.adUnits || getGlobal().adUnits, initializedSubmodules);
const ppid = getPPID();
if (ppid) {
if (isGptPubadsDefined()) {
window.googletag.pubads().setPublisherProvidedId(ppid);
} else {
window.googletag = window.googletag || {};
window.googletag.cmd = window.googletag.cmd || [];
window.googletag.cmd.push(function() {
window.googletag.pubads().setPublisherProvidedId(ppid);
});
}
}
uidMetrics().join(useMetrics(reqBidsConfigObj.metrics), {propagate: false, includeGroups: true});
// calling fn allows prebid to continue processing
fn.call(this, reqBidsConfigObj);
Expand Down Expand Up @@ -853,6 +842,24 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef
if (response.id) { submodule.idObj = submodule.submodule.decode(response.id, submodule.config); }
}
}
updatePPID(submodule.idObj);
}

function updatePPID(userIds = getUserIds()) {
if (userIds && ppidSource) {
const ppid = getPPID(createEidsArray(userIds));
if (ppid) {
if (isGptPubadsDefined()) {
window.googletag.pubads().setPublisherProvidedId(ppid);
} else {
window.googletag = window.googletag || {};
window.googletag.cmd = window.googletag.cmd || [];
window.googletag.cmd.push(function() {
window.googletag.pubads().setPublisherProvidedId(ppid);
});
}
}
}
}

function initSubmodules(dest, submodules, consentData, forceRefresh = false) {
Expand Down
43 changes: 39 additions & 4 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ describe('User ID', function () {
init(config);
setSubmoduleRegistry([amxIdSubmodule, sharedIdSystemSubmodule, identityLinkSubmodule, imuIdSubmodule]);

// before ppid should not be set
expect(window.googletag._ppid).to.equal(undefined);

config.setConfig({
userSync: {
ppid: 'pubcid.org',
Expand All @@ -416,19 +419,52 @@ describe('User ID', function () {
]
}
});
// before ppid should not be set
expect(window.googletag._ppid).to.equal(undefined);
return expectImmediateBidHook(() => {}, {adUnits}).then(() => {
// ppid should have been set without dashes and stuff
expect(window.googletag._ppid).to.equal('pubCommonidvaluepubCommonidvalue');
});
});

it('should set PPID when the source needs to call out to the network', () => {
let adUnits = [getAdUnitMock()];
init(config);
const callback = sinon.stub();
setSubmoduleRegistry([{
name: 'sharedId',
getId: function () {
return {callback}
},
decode(d) {
return d
}
}]);
config.setConfig({
userSync: {
ppid: 'pubcid.org',
auctionDelay: 10,
userIds: [
{
name: 'sharedId',
}
]
}
});
return expectImmediateBidHook(() => {}, {adUnits}).then(() => {
expect(window.googletag._ppid).to.be.undefined;
const uid = 'thismustbelongerthan32characters'
callback.yield({pubcid: uid});
expect(window.googletag._ppid).to.equal(uid);
});
});

it('should set googletag ppid correctly for imuIdSubmodule', function () {
let adUnits = [getAdUnitMock()];
init(config);
setSubmoduleRegistry([imuIdSubmodule]);

// before ppid should not be set
expect(window.googletag._ppid).to.equal(undefined);

config.setConfig({
userSync: {
ppid: 'ppid.intimatemerger.com',
Expand All @@ -437,8 +473,7 @@ describe('User ID', function () {
]
}
});
// before ppid should not be set
expect(window.googletag._ppid).to.equal(undefined);

return expectImmediateBidHook(() => {}, {adUnits}).then(() => {
// ppid should have been set without dashes and stuff
expect(window.googletag._ppid).to.equal('imppidvalueimppidvalueimppidvalue');
Expand Down

0 comments on commit f9b2f5f

Please sign in to comment.