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

Nightly #440

Merged
merged 11 commits into from
Apr 19, 2023
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ gulp.task('bundle-pwt-keys', function() {
"UUID": "hb_uuid",
"CACHE_ID": "hb_cache_id",
"CACHE_HOST": "hb_cache_host",
"ADOMAIN" : "hb_adomain"
"ADOMAIN" : "hb_adomain",
"ACAT": "hb_acat",
}
}
]
Expand Down
21 changes: 19 additions & 2 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports.kgpvMap = kgpvMap;

var refThis = this;
var onEventAdded = false;
var onAuctionEndEventAdded = false;
var isPrebidPubMaticAnalyticsEnabled = CONFIG.isPrebidPubMaticAnalyticsEnabled();
var isSingleImpressionSettingEnabled = CONFIG.isSingleImpressionSettingEnabled();
var defaultAliases = CONSTANTS.DEFAULT_ALIASES;
Expand Down Expand Up @@ -323,9 +324,16 @@ exports.pbBidRequestHandler = pbBidRequestHandler;

// removeIf(removeLegacyAnalyticsRelatedCode)
function pbAuctionEndHandler(args){
window.PWT.newAdUnits = window.PWT.newAdUnits || {};
args.adUnits.forEach(function(adUnit){
if(!!adUnit.pubmaticAutoRefresh){
window.PWT.adUnits[adUnit.code].pubmaticAutoRefresh = adUnit.pubmaticAutoRefresh;
if(!window.PWT.newAdUnits[window.PWT.bidMap[adUnit.code].impressionID]){
window.PWT.newAdUnits[window.PWT.bidMap[adUnit.code].impressionID] = {};
}
if(!window.PWT.newAdUnits[window.PWT.bidMap[adUnit.code].impressionID][adUnit.code]){
window.PWT.newAdUnits[window.PWT.bidMap[adUnit.code].impressionID][adUnit.code] = {}
}
window.PWT.newAdUnits[window.PWT.bidMap[adUnit.code].impressionID][adUnit.code].pubmaticAutoRefresh = adUnit.pubmaticAutoRefresh;
}
});
}
Expand Down Expand Up @@ -968,7 +976,10 @@ exports.addOnBidResponseHandler = addOnBidResponseHandler;
// removeIf(removeLegacyAnalyticsRelatedCode)
function addOnAuctionEndHandler(){
if(util.isFunction(window[pbNameSpace].onEvent)){
window[pbNameSpace].onEvent('auctionEnd', refThis.pbAuctionEndHandler);
if(!onAuctionEndEventAdded){
window[pbNameSpace].onEvent('auctionEnd', refThis.pbAuctionEndHandler);
onAuctionEndEventAdded = true;
}
} else {
util.logWarning("PreBid js onEvent method is not available");
return;
Expand Down Expand Up @@ -1269,12 +1280,18 @@ exports.getPbjsAdServerTargetingConfig = getPbjsAdServerTargetingConfig;

function setPbjsBidderSettingsIfRequired(){
if(isPrebidPubMaticAnalyticsEnabled === false){
window[pbNameSpace].bidderSettings = {
'standard': {
'storageAllowed': true // marking the storage allowed as true for 7.39 upgrade
}
};
return;
}

window[pbNameSpace].bidderSettings = {
'standard': {
'suppressEmptyKeys': true, // this boolean flag can be used to avoid sending those empty values to the ad server.
'storageAllowed': true // marking the storage allowed as true for 7.39 upgrade
}
};

Expand Down
2 changes: 1 addition & 1 deletion src_new/bidManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function analyticalPixelCallback(slotID, bmEntry, impressionIDMap) { // TDD, i/o
"is": refThis.getSlotLevelFrequencyDepth(frequencyDepth, 'impressionServed', adUnitInfo.adUnitId),
"rc": refThis.getSlotLevelFrequencyDepth(frequencyDepth, 'slotCnt', adUnitInfo.adUnitId),
"vw": frequencyDepth && frequencyDepth.viewedSlot && frequencyDepth.viewedSlot[adUnitInfo.adUnitId],
"rf": adUnitInfo.pubmaticAutoRefresh && adUnitInfo.pubmaticAutoRefresh.isRefreshed ? 1 : 0
"rf": window.PWT.newAdUnits ? (window.PWT.newAdUnits[impressionID] ? (window.PWT.newAdUnits[impressionID][slotID] ? (window.PWT.newAdUnits[impressionID][slotID]['pubmaticAutoRefresh'] ? (window.PWT.newAdUnits[impressionID][slotID]['pubmaticAutoRefresh']['isRefreshed'] ? 1: 0 ) : 0): 0 ) : 0 ): 0,
};
bmEntry.setExpired();
impressionIDMap[impressionID] = impressionIDMap[impressionID] || [];
Expand Down
11 changes: 4 additions & 7 deletions src_new/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,10 @@ exports.displayCreative = function(theDocument, bid){
else{
refThis.resizeWindow(theDocument, bid.width, bid.height);
if(bid.adHtml){
if(bid.getAdapterID().toLowerCase() == "appier" || bid.getAdapterID().toLowerCase() == "deepintent"){
bid.adHtml = refThis.replaceAuctionPrice(bid.adHtml, bid.getGrossEcpm());
}
bid.adHtml = refThis.replaceAuctionPrice(bid.adHtml, bid.getGrossEcpm());
theDocument.write(bid.adHtml);
}else if(bid.adUrl){
if(bid.getAdapterID().toLowerCase() == "appier" || bid.getAdapterID().toLowerCase() == "deepintent"){
bid.adUrl = refThis.replaceAuctionPrice(bid.adUrl, bid.getGrossEcpm());
}
bid.adUrl = refThis.replaceAuctionPrice(bid.adUrl, bid.getGrossEcpm());
refThis.writeIframe(theDocument, bid.adUrl, bid.width, bid.height, "");
}else{
refThis.logError("creative details are not found");
Expand Down Expand Up @@ -1544,7 +1540,8 @@ exports.generateMonetizationPixel = function(slotID, theBid){

var origAdUnit = bidManager.getAdUnitInfo(slotID);
adUnitId = origAdUnit.adUnitId || slotID;
var isRefreshed = origAdUnit.pubmaticAutoRefresh && origAdUnit.pubmaticAutoRefresh.isRefreshed ? 1 : 0;
var iiid = window.PWT.bidMap[slotID].getImpressionID();
var isRefreshed = (window.PWT.newAdUnits && window.PWT.newAdUnits[iiid] && window.PWT.newAdUnits[iiid][slotID] && window.PWT.newAdUnits[iiid][slotID]['pubmaticAutoRefresh'] && window.PWT.newAdUnits[iiid][slotID]['pubmaticAutoRefresh']['isRefreshed']) ? 1 : 0;

pixelURL += "pubid=" + pubId;
pixelURL += "&purl=" + window.encodeURIComponent(refThis.metaInfo.pageURL);
Expand Down
21 changes: 14 additions & 7 deletions test/adapters/prebid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1885,17 +1885,24 @@ describe('ADAPTER: Prebid', function() {

beforeEach(function(done) {
window.PWT = {
adUnits: {
"Div1": {
"code": 'Div1'
newAdUnits: {
"123123123":{
"Div1": {
"code": 'Div1'
}
}
},
bidMap:{
"Div1" : {
impressionID: "123123123"
}
}
}
done();
});

afterEach(function(done){
window.PWT.adUnits = {};
window.PWT.newAdUnits = {};
done();
});

Expand All @@ -1906,15 +1913,15 @@ describe('ADAPTER: Prebid', function() {

it('should copy pubmaticAutoRefresh data into window.PWT.adUnit',function(done){
PREBID.pbAuctionEndHandler(auctionArgs);
expect(window.PWT.adUnits["Div1"]["pubmaticAutoRefresh"]).to.be.an.object;
expect(window.PWT.adUnits["Div1"]["pubmaticAutoRefresh"]["isRefreshed"]).to.be.true;
expect(window.PWT.newAdUnits["123123123"]["Div1"]["pubmaticAutoRefresh"]).to.be.an.object;
expect(window.PWT.newAdUnits["123123123"]["Div1"]["pubmaticAutoRefresh"]["isRefreshed"]).to.be.true;
done();
});

it('should not copy pubmaticAutoRefresh data into window.PWT.adUnit when the entry is missing',function(done){
delete auctionArgs.adUnits[0].pubmaticAutoRefresh;
PREBID.pbAuctionEndHandler(auctionArgs);
expect(window.PWT.adUnits["Div1"]["pubmaticAutoRefresh"]).to.be.undefined;
expect(window.PWT.newAdUnits["123123123"]["Div1"]["pubmaticAutoRefresh"]).to.be.undefined;
done();
});
});
Expand Down
12 changes: 9 additions & 3 deletions test/bidManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,9 +1260,15 @@ describe('bidManager BIDMgr', function() {
"divID": slotID,
"code":slotID,
"adUnitId": adUnitId,
"mediaTypes": {'banner': {'sizes': [0]}},
"pubmaticAutoRefresh":{
"isRefreshed": true
"mediaTypes": {'banner': {'sizes': [0]}}
}
},
newAdUnits:{
"123123":{
"Slot_1":{
"pubmaticAutoRefresh":{
"isRefreshed": true
}
}
}
}
Expand Down
30 changes: 4 additions & 26 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,8 @@ describe('UTIL', function() {
},
pbbid:{
mediaType:"banner"
}
},
getGrossEcpm:function(){ return "10.55" }
};
sinon.stub(UTIL, "resizeWindow")
// .returns(true);
Expand Down Expand Up @@ -976,38 +977,15 @@ describe('UTIL', function() {
done();
});

it('should have called replace Auction Price method of the passed object if bid is of APPIER', function(done) {
bid.getAdapterID = function(){ return "appier" };
bid.getGrossEcpm = function(){ return "10.55" };
UTIL.displayCreative(theDocument, bid);
theDocument.write.calledWith(bid.adHtml).should.be.true;
UTIL.replaceAuctionPrice.calledWith(bid.adHtml,bid.getGrossEcpm()).should.be.true;
done();
});

it('should have called replace auction price and writeIframe method if adUrl is present in given bid and adHtml is not and bidder is appier', function(done) {
delete bid.adHtml;
bid.getAdapterID = function(){ return "appier" };
bid.getGrossEcpm = function(){ return "10.55" };
UTIL.displayCreative(theDocument, bid);
UTIL.replaceAuctionPrice.calledWith(bid.adUrl,bid.getGrossEcpm()).should.be.true;
UTIL.writeIframe.calledWith(theDocument, bid.adUrl, bid.width, bid.height, "").should.be.true;
done();
});

it('should have called replace Auction Price method of the passed object if bid is of DeepIntent', function(done) {
bid.getAdapterID = function(){ return "deepintent" };
bid.getGrossEcpm = function(){ return "10.55" };
it('should have called replace Auction Price method of the passed object, irrespective of bidder', function(done) {
UTIL.displayCreative(theDocument, bid);
theDocument.write.calledWith(bid.adHtml).should.be.true;
UTIL.replaceAuctionPrice.calledWith(bid.adHtml,bid.getGrossEcpm()).should.be.true;
done();
});

it('should have called replace auction price and writeIframe method if adUrl is present in given bid and adHtml is not and bidder is DeepIntent', function(done) {
it('should have called replace auction price and writeIframe method if adUrl is present in given bid and adHtml is not, irrespective of bidder', function(done) {
delete bid.adHtml;
bid.getAdapterID = function(){ return "deepintent" };
bid.getGrossEcpm = function(){ return "10.55" };
UTIL.displayCreative(theDocument, bid);
UTIL.replaceAuctionPrice.calledWith(bid.adUrl,bid.getGrossEcpm()).should.be.true;
UTIL.writeIframe.calledWith(theDocument, bid.adUrl, bid.width, bid.height, "").should.be.true;
Expand Down