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

changes to support customid and direct vs detect for liveramp #325

Open
wants to merge 6 commits into
base: nightly5.x
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion src_new/bidManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,25 @@ exports.getAdUnitAdFormats = getAdUnitAdFormats;
/* end-test-block */
// endRemoveIf(removeLegacyAnalyticsRelatedCode)

// removeIf(removeLegacyAnalyticsRelatedCode)
function getAdDomain(bidResponse) {
if (bidResponse.meta && bidResponse.meta.advertiserDomains && bidResponse.meta.advertiserDomains.length > 0) {
var adomain = bidResponse.meta.advertiserDomains[0];

if (adomain) {
try {
var hostname = new URL(adomain);
return hostname.hostname.replace('www.', '');
} catch (e) {
util.log("Adomain URL (Not a proper URL):"+ adomain);
return adomain.split('/')[0].replace('www.', '');
}
}
}
}
// endRemoveIf(removeLegacyAnalyticsRelatedCode)


// removeIf(removeLegacyAnalyticsRelatedCode)
function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o : done
var startTime = bmEntry.getCreationTime() || 0;
Expand Down Expand Up @@ -589,7 +608,8 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
"di": theBid.getDealID(),
"dc": theBid.getDealChannel(),
"l1": theBid.getServerSideStatus() ? theBid.getServerSideResponseTime() : (endTime - startTime),
"l2": 0,
"l2": 0,
"adv": pbbid ? getAdDomain(pbbid) || undefined : undefined,
"ss": theBid.getServerSideStatus(),
"t": theBid.getPostTimeoutStatus() === false ? 0 : 1,
"wb": theBid.getWinningBidStatus() === true ? 1 : 0,
Expand Down
2 changes: 1 addition & 1 deletion src_new/controllers/idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ refThis.setConfig = function(){
};
}
window.PWT.ssoEnabled = CONFIG.isSSOEnabled() || false;
if(CONFIG.isUserIdModuleEnabled()){
if(CONFIG.isUserIdModuleEnabled()) {
prebidConfig["userSync"]["userIds"] = util.getUserIdConfiguration();
}
// Adding a hook for publishers to modify the Prebid Config we have generated
Expand Down
2 changes: 2 additions & 0 deletions src_new/owt.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,6 @@ window.PWT.setAuctionTimeout = function(timeout){

window.PWT.versionDetails = util.getOWConfig();

window.PWT.getAdapterNameForAlias = CONFIG.getAdapterNameForAlias;

controller.init(window);
79 changes: 43 additions & 36 deletions src_new/util.idhub.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,47 +349,54 @@ 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;
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'];
}*/
console.log("object sent to ats script - ", atsObject);
window.ats.start(atsObject);
};
atsScript.src = "https://ats.rlcdn.com/ats.js";
Expand Down
80 changes: 43 additions & 37 deletions src_new/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1643,48 +1643,54 @@ 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'];
}*/
console.log("object sent to ats script - ", atsObject);
window.ats.start(atsObject);
};
atsScript.src = "https://ats.rlcdn.com/ats.js";
Expand Down
2 changes: 2 additions & 0 deletions test/bidManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ describe('bidManager BIDMgr', function() {
sinon.spy(theBid, "getDealChannel");
sinon.spy(theBid, "getPostTimeoutStatus");
sinon.spy(theBid, "getWinningBidStatus");
sinon.stub(theBid, "getPbBid").returns({meta: {advertiserDomains : ["startab.com"]}});
theBid.setWinningBidStatus();
bmEntryObj.setNewBid("audienceNetwork", theBid);
CONFIG.getBidPassThroughStatus.returns(2);
Expand All @@ -1742,6 +1743,7 @@ describe('bidManager BIDMgr', function() {
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].di).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].dc).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].l1).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].adv).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].l2).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].t).to.exist;
expect(impressionIDMap[bmEntryObj.getImpressionID()][0]["ps"][0].wb).to.exist;
Expand Down
Loading