Skip to content
Open
49 changes: 36 additions & 13 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,25 +938,48 @@ function setPrebidConfig(){
}
}

window.PWT.ssoEnabled = CONFIG.isSSOEnabled() || false;

refThis.getFloorsConfiguration(prebidConfig)
window.PWT.ssoEnabled = CONFIG.isSSOEnabled() || false;
refThis.assignUserSyncConfig(prebidConfig);
refThis.assignGdprConfigIfRequired(prebidConfig);
refThis.assignCcpaConfigIfRequired(prebidConfig);
refThis.assignCurrencyConfigIfRequired(prebidConfig);
refThis.assignSchainConfigIfRequired(prebidConfig);
refThis.assignSingleRequestConfigForBidders(prebidConfig);
// Adding a hook for publishers to modify the Prebid Config we have generated
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
//todo: stop supporting this hook let pubs use pbjs.requestBids hook
// do not set any config below this line as we are executing the hook above
window[pbNameSpace].setConfig(prebidConfig);
if(CONFIG.isUserIdModuleEnabled()) {
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
// setTimeout only in case of SSO enabled
if(window.PWT.ssoEnabled || owpbjs.getUserIdentities().pubProvidedEmailHash !== undefined) {
var ssoTimeout = util.getSsoTimeout() + CONSTANTS.CONFIG.SSO_ADDITIONAL_TIMEOUT;
// additional timeout of 500ms added for OW profiles. should be removed from here once we start supporting pre-pending code snippet for OW profile.
setTimeout((function() {
var userIDs = util.applyCustomParamFunctionValuesfApplicable(prebidConfig["userSync"]["userIds"]);
prebidConfig["userSync"]["userIds"] = userIDs;
util.log(CONSTANTS.MESSAGES.IDENTITY.M4 + JSON.stringify(userIDs));
prebidConfig = getAllPrebidConfigs(prebidConfig);
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
window[pbNameSpace].requestBids([]);
}), ssoTimeout);
}else {
prebidConfig = getAllPrebidConfigs(prebidConfig);
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
}
}else{
prebidConfig = getAllPrebidConfigs(prebidConfig);
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
}
} else {
util.logWarning("PreBidJS setConfig method is not available");
}
}

function getAllPrebidConfigs(prebidConfig) {
refThis.getFloorsConfiguration(prebidConfig)
refThis.assignGdprConfigIfRequired(prebidConfig);
refThis.assignCcpaConfigIfRequired(prebidConfig);
refThis.assignCurrencyConfigIfRequired(prebidConfig);
refThis.assignSchainConfigIfRequired(prebidConfig);
refThis.assignSingleRequestConfigForBidders(prebidConfig);
return prebidConfig;
}

exports.setPrebidConfig = setPrebidConfig;

function getFloorsConfiguration(prebidConfig){
Expand Down
12 changes: 11 additions & 1 deletion src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ exports.CONFIG = {
"AB_TEST_ENABLED": "abTestEnabled",
"TIMEOUT_ADJUSTMENT": 50,
"SSO_ENABLED": "ssoEnabled",
"SSO_INTEGRATION_TIMEOUT": 2500
"SSO_INTEGRATION_TIMEOUT": 2500,
"SSO_ADDITIONAL_TIMEOUT": 500
};

exports.METADATA_MACROS = {
Expand Down Expand Up @@ -272,6 +273,15 @@ exports.ID_PARTNERS_CUSTOM_VALUES = {
]
};


exports.ID_PARTNERS_CUSTOM_FUNCTION_PARAM_VALUES = {
"id5Id": [
{
"key": "params.pd",
}
]
};

exports.EXCLUDE_PARTNER_LIST = ['pubProvidedId'];

exports.MEDIATYPE = {
Expand Down
35 changes: 29 additions & 6 deletions src_new/controllers/idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,37 @@ refThis.setConfig = function(){
};
}
window.PWT.ssoEnabled = CONFIG.isSSOEnabled() || false;
if(CONFIG.isUserIdModuleEnabled()){
prebidConfig["userSync"]["userIds"] = util.getUserIdConfiguration();
if(CONFIG.isUserIdModuleEnabled()) {
var userIDs = util.getUserIdConfiguration();
prebidConfig["userSync"]["userIds"] = userIDs;
// Adding a hook for publishers to modify the Prebid Config we have generated
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
if(window.PWT.ssoEnabled || owpbjs.getUserIdentities().pubProvidedEmailHash !== undefined) {
var ssoTimeout = util.getSsoTimeout();
setTimeout((function() {
userIDs = util.applyCustomParamFunctionValuesfApplicable(prebidConfig["userSync"]["userIds"]);
prebidConfig["userSync"]["userIds"] = userIDs;
util.log(CONSTANTS.MESSAGES.IDENTITY.M4 + JSON.stringify(userIDs));
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
window[pbNameSpace].requestBids([]);
}), ssoTimeout);
}else {
util.log(CONSTANTS.MESSAGES.IDENTITY.M4 + JSON.stringify(userIDs));
window[pbNameSpace].setConfig(prebidConfig);
window[pbNameSpace].requestBids([]);
}
}else{
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
window[pbNameSpace].requestBids([]);
}
}
else{
if(!(window.PWT.ssoEnabled || owpbjs.getUserIdentities().pubProvidedEmailHash !== undefined)) {
window[pbNameSpace].requestBids([]);
}
// Adding a hook for publishers to modify the Prebid Config we have generated
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
window[pbNameSpace].setConfig(prebidConfig);
}
window[pbNameSpace].requestBids([]);
}
};

