From 632c8c1c34bee8d26f568f8e99981e3cf0d87858 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 10:21:49 +0100 Subject: [PATCH 01/45] add stickyadsTV bidder adapter --- src/adapters/stickyadstv.js | 263 ++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 src/adapters/stickyadstv.js diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js new file mode 100644 index 00000000000..748701cb856 --- /dev/null +++ b/src/adapters/stickyadstv.js @@ -0,0 +1,263 @@ +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader.js'); + +var StickyAdsTVAdapter = function StickyAdsTVAdapter() { + + var MUSTANG_URL = "http://cdn.stickyadstv.com/mustang/mustang.min.js"; + var INTEXTROLL_URL = "http://cdn.stickyadstv.com/prime-time/intext-roll.min.js"; + var SCREENROLL_URL = "http://cdn.stickyadstv.com/prime-time/screen-roll.min.js"; + + window.stickyadstv_cache = {}; + + function _callBids(params) { + + var bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + var bid = bids[i]; + // Send out bid request for each bid given its tag IDs and query strings + sendBidRequest(bid); + + } + } + + function sendBidRequest(bid){ + + var placementCode = bid.placementCode; + + var integrationType = bid.params.format ? bid.params.format : "inbanner"; + var urltoLoad = MUSTANG_URL; + + if(integrationType === "intext-roll"){ + urltoLoad = INTEXTROLL_URL; + } + if(integrationType === "screen-roll"){ + urltoLoad = SCREENROLL_URL; + } + + var bidRegistered = false; + adloader.loadScript(urltoLoad, function(){ + + getBid(bid, function(bidObject){ + if(!bidRegistered){ + bidRegistered = true; + onBidReceived(placementCode, bidObject); + } + + }); + }, true); + } + + function getBid(bid, callback){ + var zoneId = bid.params.zoneId || bid.params.zone; //accept both + var size = getBiggerSize(bid.sizes); + + var vastLoader = new window.com.stickyadstv.vast.VastLoader(); + bid.vast = window.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); + + var vastCallback = { + onSuccess : bind(function(){ + //'this' is the bid here + var bid = this; + + var adHtml = formatAdHTML(bid,size); + var price = extractPrice(bid.vast); + + callback(formatBidObject(true, price, adHtml, size[0], size[1])); + + },bid), + onError : bind(function(){ + callback(formatBidObject(false)); + },bid) + }; + + var config = { + zoneId:zoneId, + playerSize:size[0]+"x"+size[1], + vastUrlParams: bid.params.vastUrlParams, + componentId: "prebid-sticky-"+bid.params.format + }; + + if(bid.params.format === "screen-roll"){ + //in screenroll case we never use the original div size. + config.playerSize = window.com.stickyadstv.screenroll.getPlayerSize(); + } + + vastLoader.load(config, vastCallback); + } + + function getBiggerSize(array){ + var result = [1,1]; + for(var i = 0; i< array.length; i++){ + if(array[i][0]*array[i][1] > result[0]*result[1]){ + result = array[i]; + } + } + return result; + } + + var formatInBannerHTML = function(bid,size){ + var placementCode = bid.placementCode; + + var divHtml = "
"; + + var script = ""; + + return divHtml+script; + }; + + var formatIntextHTML = function(bid){ + var placementCode = bid.placementCode; + + var config = bid.params; + + //default placement if no placement is set + if(!config.hasOwnProperty("domId") && !config.hasOwnProperty("auto") && !config.hasOwnProperty("p") && !config.hasOwnProperty("article")){ + config.domId = placementCode; + } + + var script = ""; + + return script; + }; + + var formatScreenRollHTML = function(bid){ + var placementCode = bid.placementCode; + + var config = bid.params; + + var script = ""; + + return script; + }; + + function formatAdHTML(bid, size){ + + var integrationType = bid.params.format; + + var html = ""; + if(integrationType === "intext-roll"){ + html = formatIntextHTML(bid); + } + else if(integrationType === "screen-roll"){ + html = formatScreenRollHTML(bid); + } + else { + html = formatInBannerHTML(bid,size); + } + + return html; + } + + + function extractPrice(vast){ + var priceData = vast.getPricing(); + + if(!priceData) + { + console.warn("StickyAdsTV: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your sticky contact."); + } + + return priceData; + } + + function formatBidObject(valid, priceData, html, width, height){ + var bidObject; + if(valid && priceData) { + // valid bid response + bidObject = bidfactory.createBid(1); + bidObject.bidderCode = 'stickyadstv'; + bidObject.cpm = priceData.price; + bidObject.currencyCode = priceData.currency; + bidObject.ad = html; + bidObject.width = width; + bidObject.height = height; + + } + else { + // invalid bid response + bidObject = bidfactory.createBid(2); + bidObject.bidderCode = 'stickyadstv'; + } + return bidObject; + } + + function onBidReceived(placementCode, bidObject){ + + console.log("Add Bid response:"+ bidObject); + // send the bidResponse object to bid manager with the adUnitCode. + bidmanager.addBidResponse(placementCode, bidObject); + + } + + /* Create a function bound to a given object (assigning `this`, and arguments, + * optionally). Binding with arguments is also known as `curry`. + * Delegates to **ECMAScript 5**'s native `Function.bind` if available. + * We check for `func.bind` first, to fail fast when `func` is undefined. + * + * @param {function} func + * @param {optional} context + * @param {...any} var_args + * @return {function} + */ + var bind = function(func, context) { + + return function() { + return func.apply(context,arguments); + }; + }; + + // Export the callBids function, so that prebid.js can execute + // this function when the page asks to send out bid requests. + return { + callBids: _callBids + }; +}; + +module.exports = StickyAdsTVAdapter; \ No newline at end of file From a91ac2d34afdca9039eb1210be2f8ad94157860f Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 14:26:27 +0100 Subject: [PATCH 02/45] init unit test file --- adapters-sticky.json | 3 + src/adapters/stickyadstv.js | 18 ++- test/spec/adapters/stickyadstv_spec.js | 158 +++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 adapters-sticky.json create mode 100644 test/spec/adapters/stickyadstv_spec.js diff --git a/adapters-sticky.json b/adapters-sticky.json new file mode 100644 index 00000000000..5f410194f87 --- /dev/null +++ b/adapters-sticky.json @@ -0,0 +1,3 @@ +[ + "stickyadstv" +] diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 748701cb856..46ed372e14f 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -4,9 +4,9 @@ var adloader = require('../adloader.js'); var StickyAdsTVAdapter = function StickyAdsTVAdapter() { - var MUSTANG_URL = "http://cdn.stickyadstv.com/mustang/mustang.min.js"; - var INTEXTROLL_URL = "http://cdn.stickyadstv.com/prime-time/intext-roll.min.js"; - var SCREENROLL_URL = "http://cdn.stickyadstv.com/prime-time/screen-roll.min.js"; + var MUSTANG_URL = "//cdn.stickyadstv.com/mustang/mustang.min.js"; + var INTEXTROLL_URL = "//cdn.stickyadstv.com/prime-time/intext-roll.min.js"; + var SCREENROLL_URL = "//cdn.stickyadstv.com/prime-time/screen-roll.min.js"; window.stickyadstv_cache = {}; @@ -16,7 +16,13 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { for (var i = 0; i < bids.length; i++) { var bid = bids[i]; // Send out bid request for each bid given its tag IDs and query strings - sendBidRequest(bid); + + if(bid.placementCode && bid.params.zoneId) { + sendBidRequest(bid); + } + else { + console.warn("StickyAdsTV: Missing mandatory field(s)."); + } } } @@ -39,6 +45,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { adloader.loadScript(urltoLoad, function(){ getBid(bid, function(bidObject){ + if(!bidRegistered){ bidRegistered = true; onBidReceived(placementCode, bidObject); @@ -199,8 +206,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { function extractPrice(vast){ var priceData = vast.getPricing(); - if(!priceData) - { + if(!priceData) { console.warn("StickyAdsTV: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your sticky contact."); } diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js new file mode 100644 index 00000000000..1bf862238fa --- /dev/null +++ b/test/spec/adapters/stickyadstv_spec.js @@ -0,0 +1,158 @@ +import {expect} from 'chai'; +import {assert} from 'chai'; +import Adapter from '../../../src/adapters/stickyadstv'; +import bidManager from '../../../src/bidmanager'; +import adLoader from '../../../src/adloader'; + +describe('StickyAdsTV Adapter', function () { + var adapter = void 0; + var sandbox = void 0; + var bidsRequestBuff = void 0; + var bidderRequest = { + bidderCode: 'stickyadstv', + bids: [{ + bidId: 'bidId1', + bidder: 'stickyadstv', + placementCode: 'foo', + sizes: [[300, 250]], + params: { + zoneId: '2003' + } + }, { + bidId: 'bidId2', + bidder: 'stickyadstv', + placementCode: 'bar', + sizes: [[728, 90]], + params: { + zoneId: '5562003' + } + }, { + bidId: 'bidId3', + bidder: 'stickyadstv', + placementCode: '', + sizes: [[300, 600]], + params: { + zoneId: '123456' + } + }, { + bidId: 'bidId4', + bidder: 'stickyadstv', + placementCode: 'coo', + sizes: [[300, 600]], + params: { + wrong: "missing zoneId" + } + }] + }; + + beforeEach(function () { + adapter = new Adapter(); + sandbox = sinon.sandbox.create(); + bidsRequestBuff = pbjs._bidsRequested; + pbjs._bidsRequested = []; + }); + + afterEach(function () { + sandbox.restore(); + pbjs._bidsRequested = bidsRequestBuff; + }); + + describe('callBids', function () { + beforeEach(function () { + sandbox.stub(adLoader, 'loadScript'); + adapter.callBids(bidderRequest); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + + it('should have load the mustang script', function () { + var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); + }); + }); + + describe('getbids', function () { + beforeEach(function () { + adapter.getbids(); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + }); + + describe('Bid response', function () { + var vzBidRequest = void 0; + var bidderReponse = { + "vzhPlacementId": "VZ-HB-123", + "bid": "0fac1b8a-6ba0-4641-bd57-2899b1bedeae_0", + "adWidth": "300", + "adHeight": "250", + "cpm": "1.00000000000000", + "ad": "
", + "slotBidId": "bidId1", + "nurl": "", + "statusText": "vertoz:success" + }; + + beforeEach(function () { + pbjs._bidsRequested.push(bidderRequest); + }); + + describe('success', function () { + var firstBidReg = void 0; + var adSpaceId = void 0; + + beforeEach(function () { + sandbox.stub(_bidmanager2['default'], 'addBidResponse'); + pbjs.vzResponse(bidderReponse); + firstBidReg = bidManager.addBidResponse.firstCall.args[1]; + adSpaceId = bidManager.addBidResponse.firstCall.args[0]; + }); + + it('cpm to have property 1.000000', function () { + (0, _chai.expect)(firstBidReg).to.have.property('cpm', 1.00); + }); + it('adSpaceId should exist and be equal to placementCode', function () { + (0, _chai.expect)(adSpaceId).to.equal("foo"); + }); + it('should have property ad', function () { + (0, _chai.expect)(firstBidReg).to.have.property('ad'); + }); + it('should include the size to the bid object', function () { + (0, _chai.expect)(firstBidReg).to.have.property('width', '300'); + (0, _chai.expect)(firstBidReg).to.have.property('height', '250'); + }); + }); + + describe('failure', function () { + var secondBidReg = void 0; + var adSpaceId = void 0; + var bidderResponse = { + "vzhPlacementId": "VZ-HB-456", + "slotBidId": "bidId2", + "statusText": "vertoz:NO_BIDS" + }; + + beforeEach(function () { + sandbox.stub(bidManager, 'addBidResponse'); + pbjs.vzResponse(bidderResponse); + secondBidReg = bidManager.addBidResponse.firstCall.args[1]; + adSpaceId = bidManager.addBidResponse.firstCall.args[0]; + }); + + it('should not have cpm property', function () { + (0, _chai.expect)(secondBidReg.cpm).to.be.undefined; + }); + it('adSpaceId should exist and be equal to placementCode', function () { + (0, _chai.expect)(adSpaceId).to.equal("bar"); + }); + it('should not have ad property', function () { + (0, _chai.expect)(secondBidReg.ad).to.be.undefined; + }); + }); + }); +}); \ No newline at end of file From 9e2d70ea29379115ad970079ccc1141138fcb905 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 17:44:03 +0100 Subject: [PATCH 03/45] ad some unit tests --- src/adapters/stickyadstv.js | 4 +- test/spec/adapters/stickyadstv_spec.js | 267 +++++++++++-------------- 2 files changed, 121 insertions(+), 150 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 46ed372e14f..98554a7f31f 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -262,7 +262,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { // Export the callBids function, so that prebid.js can execute // this function when the page asks to send out bid requests. return { - callBids: _callBids + callBids: _callBids, + formatBidObject: formatBidObject, + formatAdHTML: formatAdHTML }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 1bf862238fa..9d619abcf09 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -5,154 +5,123 @@ import bidManager from '../../../src/bidmanager'; import adLoader from '../../../src/adloader'; describe('StickyAdsTV Adapter', function () { - var adapter = void 0; - var sandbox = void 0; - var bidsRequestBuff = void 0; - var bidderRequest = { - bidderCode: 'stickyadstv', - bids: [{ - bidId: 'bidId1', - bidder: 'stickyadstv', - placementCode: 'foo', - sizes: [[300, 250]], - params: { - zoneId: '2003' - } - }, { - bidId: 'bidId2', - bidder: 'stickyadstv', - placementCode: 'bar', - sizes: [[728, 90]], - params: { - zoneId: '5562003' - } - }, { - bidId: 'bidId3', - bidder: 'stickyadstv', - placementCode: '', - sizes: [[300, 600]], - params: { - zoneId: '123456' - } - }, { - bidId: 'bidId4', - bidder: 'stickyadstv', - placementCode: 'coo', - sizes: [[300, 600]], - params: { - wrong: "missing zoneId" - } - }] - }; + var adapter = void 0; + var sandbox = void 0; + var bidsRequestBuff = void 0; + var bidderRequest = { + bidderCode: 'stickyadstv', + bids: [{ + bidId: 'bidId1', + bidder: 'stickyadstv', + placementCode: 'foo', + sizes: [[300, 250]], + params: { + zoneId: '2003' + } + }, { + bidId: 'bidId2', + bidder: 'stickyadstv', + placementCode: 'bar', + sizes: [[728, 90]], + params: { + zoneId: '5562003' + } + }, { + bidId: 'bidId3', + bidder: 'stickyadstv', + placementCode: '', + sizes: [[300, 600]], + params: { + zoneId: '123456' + } + }, { + bidId: 'bidId4', + bidder: 'stickyadstv', + placementCode: 'coo', + sizes: [[300, 600]], + params: { + wrong: "missing zoneId" + } + }] + }; + + beforeEach(function () { + adapter = new Adapter(); + sandbox = sinon.sandbox.create(); + bidsRequestBuff = pbjs._bidsRequested; + pbjs._bidsRequested = []; + }); + + afterEach(function () { + sandbox.restore(); + pbjs._bidsRequested = bidsRequestBuff; + }); + + describe('callBids', function () { + beforeEach(function () { + sandbox.stub(adLoader, 'loadScript'); + adapter.callBids(bidderRequest); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + + it('should have load the mustang script', function () { + var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); + }); + }); + + describe('formatBidObject', function () { + + it('should create a valid bid object', function () { + let result = adapter.formatBidObject(true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + + expect(result).to.have.property('cpm', '1.2345'); + expect(result).to.have.property('ad', "
sample
"); + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result).to.have.property('currencyCode', "EUR"); + expect(result).to.have.property('width', 200); + expect(result).to.have.property('height', 300); + expect(result.getStatusCode()).to.equal(1); + }); + + it('should create a invalid bid object because price is not defined', function () { + let result = adapter.formatBidObject(true, null, "
sample
", 200, 300); + + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result.getStatusCode()).to.equal(2); + }); + + it('should create a invalid bid object', function () { + let result = adapter.formatBidObject(false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result.getStatusCode()).to.equal(2); + }); + }); + + describe('formatAdHTML', function () { + + it('should create an inBanner ad format', function () { + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{}}, [200,300]); + + expect(result).to.equal('
'); + }); + + it('should create an intext ad format', function () { + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"intext-roll", auto:"v2", smartPlay:"true"}}, [200,300]); + + expect(result).to.equal(""); + }); + + it('should create a screenroll ad format', function () { + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll"}}, [200,300]); + + expect(result).to.equal(""); + }); + }); - beforeEach(function () { - adapter = new Adapter(); - sandbox = sinon.sandbox.create(); - bidsRequestBuff = pbjs._bidsRequested; - pbjs._bidsRequested = []; - }); - - afterEach(function () { - sandbox.restore(); - pbjs._bidsRequested = bidsRequestBuff; - }); - - describe('callBids', function () { - beforeEach(function () { - sandbox.stub(adLoader, 'loadScript'); - adapter.callBids(bidderRequest); - }); - - it('should be called twice', function () { - sinon.assert.calledTwice(adLoader.loadScript); - }); - - it('should have load the mustang script', function () { - var url = void 0; - url = adLoader.loadScript.firstCall.args[0]; - expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); - }); - }); - - describe('getbids', function () { - beforeEach(function () { - adapter.getbids(); - }); - - it('should be called twice', function () { - sinon.assert.calledTwice(adLoader.loadScript); - }); - }); - - describe('Bid response', function () { - var vzBidRequest = void 0; - var bidderReponse = { - "vzhPlacementId": "VZ-HB-123", - "bid": "0fac1b8a-6ba0-4641-bd57-2899b1bedeae_0", - "adWidth": "300", - "adHeight": "250", - "cpm": "1.00000000000000", - "ad": "
", - "slotBidId": "bidId1", - "nurl": "", - "statusText": "vertoz:success" - }; - - beforeEach(function () { - pbjs._bidsRequested.push(bidderRequest); - }); - - describe('success', function () { - var firstBidReg = void 0; - var adSpaceId = void 0; - - beforeEach(function () { - sandbox.stub(_bidmanager2['default'], 'addBidResponse'); - pbjs.vzResponse(bidderReponse); - firstBidReg = bidManager.addBidResponse.firstCall.args[1]; - adSpaceId = bidManager.addBidResponse.firstCall.args[0]; - }); - - it('cpm to have property 1.000000', function () { - (0, _chai.expect)(firstBidReg).to.have.property('cpm', 1.00); - }); - it('adSpaceId should exist and be equal to placementCode', function () { - (0, _chai.expect)(adSpaceId).to.equal("foo"); - }); - it('should have property ad', function () { - (0, _chai.expect)(firstBidReg).to.have.property('ad'); - }); - it('should include the size to the bid object', function () { - (0, _chai.expect)(firstBidReg).to.have.property('width', '300'); - (0, _chai.expect)(firstBidReg).to.have.property('height', '250'); - }); - }); - - describe('failure', function () { - var secondBidReg = void 0; - var adSpaceId = void 0; - var bidderResponse = { - "vzhPlacementId": "VZ-HB-456", - "slotBidId": "bidId2", - "statusText": "vertoz:NO_BIDS" - }; - - beforeEach(function () { - sandbox.stub(bidManager, 'addBidResponse'); - pbjs.vzResponse(bidderResponse); - secondBidReg = bidManager.addBidResponse.firstCall.args[1]; - adSpaceId = bidManager.addBidResponse.firstCall.args[0]; - }); - - it('should not have cpm property', function () { - (0, _chai.expect)(secondBidReg.cpm).to.be.undefined; - }); - it('adSpaceId should exist and be equal to placementCode', function () { - (0, _chai.expect)(adSpaceId).to.equal("bar"); - }); - it('should not have ad property', function () { - (0, _chai.expect)(secondBidReg.ad).to.be.undefined; - }); - }); - }); }); \ No newline at end of file From 9c92c3e852c47a0412d470e8e90fbcb89a6626b6 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 18:22:43 +0100 Subject: [PATCH 04/45] fix unit test on ad format with parameters --- test/spec/adapters/stickyadstv_spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 9d619abcf09..19557bd2755 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -114,13 +114,13 @@ describe('StickyAdsTV Adapter', function () { it('should create an intext ad format', function () { let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"intext-roll", auto:"v2", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(""); }); it('should create a screenroll ad format', function () { - let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll"}}, [200,300]); + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(""); }); }); From 7ed68e95c81d8590442f66e0277a72196ba8fa50 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 15:31:54 +0100 Subject: [PATCH 05/45] add some unit tests --- src/adapters/stickyadstv.js | 13 +++---------- test/spec/adapters/stickyadstv_spec.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 98554a7f31f..fb5a0841ae8 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -48,7 +48,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { if(!bidRegistered){ bidRegistered = true; - onBidReceived(placementCode, bidObject); + bidmanager.addBidResponse(placementCode, bidObject); } }); @@ -234,14 +234,6 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return bidObject; } - function onBidReceived(placementCode, bidObject){ - - console.log("Add Bid response:"+ bidObject); - // send the bidResponse object to bid manager with the adUnitCode. - bidmanager.addBidResponse(placementCode, bidObject); - - } - /* Create a function bound to a given object (assigning `this`, and arguments, * optionally). Binding with arguments is also known as `curry`. * Delegates to **ECMAScript 5**'s native `Function.bind` if available. @@ -264,7 +256,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return { callBids: _callBids, formatBidObject: formatBidObject, - formatAdHTML: formatAdHTML + formatAdHTML: formatAdHTML, + getBiggerSize:getBiggerSize }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 19557bd2755..6972e4d8bc0 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -120,7 +120,17 @@ describe('StickyAdsTV Adapter', function () { it('should create a screenroll ad format', function () { let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(""); + }); + }); + + describe('getBiggerSize', function () { + + it('should returns the bigger size', function () { + let result = adapter.getBiggerSize([[1,4000],[4000,1],[200,300],[0,0]]); + + expect(result[0]).to.equal(200); + expect(result[1]).to.equal(300); }); }); From 88a45ac96f8c3fe445cf0ac26d06d2ab90eaaeca Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 16:01:41 +0100 Subject: [PATCH 06/45] add unit tests on getBid method --- src/adapters/stickyadstv.js | 3 +- test/spec/adapters/stickyadstv_spec.js | 56 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index fb5a0841ae8..30b818215da 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -257,7 +257,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { callBids: _callBids, formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, - getBiggerSize:getBiggerSize + getBiggerSize:getBiggerSize, + getBid:getBid }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 6972e4d8bc0..5f262224312 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -74,6 +74,62 @@ describe('StickyAdsTV Adapter', function () { }); }); + describe('getBid', function () { + let bidRespone; + let getPricingCalled; + + beforeEach(function () { + //Mock VastLoader for test purpose + window.com = { + stickyadstv : { + vast : { + VastLoader : function(){ + this.getVast = function(){ + return { + getPricing : function(){ + getPricingCalled = true; + return {currency:"USD", price: 4.000} + } + }; + }; + + this.load = function(config, listener){ + listener.onSuccess(); + }; + } + } + } + }; + + adapter.getBid(bidderRequest.bids[0], function(bidObject){ + bidRespone = bidObject; + }); + }); + + afterEach(function() { + delete window.com.stickyadstv.vast.VastLoader; + delete window.com.stickyadstv.vast; + delete window.com.stickyadstv; + }); + + it('should have returned a valid bidObject', function () { + + expect(bidRespone).to.have.property('cpm', 4.000); + expect(bidRespone).to.have.property('ad', "
"); + expect(bidRespone).to.have.property('bidderCode', "stickyadstv"); + expect(bidRespone).to.have.property('currencyCode', "USD"); + expect(bidRespone).to.have.property('width', 300); + expect(bidRespone).to.have.property('height', 250); + expect(bidRespone.getStatusCode()).to.equal(1); + }); + + it('should have called getPricing', function () { + + expect(getPricingCalled).to.equal(true); + + }); + }); + describe('formatBidObject', function () { it('should create a valid bid object', function () { From 7d6bf3c3484391c841d67eb8b7c6269720a92eec Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 16:21:40 +0100 Subject: [PATCH 07/45] add some test cases in unit tests --- test/spec/adapters/stickyadstv_spec.js | 42 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 5f262224312..6869f1264dd 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -16,7 +16,8 @@ describe('StickyAdsTV Adapter', function () { placementCode: 'foo', sizes: [[300, 250]], params: { - zoneId: '2003' + zoneId: '2003', + format:"screen-roll" } }, { bidId: 'bidId2', @@ -67,15 +68,20 @@ describe('StickyAdsTV Adapter', function () { sinon.assert.calledTwice(adLoader.loadScript); }); - it('should have load the mustang script', function () { + it('should have load screenroll and mustang script', function () { var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/prime-time/screen-roll.min.js"); + + url = adLoader.loadScript.secondCall.args[0]; expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); }); }); describe('getBid', function () { - let bidRespone; + let bidResponse; + let loadConfig; let getPricingCalled; beforeEach(function () { @@ -94,33 +100,47 @@ describe('StickyAdsTV Adapter', function () { }; this.load = function(config, listener){ + loadConfig = config; listener.onSuccess(); }; } + }, + screenroll : { + getPlayerSize: function(){ + return "123x456"; + } } } }; adapter.getBid(bidderRequest.bids[0], function(bidObject){ - bidRespone = bidObject; + bidResponse = bidObject; }); }); afterEach(function() { delete window.com.stickyadstv.vast.VastLoader; delete window.com.stickyadstv.vast; + delete window.com.stickyadstv.screenroll; delete window.com.stickyadstv; }); it('should have returned a valid bidObject', function () { - expect(bidRespone).to.have.property('cpm', 4.000); - expect(bidRespone).to.have.property('ad', "
"); - expect(bidRespone).to.have.property('bidderCode', "stickyadstv"); - expect(bidRespone).to.have.property('currencyCode', "USD"); - expect(bidRespone).to.have.property('width', 300); - expect(bidRespone).to.have.property('height', 250); - expect(bidRespone.getStatusCode()).to.equal(1); + expect(bidResponse).to.have.property('cpm', 4.000); + expect(bidResponse).to.have.property('ad', ""); + expect(bidResponse).to.have.property('bidderCode', "stickyadstv"); + expect(bidResponse).to.have.property('currencyCode', "USD"); + expect(bidResponse).to.have.property('width', 300); + expect(bidResponse).to.have.property('height', 250); + expect(bidResponse.getStatusCode()).to.equal(1); + }); + + it('should have called load with proper config', function () { + + expect(loadConfig).to.have.property('playerSize', "123x456"); + expect(loadConfig).to.have.property('zoneId', "2003"); + }); it('should have called getPricing', function () { From affdd67a855f8d9cb3e5a45b80f4f6c6f24ff392 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 9 Jan 2017 15:24:58 +0100 Subject: [PATCH 08/45] minor fix on component id tag. --- adapters.json | 1 + src/adapters/stickyadstv.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/adapters.json b/adapters.json index a49141c8345..f28bfab3af2 100644 --- a/adapters.json +++ b/adapters.json @@ -29,6 +29,7 @@ "sonobi", "sovrn", "springserve", + "stickyadstv", "triplelift", "yieldbot", "nginad", diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 30b818215da..7fe851285db 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -82,7 +82,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId:zoneId, playerSize:size[0]+"x"+size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: "prebid-sticky-"+bid.params.format + componentId: "prebid-sticky"+(bid.params.format ? "-"+bid.params.format : "") }; if(bid.params.format === "screen-roll"){ From 654a473048b43719a6a0fa7dc87d3ef8a86d439a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 12 Jan 2017 10:16:54 +0100 Subject: [PATCH 09/45] remove adapters-sticky.json test file --- adapters-sticky.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 adapters-sticky.json diff --git a/adapters-sticky.json b/adapters-sticky.json deleted file mode 100644 index 5f410194f87..00000000000 --- a/adapters-sticky.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - "stickyadstv" -] From 8c0f1438605ddfcaa1d2b8bdd49294566cc573fc Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 26 Jan 2017 16:17:18 +0100 Subject: [PATCH 10/45] use top most accessible window instead of window.top --- src/adapters/stickyadstv.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 7fe851285db..b682b16b3f4 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -109,13 +109,14 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var divHtml = "
"; var script = ""; @@ -135,7 +136,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; @@ -163,7 +165,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; From fd877dc69095241a554c4e6f53c5351750925867 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 26 Jan 2017 16:35:38 +0100 Subject: [PATCH 11/45] Pass in the bid request in the createBid call. --- src/adapters/stickyadstv.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index b682b16b3f4..647f3a14662 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -64,17 +64,17 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var vastCallback = { onSuccess : bind(function(){ - //'this' is the bid here - var bid = this; + //'this' is the bid request here + var bidRequest = this; - var adHtml = formatAdHTML(bid,size); - var price = extractPrice(bid.vast); + var adHtml = formatAdHTML(bidRequest,size); + var price = extractPrice(bidRequest.vast); - callback(formatBidObject(true, price, adHtml, size[0], size[1])); + callback(formatBidObject(bidRequest, true, price, adHtml, size[0], size[1])); },bid), onError : bind(function(){ - callback(formatBidObject(false)); + callback(formatBidObject(bidRequest, false)); },bid) }; @@ -216,11 +216,11 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return priceData; } - function formatBidObject(valid, priceData, html, width, height){ + function formatBidObject(bidRequest, valid, priceData, html, width, height){ var bidObject; if(valid && priceData) { // valid bid response - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(1, bidRequest); bidObject.bidderCode = 'stickyadstv'; bidObject.cpm = priceData.price; bidObject.currencyCode = priceData.currency; @@ -231,7 +231,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } else { // invalid bid response - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, bidRequest); bidObject.bidderCode = 'stickyadstv'; } return bidObject; From 09f7348fe3e7ff4d4d444c40ce05b9001c36d75a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 16:49:51 +0100 Subject: [PATCH 12/45] use top most accessible window instead of window.top --- src/adapters/stickyadstv.js | 47 +++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 647f3a14662..90fbf569e55 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -8,7 +8,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var INTEXTROLL_URL = "//cdn.stickyadstv.com/prime-time/intext-roll.min.js"; var SCREENROLL_URL = "//cdn.stickyadstv.com/prime-time/screen-roll.min.js"; - window.stickyadstv_cache = {}; + var topMostWindow = getTopMostWindow(); + topMostWindow.stickyadstv_cache = {}; function _callBids(params) { @@ -64,6 +65,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var vastCallback = { onSuccess : bind(function(){ + //'this' is the bid request here var bidRequest = this; @@ -74,6 +76,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { },bid), onError : bind(function(){ + var bidRequest = this; callback(formatBidObject(bidRequest, false)); },bid) }; @@ -109,14 +112,14 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var divHtml = "
"; var script = ""; @@ -135,9 +138,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } var script = ""; @@ -165,8 +168,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; @@ -237,6 +241,24 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return bidObject; } + + /** + * returns the top most accessible window + */ + function getTopMostWindow(){ + var res=window; + + try { + while(top != res){ + if(res.parent.location.href.length) + res=res.parent; + } + } + catch(e){} + + return res; + } + /* Create a function bound to a given object (assigning `this`, and arguments, * optionally). Binding with arguments is also known as `curry`. * Delegates to **ECMAScript 5**'s native `Function.bind` if available. @@ -254,6 +276,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { }; }; + // Export the callBids function, so that prebid.js can execute // this function when the page asks to send out bid requests. return { From 90264e8c34cef8344a1cc68893f6244729a17f23 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 16:58:07 +0100 Subject: [PATCH 13/45] add unit tests --- src/adapters/stickyadstv.js | 3 ++- test/spec/adapters/stickyadstv_spec.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 90fbf569e55..3408af5e23b 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -284,7 +284,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, getBiggerSize:getBiggerSize, - getBid:getBid + getBid:getBid, + getTopMostWindow:getTopMostWindow }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 6869f1264dd..3fa253eca32 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -210,4 +210,13 @@ describe('StickyAdsTV Adapter', function () { }); }); + describe('top most window', function () { + + it('should returns the top most window', function () { + let result = adapter.getTopMostWindow(); + + expect(result).to.equal(window.top); + }); + }); + }); \ No newline at end of file From 29453af7cf5e0e19001c4080a216be5baeec937f Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 17:23:23 +0100 Subject: [PATCH 14/45] update unit tests --- test/spec/adapters/stickyadstv_spec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 3fa253eca32..eb665ec658c 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -128,7 +128,7 @@ describe('StickyAdsTV Adapter', function () { it('should have returned a valid bidObject', function () { expect(bidResponse).to.have.property('cpm', 4.000); - expect(bidResponse).to.have.property('ad', ""); + expect(bidResponse).to.have.property('ad', ""); expect(bidResponse).to.have.property('bidderCode', "stickyadstv"); expect(bidResponse).to.have.property('currencyCode', "USD"); expect(bidResponse).to.have.property('width', 300); @@ -153,7 +153,7 @@ describe('StickyAdsTV Adapter', function () { describe('formatBidObject', function () { it('should create a valid bid object', function () { - let result = adapter.formatBidObject(true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + let result = adapter.formatBidObject("", true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); expect(result).to.have.property('cpm', '1.2345'); expect(result).to.have.property('ad', "
sample
"); @@ -165,14 +165,14 @@ describe('StickyAdsTV Adapter', function () { }); it('should create a invalid bid object because price is not defined', function () { - let result = adapter.formatBidObject(true, null, "
sample
", 200, 300); + let result = adapter.formatBidObject("", true, null, "
sample
", 200, 300); expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); it('should create a invalid bid object', function () { - let result = adapter.formatBidObject(false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + let result = adapter.formatBidObject("", false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); @@ -184,19 +184,19 @@ describe('StickyAdsTV Adapter', function () { it('should create an inBanner ad format', function () { let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{}}, [200,300]); - expect(result).to.equal('
'); + expect(result).to.equal('
'); }); it('should create an intext ad format', function () { let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"intext-roll", auto:"v2", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(''); }); it('should create a screenroll ad format', function () { let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(''); }); }); From b664ee1e883416502ca398e3d5b1363373ee4046 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 17:33:23 +0100 Subject: [PATCH 15/45] fix unit test. --- src/adapters/stickyadstv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 3408af5e23b..baf910e386e 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -61,7 +61,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var size = getBiggerSize(bid.sizes); var vastLoader = new window.com.stickyadstv.vast.VastLoader(); - bid.vast = window.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); + bid.vast = topMostWindow.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); var vastCallback = { onSuccess : bind(function(){ From 57c31a1208459b3b0de61cb01b0f5a92b43ed9d3 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 6 Feb 2017 09:49:19 +0100 Subject: [PATCH 16/45] fix CI build --- src/adapters/stickyadstv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index baf910e386e..803cd626d56 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -249,7 +249,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var res=window; try { - while(top != res){ + while(top !== res){ if(res.parent.location.href.length) res=res.parent; } From 475eee312693498b6b8ec7e2c35eaa0c0420af98 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 2 Mar 2017 14:25:12 +0100 Subject: [PATCH 17/45] add alias freewheel-ssp --- adapters.json | 5 +++++ src/adapters/stickyadstv.js | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/adapters.json b/adapters.json index dc7796ea482..6b711d02aae 100644 --- a/adapters.json +++ b/adapters.json @@ -107,6 +107,11 @@ "getintent": { "supportedMediaTypes" : ["video"] } + }, + { + "stickyadstv": { + "alias": "freewheel-ssp" + } } ] diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 803cd626d56..221898df1f0 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -1,9 +1,11 @@ +var Adapter = require('./adapter.js'); var bidfactory = require('../bidfactory.js'); var bidmanager = require('../bidmanager.js'); var adloader = require('../adloader.js'); var StickyAdsTVAdapter = function StickyAdsTVAdapter() { + var STICKYADS_BIDDERCODE = 'stickyadstv'; var MUSTANG_URL = "//cdn.stickyadstv.com/mustang/mustang.min.js"; var INTEXTROLL_URL = "//cdn.stickyadstv.com/prime-time/intext-roll.min.js"; var SCREENROLL_URL = "//cdn.stickyadstv.com/prime-time/screen-roll.min.js"; @@ -225,7 +227,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { if(valid && priceData) { // valid bid response bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = 'stickyadstv'; + bidObject.bidderCode = bidRequest.bidder; bidObject.cpm = priceData.price; bidObject.currencyCode = priceData.currency; bidObject.ad = html; @@ -236,7 +238,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { else { // invalid bid response bidObject = bidfactory.createBid(2, bidRequest); - bidObject.bidderCode = 'stickyadstv'; + bidObject.bidderCode = bidRequest.bidder; } return bidObject; } @@ -277,16 +279,19 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { }; - // Export the callBids function, so that prebid.js can execute - // this function when the page asks to send out bid requests. - return { + return Object.assign(Adapter.createNew(STICKYADS_BIDDERCODE), { callBids: _callBids, formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, getBiggerSize:getBiggerSize, getBid:getBid, - getTopMostWindow:getTopMostWindow - }; + getTopMostWindow:getTopMostWindow, + createNew: StickyAdsTVAdapter.createNew //enable alias feature (to be used for freewheel-ssp alias) + }); +}; + +StickyAdsTVAdapter.createNew = function() { + return new StickyAdsTVAdapter(); }; module.exports = StickyAdsTVAdapter; \ No newline at end of file From 410ee003e22d5f9cfba346d538348239ab5164d5 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 10 Mar 2017 16:33:24 +0100 Subject: [PATCH 18/45] update unit tests on bidderCode value --- test/spec/adapters/stickyadstv_spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index eb665ec658c..b485416f614 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -157,7 +157,6 @@ describe('StickyAdsTV Adapter', function () { expect(result).to.have.property('cpm', '1.2345'); expect(result).to.have.property('ad', "
sample
"); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result).to.have.property('currencyCode', "EUR"); expect(result).to.have.property('width', 200); expect(result).to.have.property('height', 300); @@ -167,14 +166,12 @@ describe('StickyAdsTV Adapter', function () { it('should create a invalid bid object because price is not defined', function () { let result = adapter.formatBidObject("", true, null, "
sample
", 200, 300); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); it('should create a invalid bid object', function () { let result = adapter.formatBidObject("", false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); }); From b09dfdd9077bbe07db119b3138d0f484614bd2ed Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 16 Jun 2017 11:21:54 +0200 Subject: [PATCH 19/45] fix component id values and add unit tests --- src/adapters/stickyadstv.js | 14 +++++++++++++- test/spec/adapters/stickyadstv_spec.js | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index d0095541a8f..55162532f17 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -77,7 +77,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId: zoneId, playerSize: size[0] + 'x' + size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: 'prebid-sticky' + (bid.params.format ? '-' + bid.params.format : '') + componentId: getComponentId(bid.params.format); }; if (bid.params.format === 'screen-roll') { @@ -88,6 +88,17 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { vastLoader.load(config, vastCallback); } + function getComponentId(inputFormat) { + var component = "mustang"; //default component id + + if(inputFormat == FORMAT_INTEXT || inputFormat == FORMAT_SCREEN){ + //format identifiers are equals to their component ids. + component = inputFormat; + } + + return component; + } + function getBiggerSize(array) { var result = [1, 1]; for (var i = 0; i < array.length; i++) { @@ -263,6 +274,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBiggerSize: getBiggerSize, getBid: getBid, getTopMostWindow: getTopMostWindow, + getComponentId: getComponentId, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 96a589ea07d..74438c2b0aa 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -206,4 +206,12 @@ describe('StickyAdsTV Adapter', function () { expect(result).to.equal(window.top); }); }); + + describe('get component id', function(){ + it('should returns valid component ids', function(){ + expect(adapter.getComponentId("inbanner")).to.equal("mustang"); + expect(adapter.getComponentId("intext-roll")).to.equal("intext-roll"); + expect(adapter.getComponentId("screen-roll")).to.equal("screen-roll"); + }); + }); }); From d52df6f193a0c965257ab73ca296a48ae1ae87cb Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 10:45:42 +0200 Subject: [PATCH 20/45] allws to use any outstream format. --- src/adapters/stickyadstv.js | 81 ++++++++++---------------- test/spec/adapters/stickyadstv_spec.js | 10 ++++ 2 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 55162532f17..a48c184af16 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -6,8 +6,7 @@ var adloader = require('../adloader.js'); var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var STICKYADS_BIDDERCODE = 'stickyadstv'; var MUSTANG_URL = '//cdn.stickyadstv.com/mustang/mustang.min.js'; - var INTEXTROLL_URL = '//cdn.stickyadstv.com/prime-time/intext-roll.min.js'; - var SCREENROLL_URL = '//cdn.stickyadstv.com/prime-time/screen-roll.min.js'; + var OUTSTREAM_URL = '//cdn.stickyadstv.com/prime-time/[COMP-ID].min.js'; var topMostWindow = getTopMostWindow(); topMostWindow.stickyadstv_cache = {}; @@ -32,11 +31,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var integrationType = bid.params.format ? bid.params.format : 'inbanner'; var urltoLoad = MUSTANG_URL; - if (integrationType === 'intext-roll') { - urltoLoad = INTEXTROLL_URL; - } - if (integrationType === 'screen-roll') { - urltoLoad = SCREENROLL_URL; + if (integrationType !== 'inbanner') { + // integration types are equals to component ids + urltoLoad = OUTSTREAM_URL.replace('[COMP-ID]', integrationType); } var bidRegistered = false; @@ -54,6 +51,12 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var zoneId = bid.params.zoneId || bid.params.zone; // accept both var size = getBiggerSize(bid.sizes); + // some of our formats doesn't have tools API exposed + var toolsAPI = window.com.stickyadstv.tools; + if (toolsAPI && toolsAPI.ASLoader) { + topMostWindow.stickyadstv_asLoader = new toolsAPI.ASLoader(zoneId, getComponentId(bid.params.format)); + } + var vastLoader = new window.com.stickyadstv.vast.VastLoader(); bid.vast = topMostWindow.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); @@ -77,28 +80,36 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId: zoneId, playerSize: size[0] + 'x' + size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: getComponentId(bid.params.format); + componentId: getComponentId(bid.params.format) }; - if (bid.params.format === 'screen-roll') { - // in screenroll case we never use the original div size. - config.playerSize = window.com.stickyadstv.screenroll.getPlayerSize(); + var api = window.com.stickyadstv[getAPIName(bid.params.format)]; + if (api && typeof api.getPlayerSize === 'function') { + // in screenroll and similar cases we don't use the original div size. + config.playerSize = api.getPlayerSize(); } vastLoader.load(config, vastCallback); } function getComponentId(inputFormat) { - var component = "mustang"; //default component id + var component = 'mustang'; // default component id - if(inputFormat == FORMAT_INTEXT || inputFormat == FORMAT_SCREEN){ - //format identifiers are equals to their component ids. + if(inputFormat && inputFormat !== 'inbanner'){ + // format identifiers are equals to their component ids. component = inputFormat; } return component; } + function getAPIName(componentId) { + componentId = componentId || ""; + + //remove dash in componentId to get API name + return componentId.replace('-',''); + } + function getBiggerSize(array) { var result = [1, 1]; for (var i = 0; i < array.length; i++) { @@ -123,6 +134,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { ' autoPlay:true' + '};' + 'var ad = new topWindow.com.stickyadstv.vpaid.Ad(document.getElementById("stickyadstv_prebid_target"),config);' + + 'if(topWindow.stickyadstv_asLoader) topWindow.stickyadstv_asLoader.registerEvents(ad);'+ 'ad.initAd(' + size[0] + ',' + size[1] + ',"",0,"","");' + ''; @@ -130,7 +142,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return divHtml + script; }; - var formatIntextHTML = function(bid) { + var formatOutstreamHTML = function(bid) { var placementCode = bid.placementCode; var config = bid.params; @@ -156,50 +168,20 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.intextroll.start(config);' + + 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config, topWindow.stickyadstv_asLoader);' + ''; return script; }; - var formatScreenRollHTML = function(bid) { - var placementCode = bid.placementCode; - - var config = bid.params; - - var script = "'; - - return script; - }; function formatAdHTML(bid, size) { var integrationType = bid.params.format; var html = ''; - if (integrationType === 'intext-roll') { - html = formatIntextHTML(bid); - } else if (integrationType === 'screen-roll') { - html = formatScreenRollHTML(bid); + if (integrationType && integrationType !== 'inbanner') { + html = formatOutstreamHTML(bid); } else { html = formatInBannerHTML(bid, size); } @@ -211,7 +193,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var priceData = vast.getPricing(); if (!priceData) { - console.warn("StickyAdsTV: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your sticky contact."); + console.warn("freewheel-ssp: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your Freewheel contact."); } return priceData; @@ -275,6 +257,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBid: getBid, getTopMostWindow: getTopMostWindow, getComponentId: getComponentId, + getAPIName:getAPIName, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 74438c2b0aa..46d5fa4a8bb 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -214,4 +214,14 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getComponentId("screen-roll")).to.equal("screen-roll"); }); }); + + describe('get API name', function(){ + it('should returns valid component ids', function(){ + expect(adapter.getAPIName()).to.equal(""); + expect(adapter.getAPIName("intext-roll")).to.equal("intextroll"); + expect(adapter.getAPIName("screen-roll")).to.equal("screenroll"); + expect(adapter.getAPIName("floorad")).to.equal("floorad"); + }); + }); + }); From 9ad2b7f65d3df6494c47a1025aac0600b533923e Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 11:15:08 +0200 Subject: [PATCH 21/45] fix ASLoader on futur outstream format versions --- src/adapters/stickyadstv.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index a48c184af16..457a9bf4412 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -157,7 +157,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { 'var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})();' + 'var vast = topWindow.stickyadstv_cache["' + placementCode + '"];' + 'var config = {' + - ' preloadedVast:vast'; + ' preloadedVast:vast,'+ + ' ASLoader:topWindow.stickyadstv_asLoader'; for (var key in config) { // dont' send format parameter @@ -168,7 +169,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config, topWindow.stickyadstv_asLoader);' + + 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config);' + ''; From 427b45c37a91c1c6a2224ce437d054d2fa4f519a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 11:24:18 +0200 Subject: [PATCH 22/45] minor: fix code format. --- src/adapters/stickyadstv.js | 16 ++++++++-------- test/spec/adapters/stickyadstv_spec.js | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 457a9bf4412..c747db57555 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -95,7 +95,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { function getComponentId(inputFormat) { var component = 'mustang'; // default component id - if(inputFormat && inputFormat !== 'inbanner'){ + if (inputFormat && inputFormat !== 'inbanner') { // format identifiers are equals to their component ids. component = inputFormat; } @@ -104,10 +104,10 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } function getAPIName(componentId) { - componentId = componentId || ""; + componentId = componentId || ''; - //remove dash in componentId to get API name - return componentId.replace('-',''); + // remove dash in componentId to get API name + return componentId.replace('-', ''); } function getBiggerSize(array) { @@ -134,7 +134,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { ' autoPlay:true' + '};' + 'var ad = new topWindow.com.stickyadstv.vpaid.Ad(document.getElementById("stickyadstv_prebid_target"),config);' + - 'if(topWindow.stickyadstv_asLoader) topWindow.stickyadstv_asLoader.registerEvents(ad);'+ + 'if(topWindow.stickyadstv_asLoader) topWindow.stickyadstv_asLoader.registerEvents(ad);' + 'ad.initAd(' + size[0] + ',' + size[1] + ',"",0,"","");' + ''; @@ -157,7 +157,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { 'var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})();' + 'var vast = topWindow.stickyadstv_cache["' + placementCode + '"];' + 'var config = {' + - ' preloadedVast:vast,'+ + ' preloadedVast:vast,' + ' ASLoader:topWindow.stickyadstv_asLoader'; for (var key in config) { @@ -169,7 +169,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config);' + + 'topWindow.com.stickyadstv.' + getAPIName(bid.params.format) + '.start(config);' + ''; @@ -258,7 +258,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBid: getBid, getTopMostWindow: getTopMostWindow, getComponentId: getComponentId, - getAPIName:getAPIName, + getAPIName: getAPIName, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 46d5fa4a8bb..4d7b9d82a3d 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -207,21 +207,21 @@ describe('StickyAdsTV Adapter', function () { }); }); - describe('get component id', function(){ - it('should returns valid component ids', function(){ - expect(adapter.getComponentId("inbanner")).to.equal("mustang"); - expect(adapter.getComponentId("intext-roll")).to.equal("intext-roll"); - expect(adapter.getComponentId("screen-roll")).to.equal("screen-roll"); + describe('get component id', function() { + it('should returns valid component ids', function() { + expect(adapter.getComponentId('inbanner')).to.equal('mustang'); + expect(adapter.getComponentId('intext-roll')).to.equal('intext-roll'); + expect(adapter.getComponentId('screen-roll')).to.equal('screen-roll'); }); }); - describe('get API name', function(){ - it('should returns valid component ids', function(){ - expect(adapter.getAPIName()).to.equal(""); - expect(adapter.getAPIName("intext-roll")).to.equal("intextroll"); - expect(adapter.getAPIName("screen-roll")).to.equal("screenroll"); - expect(adapter.getAPIName("floorad")).to.equal("floorad"); + describe('get API name', function() { + it('should returns valid component ids', function() { + expect(adapter.getAPIName()).to.equal(''); + expect(adapter.getAPIName('intext-roll')).to.equal('intextroll'); + expect(adapter.getAPIName('screen-roll')).to.equal('screenroll'); + expect(adapter.getAPIName('floorad')).to.equal('floorad'); }); }); - -}); + +}); \ No newline at end of file From c65c62d59c04fb66c982d5e806e6e74f8e653141 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 14:36:56 +0200 Subject: [PATCH 23/45] update unit tests --- test/spec/adapters/stickyadstv_spec.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 4d7b9d82a3d..83e43a9fbe1 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -125,9 +125,9 @@ describe('StickyAdsTV Adapter', function () { delete window.com.stickyadstv; }); - it('should have returned a valid bidObject', function () { + it('should return a valid bidObject', function () { expect(bidResponse).to.have.property('cpm', 4.000); - expect(bidResponse).to.have.property('ad', ""); + expect(bidResponse).to.have.property('ad', ""); expect(bidResponse).to.have.property('bidderCode', 'stickyadstv'); expect(bidResponse).to.have.property('currencyCode', 'USD'); expect(bidResponse).to.have.property('width', 300); @@ -174,24 +174,24 @@ describe('StickyAdsTV Adapter', function () { it('should create an inBanner ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {}}, [200, 300]); - expect(result).to.equal('
'); + expect(result).to.equal('
'); }); it('should create an intext ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'intext-roll', auto: 'v2', smartPlay: 'true'}}, [200, 300]); - expect(result).to.equal(''); + expect(result).to.equal(''); }); it('should create a screenroll ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'screen-roll', smartPlay: 'true'}}, [200, 300]); - expect(result).to.equal(''); + expect(result).to.equal(''); }); }); describe('getBiggerSize', function () { - it('should returns the bigger size', function () { + it('should return the bigger size', function () { let result = adapter.getBiggerSize([[1, 4000], [4000, 1], [200, 300], [0, 0]]); expect(result[0]).to.equal(200); @@ -200,7 +200,7 @@ describe('StickyAdsTV Adapter', function () { }); describe('top most window', function () { - it('should returns the top most window', function () { + it('should return the top most window', function () { let result = adapter.getTopMostWindow(); expect(result).to.equal(window.top); @@ -208,7 +208,7 @@ describe('StickyAdsTV Adapter', function () { }); describe('get component id', function() { - it('should returns valid component ids', function() { + it('should return valid component ids', function() { expect(adapter.getComponentId('inbanner')).to.equal('mustang'); expect(adapter.getComponentId('intext-roll')).to.equal('intext-roll'); expect(adapter.getComponentId('screen-roll')).to.equal('screen-roll'); @@ -216,7 +216,7 @@ describe('StickyAdsTV Adapter', function () { }); describe('get API name', function() { - it('should returns valid component ids', function() { + it('should return valid API names', function() { expect(adapter.getAPIName()).to.equal(''); expect(adapter.getAPIName('intext-roll')).to.equal('intextroll'); expect(adapter.getAPIName('screen-roll')).to.equal('screenroll'); From 23639ff187434c01c010c0716d9eaa9f6591f679 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 14:52:07 +0200 Subject: [PATCH 24/45] minor fix code format --- test/spec/adapters/stickyadstv_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 83e43a9fbe1..e3dc5c0a8ac 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -223,5 +223,4 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getAPIName('floorad')).to.equal('floorad'); }); }); - }); \ No newline at end of file From 7b2ff6709aeb0d5d0f9edec56d5944a8eb4c987e Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 18:29:32 +0200 Subject: [PATCH 25/45] minor: add missing new line at eof --- test/spec/adapters/stickyadstv_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index e3dc5c0a8ac..0a4866862d7 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -223,4 +223,4 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getAPIName('floorad')).to.equal('floorad'); }); }); -}); \ No newline at end of file +}); From ecaff5e105e0a7145d9b1253f860216aa9295fab Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 27 Oct 2017 18:03:25 +0200 Subject: [PATCH 26/45] replace StickyAdsTVAdapter by freewheel ssp bd adapter (for prebid 1.0) --- modules/freewheelSSPBidAdapter.js | 295 ++++++++++++++++++ modules/freewheelSSPBidAdapter.md | 27 ++ modules/stickyadstvBidAdapter.js | 269 ---------------- .../modules/freewheelSSPBidAdapter_spec.js | 194 ++++++++++++ 4 files changed, 516 insertions(+), 269 deletions(-) create mode 100644 modules/freewheelSSPBidAdapter.js create mode 100644 modules/freewheelSSPBidAdapter.md delete mode 100644 modules/stickyadstvBidAdapter.js create mode 100644 test/spec/modules/freewheelSSPBidAdapter_spec.js diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js new file mode 100644 index 00000000000..9cb2fe41a81 --- /dev/null +++ b/modules/freewheelSSPBidAdapter.js @@ -0,0 +1,295 @@ +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; +// import { config } from 'src/config'; + +const BIDDER_CODE = 'freewheel-ssp'; + +const PROTOCOL = getProtocol(); +const FREEWHEEL_ADSSETUP = PROTOCOL + '://ads.stickyadstv.com/www/delivery/swfIndex.php'; +const MUSTANG_URL = PROTOCOL + '://cdn.stickyadstv.com/mustang/mustang.min.js'; +const PRIMETIME_URL = PROTOCOL + '://cdn.stickyadstv.com/prime-time/'; + +function getProtocol() { + if (location.protocol && location.protocol.indexOf('https') === 0) { + return 'https'; + } else { + return 'http'; + } +} + +function isValidUrl(str) { + if (!str) { + return false; + } + + // regExp for url validation + var pattern = /^(https?|ftp|file):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/; + return pattern.test(str); +} + +function getBiggerSize(array) { + var result = [0, 0]; + for (var i = 0; i < array.length; i++) { + if (array[i][0] * array[i][1] > result[0] * result[1]) { + result = array[i]; + } + } + return result; +} + +/* +* read the pricing extension with this format: 1.0000 +* @return {object} pricing data in format: {currency: "EUR", price:"1.000"} +*/ +function getPricing(xmlNode) { + var pricingExtNode; + var princingData = {}; + + var extensions = xmlNode.querySelectorAll('Extension'); + extensions.forEach(function(node) { + if (node.getAttribute('type') === 'StickyPricing') { + pricingExtNode = node; + } + }); + + if (pricingExtNode) { + var priceNode = pricingExtNode.querySelector('Price'); + princingData = { + currency: priceNode.getAttribute('currency'), + price: priceNode.textContent || priceNode.innerText + }; + } else { + console.log('PREBID - ' + BIDDER_CODE + ': Can\'t get pricing data. Is price awareness enabled?'); + } + + return princingData; +} + +function getCreativeId(xmlNode) { + var creaId = ''; + var adNodes = xmlNode.querySelectorAll('Ad'); + + adNodes.forEach(function(el) { + creaId += '[' + el.getAttribute('id') + ']'; + }); + + return creaId; +} + +/** +* returns the top most accessible window +*/ +function getTopMostWindow() { + var res = window; + + try { + while (top !== res) { + if (res.parent.location.href.length) { res = res.parent; } + } + } catch (e) {} + + return res; +} + +function getComponentId(inputFormat) { + var component = 'mustang'; // default component id + + if (inputFormat && inputFormat !== 'inbanner') { + // format identifiers are equals to their component ids. + component = inputFormat; + } + + return component; +} + +function getAPIName(componentId) { + componentId = componentId || ''; + + // remove dash in componentId to get API name + return componentId.replace('-', ''); +} + +function formatAdHTML(bid, size) { + var integrationType = bid.params.format; + + var divHtml = '
'; + + var script = ''; + var libUrl = ''; + if (integrationType && integrationType !== 'inbanner') { + libUrl = PRIMETIME_URL + getComponentId(bid.params.format) + '.min.js'; + script = getOutstreamScript(bid, size); + } else { + libUrl = MUSTANG_URL; + script = getInBannerScript(bid, size); + } + + return divHtml + + ''; +} + +var getInBannerScript = function(bid, size) { + return 'var config = {' + + ' preloadedVast:vast,' + + ' autoPlay:true' + + ' };' + + ' var ad = new window.com.stickyadstv.vpaid.Ad(document.getElementById("freewheelssp_prebid_target"),config);' + + ' (new window.com.stickyadstv.tools.ASLoader(' + bid.params.zoneId + ', \'' + getComponentId(bid.params.format) + '\')).registerEvents(ad);' + + ' ad.initAd(' + size[0] + ',' + size[1] + ',"",0,"","");'; +}; + +var getOutstreamScript = function(bid) { + var placementCode = bid.adUnitCode; + + var config = bid.params; + + // default placement if no placement is set + if (!config.hasOwnProperty('domId') && !config.hasOwnProperty('auto') && !config.hasOwnProperty('p') && !config.hasOwnProperty('article')) { + config.domId = placementCode; + } + + var script = 'var config = {' + + ' preloadedVast:vast,' + + ' ASLoader:new window.com.stickyadstv.tools.ASLoader(' + bid.params.zoneId + ', \'' + getComponentId(bid.params.format) + '\')'; + + for (var key in config) { + // dont' send format parameter + // neither zone nor vastUrlParams value as Vast is already loaded + if (config.hasOwnProperty(key) && key !== 'format' && key !== 'zone' && key !== 'zoneId' && key !== 'vastUrlParams') { + script += ',' + key + ':"' + config[key] + '"'; + } + } + script += '};' + + + 'window.com.stickyadstv.' + getAPIName(bid.params.format) + '.start(config);'; + + return script; +}; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: ['video'], + aliases: ['stickyadstv'], // former name for freewheel-ssp + /** + * Determines whether or not the given bid request is valid. + * + * @param {object} bid The bid to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function(bid) { + return !!(bid.params.zoneId); + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function(bidRequests) { + // var currency = config.getConfig(currency); + + this._currentBidRequest = bidRequests[0]; + if (bidRequests.length > 1) { + console.log('Prebid.JS - freewheel bid adapter: only one ad unit is required.'); + } + + var requestParams = { + reqType: 'AdsSetup', + protocolVersion: '2.0', + zoneId: this._currentBidRequest.params.zoneId, + componentId: getComponentId(this._currentBidRequest.params.format) + }; + + var location = utils.getTopWindowUrl(); + if (isValidUrl(location)) { + requestParams.loc = location; + } + + this._currentPlayerSize = getBiggerSize(this._currentBidRequest.sizes); + if (this._currentPlayerSize[0] > 0 || this._currentPlayerSize[1] > 0) { + requestParams.playerSize = this._currentPlayerSize[0] + 'x' + this._currentPlayerSize[1]; + } + + return { + method: 'GET', + url: FREEWHEEL_ADSSETUP, + data: requestParams + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function(serverResponse) { + var xmlDoc; + try { + var parser = new DOMParser(); + xmlDoc = parser.parseFromString(serverResponse, 'application/xml'); + } catch (err) { + console.warn('Prebid.js - ' + BIDDER_CODE + ' : ' + err); + return; + } + + const princingData = getPricing(xmlDoc); + const creativeId = getCreativeId(xmlDoc); + + const topWin = getTopMostWindow(); + if (!topWin.freeheelssp_cache) { + topWin.freeheelssp_cache = {}; + } + topWin.freeheelssp_cache[this._currentBidRequest.adUnitCode] = serverResponse; + + const bidResponses = []; + + if (princingData.price) { + const bidResponse = { + requestId: this._currentBidRequest.bidId, + bidderCode: this._currentBidRequest.bidder, + cpm: princingData.price, + width: this._currentPlayerSize[0], + height: this._currentPlayerSize[1], + creativeId: creativeId, + currency: princingData.currency, + netRevenue: true, + ttl: 360 + }; + + var mediaTypes = this._currentBidRequest.mediaTypes || {}; + if (mediaTypes.video) { + bidResponse.vastUrl = 'https//ads.stickyadstv.com/www/delivery/swfIndex.php?reqType=AdsSetup&protocolVersion=2.0&zoneId=2003'; + bidResponse.mediaType = 'video'; + } else { + bidResponse.ad = formatAdHTML(this._currentBidRequest, this._currentPlayerSize) + } + + bidResponses.push(bidResponse); + } + + return bidResponses; + }, + + getUserSyncs: function(syncOptions) {} +} +registerBidder(spec); diff --git a/modules/freewheelSSPBidAdapter.md b/modules/freewheelSSPBidAdapter.md new file mode 100644 index 00000000000..ba7915c87e1 --- /dev/null +++ b/modules/freewheelSSPBidAdapter.md @@ -0,0 +1,27 @@ +# Overview + +Module Name: Freewheel SSP Bidder Adapter +Module Type: Bidder Adapter +Maintainer: clientsidesdk@freewheel.tv + +# Description + +Module that connects to Freewheel ssp's demand sources + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + sizes: [[300, 250]], // a display size + bids: [ + { + bidder: "freewheel-ssp", + params: { + zoneId : '277225' + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/modules/stickyadstvBidAdapter.js b/modules/stickyadstvBidAdapter.js deleted file mode 100644 index 0201996ae8c..00000000000 --- a/modules/stickyadstvBidAdapter.js +++ /dev/null @@ -1,269 +0,0 @@ -var Adapter = require('src/adapter.js').default; -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var utils = require('src/utils.js'); -var adaptermanager = require('src/adaptermanager'); - -var StickyAdsTVAdapter = function StickyAdsTVAdapter() { - var STICKYADS_BIDDERCODE = 'stickyadstv'; - var MUSTANG_URL = '//cdn.stickyadstv.com/mustang/mustang.min.js'; - var OUTSTREAM_URL = '//cdn.stickyadstv.com/prime-time/[COMP-ID].min.js'; - - var topMostWindow = getTopMostWindow(); - topMostWindow.stickyadstv_cache = {}; - - function _callBids(params) { - var bids = params.bids || []; - for (var i = 0; i < bids.length; i++) { - var bid = bids[i]; - // Send out bid request for each bid given its tag IDs and query strings - - if (bid.placementCode && bid.params.zoneId) { - sendBidRequest(bid); - } else { - utils.logWarn('StickyAdsTV: Missing mandatory field(s).'); - } - } - } - - function sendBidRequest(bid) { - var placementCode = bid.placementCode; - - var integrationType = bid.params.format ? bid.params.format : 'inbanner'; - var urltoLoad = MUSTANG_URL; - - if (integrationType !== 'inbanner') { - // integration types are equals to component ids - urltoLoad = OUTSTREAM_URL.replace('[COMP-ID]', integrationType); - } - - var bidRegistered = false; - adloader.loadScript(urltoLoad, function() { - getBid(bid, function(bidObject) { - if (!bidRegistered) { - bidRegistered = true; - bidmanager.addBidResponse(placementCode, bidObject); - } - }); - }, true); - } - - function getBid(bid, callback) { - var zoneId = bid.params.zoneId || bid.params.zone; // accept both - var size = getBiggerSize(bid.sizes); - - // some of our formats doesn't have tools API exposed - var toolsAPI = window.com.stickyadstv.tools; - if (toolsAPI && toolsAPI.ASLoader) { - topMostWindow.stickyadstv_asLoader = new toolsAPI.ASLoader(zoneId, getComponentId(bid.params.format)); - } - - var vastLoader = new window.com.stickyadstv.vast.VastLoader(); - bid.vast = topMostWindow.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); - - var vastCallback = { - onSuccess: bind(function() { - // 'this' is the bid request here - var bidRequest = this; - - var adHtml = formatAdHTML(bidRequest, size); - var price = extractPrice(bidRequest.vast); - - callback(formatBidObject(bidRequest, true, price, adHtml, size[0], size[1])); - }, bid), - onError: bind(function() { - var bidRequest = this; - callback(formatBidObject(bidRequest, false)); - }, bid) - }; - - var config = { - zoneId: zoneId, - playerSize: size[0] + 'x' + size[1], - vastUrlParams: bid.params.vastUrlParams, - componentId: getComponentId(bid.params.format) - }; - - var api = window.com.stickyadstv[getAPIName(bid.params.format)]; - if (api && typeof api.getPlayerSize === 'function') { - // in screenroll and similar cases we don't use the original div size. - config.playerSize = api.getPlayerSize(); - } - - vastLoader.load(config, vastCallback); - } - - function getComponentId(inputFormat) { - var component = 'mustang'; // default component id - - if (inputFormat && inputFormat !== 'inbanner') { - // format identifiers are equals to their component ids. - component = inputFormat; - } - - return component; - } - - function getAPIName(componentId) { - componentId = componentId || ''; - - // remove dash in componentId to get API name - return componentId.replace('-', ''); - } - - function getBiggerSize(array) { - var result = [1, 1]; - for (var i = 0; i < array.length; i++) { - if (array[i][0] * array[i][1] > result[0] * result[1]) { - result = array[i]; - } - } - return result; - } - - var formatInBannerHTML = function(bid, size) { - var placementCode = bid.placementCode; - - var divHtml = '
'; - - var script = "'; - - return divHtml + script; - }; - - var formatOutstreamHTML = function(bid) { - var placementCode = bid.placementCode; - - var config = bid.params; - - // default placement if no placement is set - if (!config.hasOwnProperty('domId') && !config.hasOwnProperty('auto') && !config.hasOwnProperty('p') && !config.hasOwnProperty('article')) { - config.domId = placementCode; - } - - var script = "'; - - return script; - }; - - function formatAdHTML(bid, size) { - var integrationType = bid.params.format; - - var html = ''; - if (integrationType && integrationType !== 'inbanner') { - html = formatOutstreamHTML(bid); - } else { - html = formatInBannerHTML(bid, size); - } - - return html; - } - - function extractPrice(vast) { - var priceData = vast.getPricing(); - - if (!priceData) { - console.warn("freewheel-ssp: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your Freewheel contact."); - } - - return priceData; - } - - function formatBidObject(bidRequest, valid, priceData, html, width, height) { - var bidObject; - if (valid && priceData) { - // valid bid response - bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = bidRequest.bidder; - bidObject.cpm = priceData.price; - bidObject.currencyCode = priceData.currency; - bidObject.ad = html; - bidObject.width = width; - bidObject.height = height; - } else { - // invalid bid response - bidObject = bidfactory.createBid(2, bidRequest); - bidObject.bidderCode = bidRequest.bidder; - } - return bidObject; - } - - /** - * returns the top most accessible window - */ - function getTopMostWindow() { - var res = window; - - try { - while (top !== res) { - if (res.parent.location.href.length) { res = res.parent; } - } - } catch (e) {} - - return res; - } - - /* Create a function bound to a given object (assigning `this`, and arguments, - * optionally). Binding with arguments is also known as `curry`. - * Delegates to **ECMAScript 5**'s native `Function.bind` if available. - * We check for `func.bind` first, to fail fast when `func` is undefined. - * - * @param {function} func - * @param {optional} context - * @param {...any} var_args - * @return {function} - */ - var bind = function(func, context) { - return function() { - return func.apply(context, arguments); - }; - }; - - return Object.assign(this, new Adapter(STICKYADS_BIDDERCODE), { - callBids: _callBids, - formatBidObject: formatBidObject, - formatAdHTML: formatAdHTML, - getBiggerSize: getBiggerSize, - getBid: getBid, - getTopMostWindow: getTopMostWindow, - getComponentId: getComponentId, - getAPIName: getAPIName, - }); -}; - -adaptermanager.registerBidAdapter(new StickyAdsTVAdapter(), 'stickyadstv'); -adaptermanager.aliasBidAdapter('stickyadstv', 'freewheel-ssp'); - -module.exports = StickyAdsTVAdapter; diff --git a/test/spec/modules/freewheelSSPBidAdapter_spec.js b/test/spec/modules/freewheelSSPBidAdapter_spec.js new file mode 100644 index 00000000000..0fa65795ef6 --- /dev/null +++ b/test/spec/modules/freewheelSSPBidAdapter_spec.js @@ -0,0 +1,194 @@ +import { expect } from 'chai'; +import { spec } from 'modules/freewheelSSPBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const ENDPOINT = '//ads.stickyadstv.com/www/delivery/swfIndex.php'; + +describe('freewheelSSP BidAdapter Test', () => { + const adapter = newBidder(spec); + + describe('inherited functions', () => { + it('exists and is a function', () => { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', () => { + let bid = { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }; + + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', () => { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + wrong: 'missing zone id' + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', () => { + let bidRequests = [ + { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('should add parameters to the tag', () => { + const request = spec.buildRequests(bidRequests); + console.log(request.data); + + const payload = request.data; + expect(payload.reqType).to.equal('AdsSetup'); + expect(payload.protocolVersion).to.equal('2.0'); + expect(payload.zoneId).to.equal('277225'); + expect(payload.componentId).to.equal('mustang'); + expect(payload.playerSize).to.equal('300x600'); + }); + + it('sends bid request to ENDPOINT via GET', () => { + const request = spec.buildRequests(bidRequests); + expect(request.url).to.contain(ENDPOINT); + expect(request.method).to.equal('GET'); + }); + }) + + describe('interpretResponse', () => { + let bidRequests = [ + { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + let formattedBidRequests = [ + { + 'bidder': 'freewheel-ssp', + 'params': { + 'zoneId': '277225', + 'format': 'floorad' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[600, 250], [300, 600]], + 'bidId': '30b3other1c1838de1e', + 'bidderRequestId': '22edbae273other3bf6', + 'auctionId': '1d1a03079test0a475', + }, + { + 'bidder': 'stickyadstv', + 'params': { + 'zoneId': '277225', + 'format': 'test' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 600]], + 'bidId': '2', + 'bidderRequestId': '3', + 'auctionId': '4', + } + ]; + + let response = '' + + '' + + ' ' + + ' Adswizz' + + ' ' + + ' ' + + ' ' + + ' 00:00:09' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 0.2000' + + ' ' + + ' ' + + ' ' + + ''; + + let ad = '
'; + let formattedAd = '
'; + + it('should get correct bid response', () => { + spec.buildRequests(bidRequests); + + let expectedResponse = [ + { + requestId: '30b31c1838de1e', + bidderCode: 'freewheel-ssp', + cpm: '0.2000', + width: 300, + height: 600, + creativeId: '28517153', + currency: 'EUR', + netRevenue: true, + ttl: 360, + ad: ad + } + ]; + + let result = spec.interpretResponse(response); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('should get correct bid response with formated ad', () => { + spec.buildRequests(formattedBidRequests); + + let expectedResponse = [ + { + requestId: '30b31c1838de1e', + bidderCode: 'freewheel-ssp', + cpm: '0.2000', + width: 300, + height: 600, + creativeId: '28517153', + currency: 'EUR', + netRevenue: true, + ttl: 360, + ad: formattedAd + } + ]; + + let result = spec.interpretResponse(response); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('handles nobid responses', () => { + let response = ''; + + let result = spec.interpretResponse(response); + expect(result.length).to.equal(0); + }); + }); +}); From 584d8fd4c64f78d3318cd032228056ce3e343f19 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 30 Oct 2017 15:31:09 +0100 Subject: [PATCH 27/45] remove old stickyadstv unittest spec. --- .../modules/stickyadstvBidAdapter_spec.js | 225 ------------------ 1 file changed, 225 deletions(-) delete mode 100644 test/spec/modules/stickyadstvBidAdapter_spec.js diff --git a/test/spec/modules/stickyadstvBidAdapter_spec.js b/test/spec/modules/stickyadstvBidAdapter_spec.js deleted file mode 100644 index c0f35b1c406..00000000000 --- a/test/spec/modules/stickyadstvBidAdapter_spec.js +++ /dev/null @@ -1,225 +0,0 @@ -import {expect} from 'chai'; -import {assert} from 'chai'; -import Adapter from '../../../modules/stickyadstvBidAdapter'; -import adLoader from '../../../src/adloader'; - -describe('StickyAdsTV Adapter', function () { - var adapter = void 0; - var sandbox = void 0; - var bidsRequestBuff = void 0; - var bidderRequest = { - bidderCode: 'stickyadstv', - bids: [{ - bidId: 'bidId1', - bidder: 'stickyadstv', - placementCode: 'foo', - sizes: [[300, 250]], - params: { - zoneId: '2003', - format: 'screen-roll' - } - }, { - bidId: 'bidId2', - bidder: 'stickyadstv', - placementCode: 'bar', - sizes: [[728, 90]], - params: { - zoneId: '5562003' - } - }, { - bidId: 'bidId3', - bidder: 'stickyadstv', - placementCode: '', - sizes: [[300, 600]], - params: { - zoneId: '123456' - } - }, { - bidId: 'bidId4', - bidder: 'stickyadstv', - placementCode: 'coo', - sizes: [[300, 600]], - params: { - wrong: 'missing zoneId' - } - }] - }; - - beforeEach(function () { - adapter = new Adapter(); - sandbox = sinon.sandbox.create(); - bidsRequestBuff = $$PREBID_GLOBAL$$._bidsRequested; - $$PREBID_GLOBAL$$._bidsRequested = []; - }); - - afterEach(function () { - sandbox.restore(); - $$PREBID_GLOBAL$$._bidsRequested = bidsRequestBuff; - }); - - describe('callBids', function () { - beforeEach(function () { - sandbox.stub(adLoader, 'loadScript'); - adapter.callBids(bidderRequest); - }); - - it('should be called twice', function () { - sinon.assert.calledTwice(adLoader.loadScript); - }); - - it('should have load screenroll and mustang script', function () { - var url = void 0; - - url = adLoader.loadScript.firstCall.args[0]; - expect(url).to.equal('//cdn.stickyadstv.com/prime-time/screen-roll.min.js'); - - url = adLoader.loadScript.secondCall.args[0]; - expect(url).to.equal('//cdn.stickyadstv.com/mustang/mustang.min.js'); - }); - }); - - describe('getBid', function () { - let bidResponse; - let loadConfig; - let getPricingCalled; - - beforeEach(function () { - // Mock VastLoader for test purpose - window.com = { - stickyadstv: { - vast: { - VastLoader: function() { - this.getVast = function() { - return { - getPricing: function() { - getPricingCalled = true; - return {currency: 'USD', price: 4.000} - } - }; - }; - - this.load = function(config, listener) { - loadConfig = config; - listener.onSuccess(); - }; - } - }, - screenroll: { - getPlayerSize: function() { - return '123x456'; - } - } - } - }; - - adapter.getBid(bidderRequest.bids[0], function(bidObject) { - bidResponse = bidObject; - }); - }); - - afterEach(function() { - delete window.com.stickyadstv.vast.VastLoader; - delete window.com.stickyadstv.vast; - delete window.com.stickyadstv.screenroll; - delete window.com.stickyadstv; - }); - - it('should return a valid bidObject', function () { - expect(bidResponse).to.have.property('cpm', 4.000); - expect(bidResponse).to.have.property('ad', ""); - expect(bidResponse).to.have.property('bidderCode', 'stickyadstv'); - expect(bidResponse).to.have.property('currencyCode', 'USD'); - expect(bidResponse).to.have.property('width', 300); - expect(bidResponse).to.have.property('height', 250); - expect(bidResponse.getStatusCode()).to.equal(1); - }); - - it('should have called load with proper config', function () { - expect(loadConfig).to.have.property('playerSize', '123x456'); - expect(loadConfig).to.have.property('zoneId', '2003'); - }); - - it('should have called getPricing', function () { - expect(getPricingCalled).to.equal(true); - }); - }); - - describe('formatBidObject', function () { - it('should create a valid bid object', function () { - let result = adapter.formatBidObject('', true, {currency: 'EUR', price: '1.2345'}, '
sample
', 200, 300); - - expect(result).to.have.property('cpm', '1.2345'); - expect(result).to.have.property('ad', '
sample
'); - expect(result).to.have.property('currencyCode', 'EUR'); - expect(result).to.have.property('width', 200); - expect(result).to.have.property('height', 300); - expect(result.getStatusCode()).to.equal(1); - }); - - it('should create a invalid bid object because price is not defined', function () { - let result = adapter.formatBidObject('', true, null, '
sample
', 200, 300); - - expect(result.getStatusCode()).to.equal(2); - }); - - it('should create a invalid bid object', function () { - let result = adapter.formatBidObject('', false, {currency: 'EUR', price: '1.2345'}, '
sample
', 200, 300); - - expect(result.getStatusCode()).to.equal(2); - }); - }); - - describe('formatAdHTML', function () { - it('should create an inBanner ad format', function () { - let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {}}, [200, 300]); - - expect(result).to.equal('
'); - }); - - it('should create an intext ad format', function () { - let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'intext-roll', auto: 'v2', smartPlay: 'true'}}, [200, 300]); - - expect(result).to.equal(''); - }); - - it('should create a screenroll ad format', function () { - let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'screen-roll', smartPlay: 'true'}}, [200, 300]); - - expect(result).to.equal(''); - }); - }); - - describe('getBiggerSize', function () { - it('should return the bigger size', function () { - let result = adapter.getBiggerSize([[1, 4000], [4000, 1], [200, 300], [0, 0]]); - - expect(result[0]).to.equal(200); - expect(result[1]).to.equal(300); - }); - }); - - describe('top most window', function () { - it('should return the top most window', function () { - let result = adapter.getTopMostWindow(); - - expect(result).to.equal(window.top); - }); - }); - - describe('get component id', function() { - it('should return valid component ids', function() { - expect(adapter.getComponentId('inbanner')).to.equal('mustang'); - expect(adapter.getComponentId('intext-roll')).to.equal('intext-roll'); - expect(adapter.getComponentId('screen-roll')).to.equal('screen-roll'); - }); - }); - - describe('get API name', function() { - it('should return valid API names', function() { - expect(adapter.getAPIName()).to.equal(''); - expect(adapter.getAPIName('intext-roll')).to.equal('intextroll'); - expect(adapter.getAPIName('screen-roll')).to.equal('screenroll'); - expect(adapter.getAPIName('floorad')).to.equal('floorad'); - }); - }); -}); From 545876d8ffbf5a278c80e18859e079f6ff8ffdbe Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 30 Oct 2017 16:48:16 +0100 Subject: [PATCH 28/45] fix server response parsing if sent as object with 'body' field --- modules/freewheelSSPBidAdapter.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 9cb2fe41a81..3d858535072 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -243,6 +243,10 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: function(serverResponse) { + if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string'){ + serverResponse = serverResponse.body; + } + var xmlDoc; try { var parser = new DOMParser(); From c6db60529aae8f064b6056e99bad88eccda656a9 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 30 Oct 2017 17:15:09 +0100 Subject: [PATCH 29/45] use the vastXml field for video mediatype --- modules/freewheelSSPBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 3d858535072..b4830e62430 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -243,7 +243,7 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: function(serverResponse) { - if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string'){ + if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string') { serverResponse = serverResponse.body; } @@ -282,7 +282,7 @@ export const spec = { var mediaTypes = this._currentBidRequest.mediaTypes || {}; if (mediaTypes.video) { - bidResponse.vastUrl = 'https//ads.stickyadstv.com/www/delivery/swfIndex.php?reqType=AdsSetup&protocolVersion=2.0&zoneId=2003'; + bidResponse.vastXml = serverResponse; bidResponse.mediaType = 'video'; } else { bidResponse.ad = formatAdHTML(this._currentBidRequest, this._currentPlayerSize) From 8aae6c6d0ad83d40a1e1ed4645a9c89ab4ef9295 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 31 Oct 2017 10:13:00 +0100 Subject: [PATCH 30/45] add user sync pixel in freewheel ssp adapter --- modules/freewheelSSPBidAdapter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index b4830e62430..2561ee73e96 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -8,6 +8,7 @@ const PROTOCOL = getProtocol(); const FREEWHEEL_ADSSETUP = PROTOCOL + '://ads.stickyadstv.com/www/delivery/swfIndex.php'; const MUSTANG_URL = PROTOCOL + '://cdn.stickyadstv.com/mustang/mustang.min.js'; const PRIMETIME_URL = PROTOCOL + '://cdn.stickyadstv.com/prime-time/'; +const USER_SYNC_URL = PROTOCOL + '://ads.stickyadstv.com/auto-user-sync'; function getProtocol() { if (location.protocol && location.protocol.indexOf('https') === 0) { @@ -294,6 +295,9 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions) {} + getUserSyncs: function(syncOptions) { + var img = new Image(); + img.src = USER_SYNC_URL; + } } registerBidder(spec); From fc3e2178346eda6e37655e6bc45f83a059e9fc16 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 23 Nov 2017 14:30:00 +0100 Subject: [PATCH 31/45] remove all console log calls (replaced using util helper) --- modules/freewheelSSPBidAdapter.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 2561ee73e96..94774cc8172 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -60,7 +60,7 @@ function getPricing(xmlNode) { price: priceNode.textContent || priceNode.innerText }; } else { - console.log('PREBID - ' + BIDDER_CODE + ': Can\'t get pricing data. Is price awareness enabled?'); + utils.logWarn('PREBID - ' + BIDDER_CODE + ': Can\'t get pricing data. Is price awareness enabled?'); } return princingData; @@ -210,7 +210,7 @@ export const spec = { this._currentBidRequest = bidRequests[0]; if (bidRequests.length > 1) { - console.log('Prebid.JS - freewheel bid adapter: only one ad unit is required.'); + utils.logMessage('Prebid.JS - freewheel bid adapter: only one ad unit is required.'); } var requestParams = { @@ -253,7 +253,7 @@ export const spec = { var parser = new DOMParser(); xmlDoc = parser.parseFromString(serverResponse, 'application/xml'); } catch (err) { - console.warn('Prebid.js - ' + BIDDER_CODE + ' : ' + err); + utils.logWarn('Prebid.js - ' + BIDDER_CODE + ' : ' + err); return; } @@ -283,10 +283,13 @@ export const spec = { var mediaTypes = this._currentBidRequest.mediaTypes || {}; if (mediaTypes.video) { - bidResponse.vastXml = serverResponse; + // bidResponse.vastXml = serverResponse; bidResponse.mediaType = 'video'; + + var blob = new Blob([serverResponse], {type: 'application/xml'}); + bidResponse.vastUrl = window.URL.createObjectURL(blob); } else { - bidResponse.ad = formatAdHTML(this._currentBidRequest, this._currentPlayerSize) + bidResponse.ad = formatAdHTML(this._currentBidRequest, this._currentPlayerSize); } bidResponses.push(bidResponse); From 8d6360b9a5c77f166dbafd0c500a12bba834ab19 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 23 Nov 2017 14:34:56 +0100 Subject: [PATCH 32/45] remove useless bidderCode (automatically added by the bidderFactory) --- modules/freewheelSSPBidAdapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 94774cc8172..57191da8217 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -271,7 +271,6 @@ export const spec = { if (princingData.price) { const bidResponse = { requestId: this._currentBidRequest.bidId, - bidderCode: this._currentBidRequest.bidder, cpm: princingData.price, width: this._currentPlayerSize[0], height: this._currentPlayerSize[1], From 4ccb39dc9c189c31188bed95f5d0d28d8ca9d040 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 23 Nov 2017 14:35:30 +0100 Subject: [PATCH 33/45] Return the SYNC pixel to be added in the page by Prebid.js --- modules/freewheelSSPBidAdapter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 57191da8217..a7d89ddb4d6 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -298,8 +298,12 @@ export const spec = { }, getUserSyncs: function(syncOptions) { - var img = new Image(); - img.src = USER_SYNC_URL; + if (syncOptions.pixelEnabled) { + return [{ + type: 'image', + url: USER_SYNC_URL + }]; + } } } registerBidder(spec); From 57f7c27b26d8608e22ec22dffb75e4225145ebc1 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 23 Nov 2017 14:40:53 +0100 Subject: [PATCH 34/45] remove instance level properties to enable concurrent bids with the same adapter instance. --- modules/freewheelSSPBidAdapter.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index a7d89ddb4d6..0d5349920da 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -208,7 +208,7 @@ export const spec = { buildRequests: function(bidRequests) { // var currency = config.getConfig(currency); - this._currentBidRequest = bidRequests[0]; + var currentBidRequest = bidRequests[0]; if (bidRequests.length > 1) { utils.logMessage('Prebid.JS - freewheel bid adapter: only one ad unit is required.'); } @@ -216,8 +216,8 @@ export const spec = { var requestParams = { reqType: 'AdsSetup', protocolVersion: '2.0', - zoneId: this._currentBidRequest.params.zoneId, - componentId: getComponentId(this._currentBidRequest.params.format) + zoneId: currentBidRequest.params.zoneId, + componentId: getComponentId(currentBidRequest.params.format) }; var location = utils.getTopWindowUrl(); @@ -225,9 +225,9 @@ export const spec = { requestParams.loc = location; } - this._currentPlayerSize = getBiggerSize(this._currentBidRequest.sizes); - if (this._currentPlayerSize[0] > 0 || this._currentPlayerSize[1] > 0) { - requestParams.playerSize = this._currentPlayerSize[0] + 'x' + this._currentPlayerSize[1]; + var playerSize = getBiggerSize(currentBidRequest.sizes); + if (playerSize[0] > 0 || playerSize[1] > 0) { + requestParams.playerSize = playerSize[0] + 'x' + playerSize[1]; } return { @@ -243,7 +243,9 @@ export const spec = { * @param {*} serverResponse A successful response from the server. * @return {Bid[]} An array of bids which were nested inside the server. */ - interpretResponse: function(serverResponse) { + interpretResponse: function(serverResponse, bidrequest) { + var playerSize = getBiggerSize(bidrequest.sizes); + if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string') { serverResponse = serverResponse.body; } @@ -264,23 +266,23 @@ export const spec = { if (!topWin.freeheelssp_cache) { topWin.freeheelssp_cache = {}; } - topWin.freeheelssp_cache[this._currentBidRequest.adUnitCode] = serverResponse; + topWin.freeheelssp_cache[bidrequest.adUnitCode] = serverResponse; const bidResponses = []; if (princingData.price) { const bidResponse = { - requestId: this._currentBidRequest.bidId, + requestId: bidrequest.bidId, cpm: princingData.price, - width: this._currentPlayerSize[0], - height: this._currentPlayerSize[1], + width: playerSize[0], + height: playerSize[1], creativeId: creativeId, currency: princingData.currency, netRevenue: true, ttl: 360 }; - var mediaTypes = this._currentBidRequest.mediaTypes || {}; + var mediaTypes = bidrequest.mediaTypes || {}; if (mediaTypes.video) { // bidResponse.vastXml = serverResponse; bidResponse.mediaType = 'video'; @@ -288,7 +290,7 @@ export const spec = { var blob = new Blob([serverResponse], {type: 'application/xml'}); bidResponse.vastUrl = window.URL.createObjectURL(blob); } else { - bidResponse.ad = formatAdHTML(this._currentBidRequest, this._currentPlayerSize); + bidResponse.ad = formatAdHTML(bidrequest, playerSize); } bidResponses.push(bidResponse); From 91029d945a7a5aeae17c42ea4234bb9272275389 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 23 Nov 2017 17:38:35 +0100 Subject: [PATCH 35/45] fix the request apss through and corresponding unit tests --- modules/freewheelSSPBidAdapter.js | 9 ++++++--- test/spec/modules/freewheelSSPBidAdapter_spec.js | 13 ++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 0d5349920da..1504dbfa3e0 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -233,7 +233,8 @@ export const spec = { return { method: 'GET', url: FREEWHEEL_ADSSETUP, - data: requestParams + data: requestParams, + bidRequest: currentBidRequest }; }, @@ -241,11 +242,13 @@ export const spec = { * Unpack the response from the server into a list of bids. * * @param {*} serverResponse A successful response from the server. + * @param {object} request: the built request object containing the initial bidRequest. * @return {Bid[]} An array of bids which were nested inside the server. */ - interpretResponse: function(serverResponse, bidrequest) { + interpretResponse: function(serverResponse, request) { + var bidrequest = request.bidRequest; var playerSize = getBiggerSize(bidrequest.sizes); - + if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string') { serverResponse = serverResponse.body; } diff --git a/test/spec/modules/freewheelSSPBidAdapter_spec.js b/test/spec/modules/freewheelSSPBidAdapter_spec.js index 0fa65795ef6..107259e9805 100644 --- a/test/spec/modules/freewheelSSPBidAdapter_spec.js +++ b/test/spec/modules/freewheelSSPBidAdapter_spec.js @@ -141,12 +141,11 @@ describe('freewheelSSP BidAdapter Test', () => { let formattedAd = '
'; it('should get correct bid response', () => { - spec.buildRequests(bidRequests); + var request = spec.buildRequests(bidRequests); let expectedResponse = [ { requestId: '30b31c1838de1e', - bidderCode: 'freewheel-ssp', cpm: '0.2000', width: 300, height: 600, @@ -158,17 +157,16 @@ describe('freewheelSSP BidAdapter Test', () => { } ]; - let result = spec.interpretResponse(response); + let result = spec.interpretResponse(response, request); expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); it('should get correct bid response with formated ad', () => { - spec.buildRequests(formattedBidRequests); + var request = spec.buildRequests(formattedBidRequests); let expectedResponse = [ { requestId: '30b31c1838de1e', - bidderCode: 'freewheel-ssp', cpm: '0.2000', width: 300, height: 600, @@ -180,14 +178,15 @@ describe('freewheelSSP BidAdapter Test', () => { } ]; - let result = spec.interpretResponse(response); + let result = spec.interpretResponse(response, request); expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); }); it('handles nobid responses', () => { + var reqest = spec.buildRequests(formattedBidRequests); let response = ''; - let result = spec.interpretResponse(response); + let result = spec.interpretResponse(response, reqest); expect(result.length).to.equal(0); }); }); From cf55f762ca44cd025d1389cc9791de6ff7093b90 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 7 Dec 2017 16:26:49 +0100 Subject: [PATCH 36/45] fix 'freeheelssp' typo --- modules/freewheelSSPBidAdapter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 1504dbfa3e0..7c696c746e6 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -136,7 +136,7 @@ function formatAdHTML(bid, size) { // get the top most accessible window ' var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})();' + // inject the xml in the Vast object as string - ' vast.setXmlString(topWindow.freeheelssp_cache["' + bid.adUnitCode + '"]);' + + ' vast.setXmlString(topWindow.freewheelssp_cache["' + bid.adUnitCode + '"]);' + // force ad parsing on the given vast xml ' vastLoader.parseAds(vast, {' + ' onSuccess: function() {' + script + ' }' + @@ -266,10 +266,10 @@ export const spec = { const creativeId = getCreativeId(xmlDoc); const topWin = getTopMostWindow(); - if (!topWin.freeheelssp_cache) { - topWin.freeheelssp_cache = {}; + if (!topWin.freewheelssp_cache) { + topWin.freewheelssp_cache = {}; } - topWin.freeheelssp_cache[bidrequest.adUnitCode] = serverResponse; + topWin.freewheelssp_cache[bidrequest.adUnitCode] = serverResponse; const bidResponses = []; From f62aab2e73891dffee82fff16ea379937553bbd6 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 11 May 2018 15:04:35 +0200 Subject: [PATCH 37/45] add vast parameters feature and GDPR params in VAST request --- modules/freewheelSSPBidAdapter.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 632df8fe93c..97605e642fd 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -223,6 +223,20 @@ export const spec = { componentId: getComponentId(currentBidRequest.params.format) }; + if(typeof currentBidRequest.params.gdpr !== "undefined") { + requestParams._fw_gdpr = currentBidRequest.params.gdpr; + requestParams._fw_gdpr_consent = currentBidRequest.params.gdpr_consent; + } + + var vastParams = currentBidRequest.params.vastUrlParams; + if(typeof vastParams === "object") { + for(kye in vastParams){ + + if(vastParams.hasOwnProperty(key)) + requestParams[key] = vastParams[key]; + } + } + var location = utils.getTopWindowUrl(); if (isValidUrl(location)) { requestParams.loc = location; From 0717715d2fe48952d09aa67114a7c0fbf62c85b5 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 11 May 2018 15:18:35 +0200 Subject: [PATCH 38/45] fix lint issues --- modules/freewheelSSPBidAdapter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 97605e642fd..fd1d17da122 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -223,17 +223,17 @@ export const spec = { componentId: getComponentId(currentBidRequest.params.format) }; - if(typeof currentBidRequest.params.gdpr !== "undefined") { + if (typeof currentBidRequest.params.gdpr !== 'undefined') { requestParams._fw_gdpr = currentBidRequest.params.gdpr; requestParams._fw_gdpr_consent = currentBidRequest.params.gdpr_consent; } var vastParams = currentBidRequest.params.vastUrlParams; - if(typeof vastParams === "object") { - for(kye in vastParams){ - - if(vastParams.hasOwnProperty(key)) + if (typeof vastParams === 'object') { + for (kye in vastParams) { + if (vastParams.hasOwnProperty(key)) { requestParams[key] = vastParams[key]; + } } } From d7f57f43cf7b18ec9cf95f4e91c098788301fb57 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 22 May 2018 12:28:49 +0200 Subject: [PATCH 39/45] add gdpr parameter support on freewheelSSPBidAdapter --- modules/freewheelSSPBidAdapter.js | 10 +++++++--- test/spec/modules/freewheelSSPBidAdapter_spec.js | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index fd1d17da122..d2b453ea728 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -223,9 +223,13 @@ export const spec = { componentId: getComponentId(currentBidRequest.params.format) }; - if (typeof currentBidRequest.params.gdpr !== 'undefined') { - requestParams._fw_gdpr = currentBidRequest.params.gdpr; - requestParams._fw_gdpr_consent = currentBidRequest.params.gdpr_consent; + // Add GDPR flag and consent string + if (currentBidRequest.gdprConsent) { + requestParams._fw_gdpr_consent = currentBidRequest.gdprConsent.consentString; + + if (typeof currentBidRequest.gdprConsent.gdprApplies === 'boolean') { + requestParams._fw_gdpr = currentBidRequest.gdprConsent.gdprApplies; + } } var vastParams = currentBidRequest.params.vastUrlParams; diff --git a/test/spec/modules/freewheelSSPBidAdapter_spec.js b/test/spec/modules/freewheelSSPBidAdapter_spec.js index 33bd647efaa..cc46d7eef3e 100644 --- a/test/spec/modules/freewheelSSPBidAdapter_spec.js +++ b/test/spec/modules/freewheelSSPBidAdapter_spec.js @@ -52,6 +52,10 @@ describe('freewheelSSP BidAdapter Test', () => { 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', + 'gdprConsent': { + 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', + 'gdprApplies': true + } } ]; @@ -63,6 +67,8 @@ describe('freewheelSSP BidAdapter Test', () => { expect(payload.zoneId).to.equal('277225'); expect(payload.componentId).to.equal('mustang'); expect(payload.playerSize).to.equal('300x600'); + expect(payload._fw_gdpr).to.equal(true); + expect(payload._fw_gdpr_consent).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); }); it('sends bid request to ENDPOINT via GET', () => { From 1ad8abdf06fc4f41339fa42bc763dc9cd6678e9e Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 22 May 2018 12:49:30 +0200 Subject: [PATCH 40/45] use bidderrequest to read gdpr parameters and update unit tests --- modules/freewheelSSPBidAdapter.js | 6 +++--- test/spec/modules/freewheelSSPBidAdapter_spec.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index d2b453ea728..402074a8fee 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -208,7 +208,7 @@ export const spec = { * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. * @return ServerRequest Info describing the request to the server. */ - buildRequests: function(bidRequests) { + buildRequests: function(bidRequests, bidderRequest) { // var currency = config.getConfig(currency); var currentBidRequest = bidRequests[0]; @@ -224,8 +224,8 @@ export const spec = { }; // Add GDPR flag and consent string - if (currentBidRequest.gdprConsent) { - requestParams._fw_gdpr_consent = currentBidRequest.gdprConsent.consentString; + if (bidderRequest.gdprConsent) { + requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString; if (typeof currentBidRequest.gdprConsent.gdprApplies === 'boolean') { requestParams._fw_gdpr = currentBidRequest.gdprConsent.gdprApplies; diff --git a/test/spec/modules/freewheelSSPBidAdapter_spec.js b/test/spec/modules/freewheelSSPBidAdapter_spec.js index cc46d7eef3e..ec4483fafed 100644 --- a/test/spec/modules/freewheelSSPBidAdapter_spec.js +++ b/test/spec/modules/freewheelSSPBidAdapter_spec.js @@ -60,7 +60,7 @@ describe('freewheelSSP BidAdapter Test', () => { ]; it('should add parameters to the tag', () => { - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests, bidRequests[0]); const payload = request.data; expect(payload.reqType).to.equal('AdsSetup'); expect(payload.protocolVersion).to.equal('2.0'); @@ -72,7 +72,7 @@ describe('freewheelSSP BidAdapter Test', () => { }); it('sends bid request to ENDPOINT via GET', () => { - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests, bidRequests[0]); expect(request.url).to.contain(ENDPOINT); expect(request.method).to.equal('GET'); }); @@ -145,7 +145,7 @@ describe('freewheelSSP BidAdapter Test', () => { let formattedAd = '
'; it('should get correct bid response', () => { - var request = spec.buildRequests(bidRequests); + var request = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); let expectedResponse = [ { @@ -166,7 +166,7 @@ describe('freewheelSSP BidAdapter Test', () => { }); it('should get correct bid response with formated ad', () => { - var request = spec.buildRequests(formattedBidRequests); + var request = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); let expectedResponse = [ { @@ -187,7 +187,7 @@ describe('freewheelSSP BidAdapter Test', () => { }); it('handles nobid responses', () => { - var reqest = spec.buildRequests(formattedBidRequests); + var reqest = spec.buildRequests(formattedBidRequests, formattedBidRequests[0]); let response = ''; let result = spec.interpretResponse(response, reqest); From 447785f472a7477e16c359314830ec0f676ffd1c Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 22 May 2018 12:55:06 +0200 Subject: [PATCH 41/45] fix lint errors --- modules/freewheelSSPBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 402074a8fee..63c10a60d64 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -224,7 +224,7 @@ export const spec = { }; // Add GDPR flag and consent string - if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent) { requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString; if (typeof currentBidRequest.gdprConsent.gdprApplies === 'boolean') { From 37d95fcac7ad6f843420f56d9e13bd0032d8a077 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 22 May 2018 12:57:18 +0200 Subject: [PATCH 42/45] fix lint errors --- modules/freewheelSSPBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 63c10a60d64..cdc03b18f25 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -224,7 +224,7 @@ export const spec = { }; // Add GDPR flag and consent string - if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent) { requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString; if (typeof currentBidRequest.gdprConsent.gdprApplies === 'boolean') { From 0238d9290030ed5d385cdfa1d1f654132f307477 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 14 Jun 2018 15:07:27 +0200 Subject: [PATCH 43/45] fix typo and bidderRequest reference. --- modules/freewheelSSPBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index cdc03b18f25..604beaaf539 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -234,7 +234,7 @@ export const spec = { var vastParams = currentBidRequest.params.vastUrlParams; if (typeof vastParams === 'object') { - for (kye in vastParams) { + for (key in vastParams) { if (vastParams.hasOwnProperty(key)) { requestParams[key] = vastParams[key]; } From 2a18f585270afe2b85a243b30f53ab9722c82d3d Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 14 Jun 2018 15:07:53 +0200 Subject: [PATCH 44/45] fix bidderRequest reference. --- modules/freewheelSSPBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index 604beaaf539..d56e7d4998e 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -227,8 +227,8 @@ export const spec = { if (bidderRequest.gdprConsent) { requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString; - if (typeof currentBidRequest.gdprConsent.gdprApplies === 'boolean') { - requestParams._fw_gdpr = currentBidRequest.gdprConsent.gdprApplies; + if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { + requestParams._fw_gdpr = bidderRequest.gdprConsent.gdprApplies; } } From de1de4bd5376d977bc73dab16432a282d3cf278b Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 18 Jun 2018 15:47:47 +0200 Subject: [PATCH 45/45] add missing declaration for 'key' variable --- modules/freewheelSSPBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/freewheelSSPBidAdapter.js b/modules/freewheelSSPBidAdapter.js index d56e7d4998e..87c1979ac5d 100644 --- a/modules/freewheelSSPBidAdapter.js +++ b/modules/freewheelSSPBidAdapter.js @@ -234,7 +234,7 @@ export const spec = { var vastParams = currentBidRequest.params.vastUrlParams; if (typeof vastParams === 'object') { - for (key in vastParams) { + for (var key in vastParams) { if (vastParams.hasOwnProperty(key)) { requestParams[key] = vastParams[key]; }