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

Refreshuserid #340

Open
wants to merge 8 commits into
base: nightly5.x
Choose a base branch
from
3 changes: 1 addition & 2 deletions src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ exports.CONFIG = {
"USE_PREBID_KEYS": "usePBJSKeys",
"AB_TEST_ENABLED": "abTestEnabled",
"TIMEOUT_ADJUSTMENT": 50,
"SSO_ENABLED": "ssoEnabled",
"SSO_INTEGRATION_TIMEOUT": 2500
"SSO_ENABLED": "ssoEnabled"
};

exports.METADATA_MACROS = {
Expand Down
115 changes: 56 additions & 59 deletions src_new/util.idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ exports.addHookOnFunction = function (theObject, useProto, functionName, newFunc

exports.getUserIdConfiguration = function () {
var userIdConfs = [];
owpbjs.onSSOLogin({});
refThis.forEachOnObject(CONFIG.getIdentityPartners(), function (parterId, partnerValues) {
if (!CONSTANTS.EXCLUDE_PARTNER_LIST.includes(parterId)) {
userIdConfs.push(refThis.getUserIdParams(partnerValues));
Expand All @@ -246,7 +247,6 @@ exports.getUserIdParams = function (params) {
var userIdParams = {};
refThis.applyDataTypeChangesIfApplicable(params);
refThis.applyCustomParamValuesfApplicable(params);
owpbjs.onSSOLogin({});
for (var key in params) {
try {
if (CONSTANTS.EXCLUDE_IDENTITY_PARAMS.indexOf(key) == -1) {
Expand All @@ -262,17 +262,11 @@ 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.initLiveRampAts(userIdParams);
}
if(userIdParams && userIdParams.params && userIdParams.params['loadIDP'] == 'true'){
setTimeout(function() {
refThis.initZeoTapJs(userIdParams);
}, 0);
refThis.initZeoTapJs(userIdParams);
}
return userIdParams;
};
Expand Down Expand Up @@ -349,48 +343,55 @@ exports.getNestedObjectFromString = function (sourceObject, separator, key, valu
return sourceObject;
};

exports.getLiverampParams = function(params) {
if (params.params.cssSelectors && params.params.cssSelectors.length > 0) {
params.params.cssSelectors = params.params.cssSelectors.split(",");
}
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
var detectionMechanism = params.params.detectionMechanism;
var enableCustomId = params.params.enableCustomId === "true" ? true : false;
var atsObject = {
"placementID": params.params.pid,
"storageType": params.params.storageType,
"logging": params.params.logging //"error"
};
if (enableCustomId) {
atsObject.accountID = params.params.accountID;
atsObject.customerIDRegex = params.params.customerIDRegex;
atsObject.detectionSubject = "customerIdentifier";
}

switch (detectionMechanism) {
case undefined:
case 'detect':
atsObject.detectionType = params.params.detectionType;
atsObject.urlParameter = params.params.urlParameter;
atsObject.cssSelectors = params.params.cssSelectors;
atsObject.detectDynamicNodes = params.params.detectDynamicNodes;
break;
case 'direct':
var emailHash = enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected indentation of 3 tabs but found 4.

Suggested change
var emailHash = enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;
var emailHash = enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;

atsObject.emailHashes = emailHash && [emailHash['MD5'], emailHash['SHA1'], emailHash['SHA256']] || undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected indentation of 3 tabs but found 4.

Suggested change
atsObject.emailHashes = emailHash && [emailHash['MD5'], emailHash['SHA1'], emailHash['SHA256']] || undefined;
atsObject.emailHashes = emailHash && [emailHash['MD5'], emailHash['SHA1'], emailHash['SHA256']] || undefined;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Strings must use doublequote.

Suggested change
atsObject.emailHashes = emailHash && [emailHash['MD5'], emailHash['SHA1'], emailHash['SHA256']] || undefined;
atsObject.emailHashes = emailHash && [emailHash["MD5"], emailHash['SHA1'], emailHash['SHA256']] || undefined;

/* do we want to keep sso data under direct option?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Expected indentation of 2 tabs but found 3.

Suggested change
/* do we want to keep sso data under direct option?
/* do we want to keep sso data under direct option?

if yes, if sso is enabled and 'direct' is selected as detection mechanism, sso emails will be sent to ats script.
if sso is disabled, and 'direct' is selected as detection mechanism, we will look for publisher provided email ids, and if available the hashes will be sent to ats script.
*/
if (enableCustomId && refThis.isFunction(owpbjs.getUserIdentities) && owpbjs.getUserIdentities() !== undefined) {
atsObject.customerID = owpbjs.getUserIdentities().customerID || undefined;
}
break;
};
return atsObject;
};

exports.initLiveRampAts = function (params) {
function addATS() {
var atsScript = document.createElement("script");
if (params.params.cssSelectors && params.params.cssSelectors.length > 0) {
params.params.cssSelectors = params.params.cssSelectors.split(",");
}
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
var detectionMechanism = params.params.detectionMechanism;
var customIdSupport = params.params.customIdSupport === "1" ? true : false;
var atsObject = {
"placementID": params.params.pid,
"storageType": params.params.storageType,
"logging": params.params.logging //"error"
};
switch (detectionMechanism) {
case undefined:
case 'detect':
atsObject.detectionType = params.params.detectionType;
atsObject.urlParameter = params.params.urlParameter;
atsObject.cssSelectors = params.params.cssSelectors;
atsObject.detectDynamicNodes = params.params.detectDynamicNodes;
break;
case 'direct':
if (customIdSupport) {
if (parseInt(params.params.accountId) === NaN) {
utils.logWarning("Liveramp ATS.js - customID is enabled, but accountID param missing. Ignoring customId config")
} else {
atsObject.accountID = params.params.accountID;
}
}
break;
};

var atsObject = refThis.getLiverampParams(params);
atsScript.onload = function () {
userIdentity = owpbjs.getUserIdentities() || {};
atsObject.emailHashes = enableSSO && userIdentity.emailHash ? [userIdentity.emailHash['MD5'], userIdentity.emailHash['SHA1'], userIdentity.emailHash['SHA256']] : undefined;
/*if (detectionMechanism === "direct" && customIdSupport && !isNaN(parseInt(params.params.accountId))) {
atsObject.customID = userIdentity.emailHash['SHA256'];
}*/
window.ats.start(atsObject);
console.log("object sent to ats script - ", atsObject);
window.ats && window.ats.start(atsObject);
};
atsScript.src = "https://ats.rlcdn.com/ats.js";
document.body.appendChild(atsScript);
Expand All @@ -409,25 +410,21 @@ exports.initZeoTapJs = function(params) {
var n = document, t = window;
var userIdentity = owpbjs.getUserIdentities() || {};
var userIdentityObject = {
email: userIdentity.email || "",
cellno: userIdentity.cellNo || "",
loginid: userIdentity.loginId || "",
fpuid: userIdentity.fpuid || "",
cellno_cc: userIdentity.cellNoCC || ""
email: userIdentity.emailHash || ""
};
var e=n.createElement("script");
var initialsationObject = {
partnerId:params.partnerId,
allowIDP: true,
useConsent: (CONFIG.getCCPA() || CONFIG.getGdpr()),
checkForCMP: (CONFIG.getCCPA() || CONFIG.getGdpr())
};
e.type="text/javascript",
e.crossorigin="anonymous"
e.async=!0 ,
e.src="https://content.zeotap.com/sdk/idp.min.js",
e.onload=function(){};
n=n.getElementsByTagName("script")[0];
var initialsationObject = {
partnerId:params.partnerId,
allowIDP: true,
useConsent: (CONFIG.getCCPA() || CONFIG.getGdpr()),
checkForCMP: (CONFIG.getCCPA() || CONFIG.getGdpr())
};
n.parentNode.insertBefore(e,n);

n=t.zeotap||{_q:[],_qcmp:[]};
Expand All @@ -441,8 +438,8 @@ exports.initZeoTapJs = function(params) {
}(t[o])
}(n,["callMethod"],"_q"),
t.zeotap=n,
t.zeotap.callMethod("init",initialsationObject)
t.zeotap.callMethod("setUserIdentities",userIdentityObject);
t.zeotap.callMethod("init",initialsationObject),
t.zeotap.callMethod("setUserIdentities",userIdentityObject, true);
}

if (document.readyState == 'complete') {
Expand Down
115 changes: 56 additions & 59 deletions src_new/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ exports.getConfigFromRegex = function(klmsForPartner, generatedKey){
// removeIf(removeUserIdRelatedCode)
exports.getUserIdConfiguration = function(){
var userIdConfs = [];
owpbjs.onSSOLogin({});
refThis.forEachOnObject(CONFIG.getIdentityPartners(),function(parterId, partnerValues){
if (CONSTANTS.EXCLUDE_PARTNER_LIST.indexOf(parterId) < 0) {
userIdConfs.push(refThis.getUserIdParams(partnerValues));
Expand Down Expand Up @@ -1366,7 +1367,6 @@ exports.getUserIdParams = function(params){
var userIdParams= {};
refThis.applyDataTypeChangesIfApplicable(params);
refThis.applyCustomParamValuesfApplicable(params);
owpbjs.onSSOLogin({});
for(var key in params){
try{
if(CONSTANTS.EXCLUDE_IDENTITY_PARAMS.indexOf(key) == -1) {
Expand All @@ -1383,17 +1383,12 @@ 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;
// 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() {
refThis.initLiveRampAts(userIdParams);
}, ssoTimeout);
refThis.initLiveRampAts(userIdParams);
}
if(userIdParams && userIdParams.params && userIdParams.params['loadIDP'] == 'true'){
setTimeout(function() {
refThis.initZeoTapJs(userIdParams);
}, 0);
}
return userIdParams;
};
Expand Down Expand Up @@ -1643,49 +1638,55 @@ exports.updateUserIds = function(bid){
}
};
// endRemoveIf(removeIdHubOnlyRelatedCode)
exports.getLiverampParams = function(params) {
if (params.params.cssSelectors && params.params.cssSelectors.length > 0) {
params.params.cssSelectors = params.params.cssSelectors.split(",");
}
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
var detectionMechanism = params.params.detectionMechanism;
var enableCustomId = params.params.enableCustomId === "true" ? true : false;
var atsObject = {
"placementID": params.params.pid,
"storageType": params.params.storageType,
"logging": params.params.logging //"error"
};
if (enableCustomId) {
atsObject.accountID = params.params.accountID;
atsObject.customerIDRegex = params.params.customerIDRegex;
atsObject.detectionSubject = "customerIdentifier";
}

switch (detectionMechanism) {
case undefined:
case 'detect':
atsObject.detectionType = params.params.detectionType;
atsObject.urlParameter = params.params.urlParameter;
atsObject.cssSelectors = params.params.cssSelectors;
atsObject.detectDynamicNodes = params.params.detectDynamicNodes;
break;
case 'direct':
var emailHash = enableSSO && userIdentity.emailHash ? userIdentity.emailHash : userIdentity.pubProvidedEmailHash ? userIdentity.pubProvidedEmailHash : undefined;
atsObject.emailHashes = emailHash && [emailHash['MD5'], emailHash['SHA1'], emailHash['SHA256']] || undefined;
/* do we want to keep sso data under direct option?
if yes, if sso is enabled and 'direct' is selected as detection mechanism, sso emails will be sent to ats script.
if sso is disabled, and 'direct' is selected as detection mechanism, we will look for publisher provided email ids, and if available the hashes will be sent to ats script.
*/
if (enableCustomId && refThis.isFunction(owpbjs.getUserIdentities) && owpbjs.getUserIdentities() !== undefined) {
atsObject.customerID = owpbjs.getUserIdentities().customerID || undefined;
}
break;
};
return atsObject;
};

exports.initLiveRampAts = function (params) {
function addATS() {
var atsScript = document.createElement("script");
if (params.params.cssSelectors && params.params.cssSelectors.length > 0) {
params.params.cssSelectors = params.params.cssSelectors.split(",");
}
var userIdentity = owpbjs.getUserIdentities() || {};
var enableSSO = CONFIG.isSSOEnabled() || false;
var detectionMechanism = params.params.detectionMechanism;
var customIdSupport = params.params.customIdSupport === "1" ? true : false;
var atsObject = {
"placementID": params.params.pid,
"storageType": params.params.storageType,
"logging": params.params.logging //"error"
};
switch (detectionMechanism) {
case undefined:
case 'detect':
atsObject.detectionType = params.params.detectionType;
atsObject.urlParameter = params.params.urlParameter;
atsObject.cssSelectors = params.params.cssSelectors;
atsObject.detectDynamicNodes = params.params.detectDynamicNodes;
break;
case 'direct':
if (customIdSupport) {
if (parseInt(params.params.accountId) === NaN) {
utils.logWarning("Liveramp ATS.js - customID is enabled, but accountID param missing. Ignoring customId config")
} else {
atsObject.accountID = params.params.accountID;
}
}
break;
};

var atsObject = refThis.getLiverampParams(params);
atsScript.onload = function () {
userIdentity = owpbjs.getUserIdentities() || {};
atsObject.emailHashes = enableSSO && userIdentity.emailHash ? [userIdentity.emailHash['MD5'], userIdentity.emailHash['SHA1'], userIdentity.emailHash['SHA256']] : undefined;
/* -- need this code for customid support
if (detectionMechanism === "direct" && customIdSupport && !isNaN(parseInt(params.params.accountId))) {
atsObject.customID = userIdentity.emailHash['SHA256'];
}*/
window.ats.start(atsObject);
console.log("object sent to ats script - ", atsObject);
window.ats && window.ats.start(atsObject);
};
atsScript.src = "https://ats.rlcdn.com/ats.js";
document.body.appendChild(atsScript);
Expand All @@ -1704,25 +1705,21 @@ exports.initZeoTapJs = function(params) {
var n = document, t = window;
var userIdentity = owpbjs.getUserIdentities() || {};
var userIdentityObject = {
email: userIdentity.email || "",
cellno: userIdentity.cellNo || "",
loginid: userIdentity.loginId || "",
fpuid: userIdentity.fpuid || "",
cellno_cc: userIdentity.cellNoCC || ""
email: userIdentity.emailHash || ""
};
var e=n.createElement("script");
var initialsationObject = {
partnerId:params.partnerId,
allowIDP: true,
useConsent: (CONFIG.getCCPA() || CONFIG.getGdpr()),
checkForCMP: (CONFIG.getCCPA() || CONFIG.getGdpr())
};
e.type="text/javascript",
e.crossorigin="anonymous"
e.async=!0 ,
e.src="https://content.zeotap.com/sdk/idp.min.js",
e.onload=function(){};
n=n.getElementsByTagName("script")[0];
var initialsationObject = {
partnerId:params.partnerId,
allowIDP: true,
useConsent: (CONFIG.getCCPA() || CONFIG.getGdpr()),
checkForCMP: (CONFIG.getCCPA() || CONFIG.getGdpr())
};
n.parentNode.insertBefore(e,n);

n=t.zeotap||{_q:[],_qcmp:[]};
Expand All @@ -1736,8 +1733,8 @@ exports.initZeoTapJs = function(params) {
}(t[o])
}(n,["callMethod"],"_q"),
t.zeotap=n,
t.zeotap.callMethod("init",initialsationObject)
t.zeotap.callMethod("setUserIdentities",userIdentityObject);
t.zeotap.callMethod("init",initialsationObject),
t.zeotap.callMethod("setUserIdentities",userIdentityObject, true);
}

if (document.readyState == 'complete') {
Expand Down
Loading