Expand Down
69 changes: 65 additions & 4 deletions src_new/util.idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ exports.getUserIdConfiguration = function () {
userIdConfs.push(refThis.getUserIdParams(partnerValues));
}
});
refThis.log(CONSTANTS.MESSAGES.IDENTITY.M4 + JSON.stringify(userIdConfs));
return userIdConfs;
};

Expand All @@ -262,12 +261,10 @@ exports.getUserIdParams = function (params) {
refThis.logWarning(CONSTANTS.MESSAGES.IDENTITY.M3, ex);
}
}
var ssoTimeout = window.PWT && window.PWT.ssoEnabled ? CONSTANTS.CONFIG.SSO_INTEGRATION_TIMEOUT : 0;
ssoTimeout += window.PWT.fbTimeout ? window.PWT.fbTimeout : 0;
if (userIdParams && userIdParams.params && userIdParams.params["loadATS"] == "true") {
setTimeout(function() {
refThis.initLiveRampAts(userIdParams);
}, ssoTimeout);
}, refThis.getSsoTimeout());
}
if(userIdParams && userIdParams.params && userIdParams.params['loadIDP'] == 'true'){
setTimeout(function() {
Expand Down Expand Up @@ -531,6 +528,70 @@ exports.applyDataTypeChangesIfApplicable = function(params) {
}
}

exports.getSsoTimeout = function () {
var ssoTimeout = window.PWT && window.PWT.ssoEnabled ? CONSTANTS.CONFIG.SSO_INTEGRATION_TIMEOUT : 0;
ssoTimeout += window.PWT.fbTimeout ? window.PWT.fbTimeout : 0;
return ssoTimeout;
};

exports.getHashEmailId = function() {
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
return enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;
}

exports.getEncodedUserId = function() {
var userIdentity = owpbjs.getUserIdentities() || {};
return userIdentity && userIdentity.userID ? userIdentity.userID: "";
}

exports.skipUndefinedValues = function (obj){
var newObj = {}
for (prop in obj) {
if (obj[prop]) {
newObj[prop] = obj[prop];
}
}
return newObj;
}

// Specfic to ID5 parnter to create PD string.
exports.createRawPdString = function () {
var emailHashes = refThis.getHashEmailId();
var params = {
1: emailHashes && emailHashes['SHA256'] || undefined, // Email
5: refThis.getEncodedUserId() // UserID
};
return Object.keys(refThis.skipUndefinedValues(params)).map((function(key) {
return params[key] && key + '=' + params[key]
})).join('&');
}

exports.getEncodeString = function (str) {
return str ? btoa(str): "";
}

exports.getEncodedPdString = function(){
return refThis.getEncodeString(refThis.createRawPdString()) ;
}

exports.getCustomParamValues = function(customParam){
var params = {
"params.pd": refThis.getEncodedPdString.bind(refThis)
};
return params[customParam] && refThis.isFunction(params[customParam])? params[customParam]() : "";
};

exports.applyCustomParamFunctionValuesfApplicable = function(partners) {
partners.forEach(function(partner){
var params = CONSTANTS.ID_PARTNERS_CUSTOM_FUNCTION_PARAM_VALUES[partner['name']]
params && params.forEach(function(param){
refThis.getNestedObjectFromString(partner, ".", param.key, refThis.getCustomParamValues(param.key));
});
});
return partners;
};

exports.applyCustomParamValuesfApplicable = function(params) {
if (params.name in CONSTANTS.ID_PARTNERS_CUSTOM_VALUES) {
var partnerValues = CONSTANTS.ID_PARTNERS_CUSTOM_VALUES[params.name];
Expand Down
67 changes: 65 additions & 2 deletions src_new/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,6 @@ exports.getUserIdConfiguration = function(){
userIdConfs.push(refThis.getUserIdParams(partnerValues));
}
});
refThis.log(CONSTANTS.MESSAGES.IDENTITY.M4+ JSON.stringify(userIdConfs));
return userIdConfs;
};
// endRemoveIf(removeUserIdRelatedCode)
Expand Down Expand Up @@ -1383,7 +1382,7 @@ exports.getUserIdParams = function(params){
refThis.logWarning(CONSTANTS.MESSAGES.IDENTITY.M3, ex);
}
}
var ssoTimeout = window.PWT && window.PWT.ssoEnabled ? CONSTANTS.CONFIG.SSO_INTEGRATION_TIMEOUT + 500 : 0;
var ssoTimeout = window.PWT && window.PWT.ssoEnabled ? CONSTANTS.CONFIG.SSO_INTEGRATION_TIMEOUT + CONSTANTS.CONFIG.SSO_ADDITIONAL_TIMEOUT : 0;
// additional timeout of 500ms added for OW profiles. should be removed from here once we start supporting pre-pending code snippet for OW profile.
if (userIdParams && userIdParams.params && userIdParams.params["loadATS"] == "true") {
setTimeout(function() {
Expand Down Expand Up @@ -1806,6 +1805,70 @@ exports.applyDataTypeChangesIfApplicable = function(params) {
}
}

exports.getSsoTimeout = function () {
var ssoTimeout = window.PWT && window.PWT.ssoEnabled ? CONSTANTS.CONFIG.SSO_INTEGRATION_TIMEOUT : 0;
ssoTimeout += window.PWT.fbTimeout ? window.PWT.fbTimeout : 0;
return ssoTimeout;
};

exports.getHashEmailId = function() {
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
return enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;
}

exports.getEncodedUserId = function() {
var userIdentity = owpbjs.getUserIdentities() || {};
return userIdentity && userIdentity.userID ? userIdentity.userID: "";
}

exports.skipUndefinedValues = function (obj){
var newObj = {}
for (prop in obj) {
if (obj[prop]) {
newObj[prop] = obj[prop];
}
}
return newObj;
}

// Specfic to ID5 parnter to create PD string.
exports.createRawPdString = function () {
var emailHashes = refThis.getHashEmailId();
var params = {
1: emailHashes && emailHashes['SHA256'] || undefined, // Email
5: refThis.getEncodedUserId() // UserID
};
return Object.keys(refThis.skipUndefinedValues(params)).map((function(key) {
return params[key] && key + '=' + params[key]
})).join('&');
}

exports.getEncodeString = function (str) {
return str ? btoa(str): "";
}

exports.getEncodedPdString = function(){
return refThis.getEncodeString(refThis.createRawPdString()) ;
}

exports.getCustomParamValues = function(customParam){
var params = {
"params.pd": refThis.getEncodedPdString.bind(refThis)
};
return params[customParam] && refThis.isFunction(params[customParam])? params[customParam]() : "";
};

exports.applyCustomParamFunctionValuesfApplicable = function(partners) {
partners.forEach(function(partner){
var params = CONSTANTS.ID_PARTNERS_CUSTOM_FUNCTION_PARAM_VALUES[partner['name']]
params && params.forEach(function(param){
refThis.getNestedObjectFromString(partner, ".", param.key, refThis.getCustomParamValues(param.key));
});
});
return partners;
};

exports.applyCustomParamValuesfApplicable = function(params) {
if (params.name in CONSTANTS.ID_PARTNERS_CUSTOM_VALUES) {
var partnerValues = CONSTANTS.ID_PARTNERS_CUSTOM_VALUES[params.name];
Expand Down
40 changes: 40 additions & 0 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,46 @@ describe('UTIL', function() {
});
});

describe('#applyCustomParamFunctionValuesfApplicable', function() {
var partners;
beforeEach(function(done) {
partners = [{"name":"id5Id","storage":{"type":"html5","expires":"30","name":"id5id","refreshInSeconds":"28800"},"params":{"partner":173},"display":0}]
function getUserIdentities() {
return {
"emailHash": {
"MD5": "b9ea47bd80a563c9299ca16b2f79405b",
"SHA1": "df0dd701dc1a7ef9dd65d6eca9abfbc1c33abbd1",
"SHA256": "c08a386a01d187e2e3b03489b6553b0d7cf7ac6feb99a92516f9fbde30d0b283"
}
}
}
window.owpbjs = {
getUserIdentities: getUserIdentities
}
done();
});
afterEach(function(done) {
partners = null;
CONFIG.isSSOEnabled.restore();
window.owpbjs = undefined;
done();
});
it('should update the params object with PD with emailhash(SHA256) as value if SSOEnabled is enabled for ID partners', function(done) {
sinon.stub(CONFIG, "isSSOEnabled").returns(true);
UTIL.applyCustomParamFunctionValuesfApplicable(partners);
expect(partners[0]["params"]["pd"]).to.be.defined;
expect(partners[0]["params"]["pd"]).to.be.equal("MT1jMDhhMzg2YTAxZDE4N2UyZTNiMDM0ODliNjU1M2IwZDdjZjdhYzZmZWI5OWE5MjUxNmY5ZmJkZTMwZDBiMjgz");
done();
});

it('should update the params object with PD with empty string if SSOEnabled is not enabled for ID partners', function(done) {
sinon.stub(CONFIG, "isSSOEnabled").returns(false);
UTIL.applyCustomParamFunctionValuesfApplicable(partners);
expect(partners[0]["params"]["pd"]).to.be.defined;
expect(partners[0]["params"]["pd"]).to.be.equal("");
done();
});
});

describe('#getUpdatedKGPVForVideo', function() {
var kgpv, adFormat;
Expand Down