Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StickyAdsTV bidder adapter update #1311

Merged
merged 35 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
632c8c1
add stickyadsTV bidder adapter
Jan 5, 2017
a91ac2d
init unit test file
Jan 5, 2017
9e2d70e
ad some unit tests
Jan 5, 2017
9c92c3e
fix unit test on ad format with parameters
Jan 5, 2017
7ed68e9
add some unit tests
Jan 6, 2017
88a45ac
add unit tests on getBid method
Jan 6, 2017
7d6bf3c
add some test cases in unit tests
Jan 6, 2017
affdd67
minor fix on component id tag.
Jan 9, 2017
654a473
remove adapters-sticky.json test file
Jan 12, 2017
3b0760e
Merge remote-tracking branch 'Prebid/master'
Jan 12, 2017
8c0f143
use top most accessible window instead of window.top
Jan 26, 2017
fd877dc
Pass in the bid request in the createBid call.
Jan 26, 2017
09f7348
use top most accessible window instead of window.top
Feb 3, 2017
28a36a6
Merge remote-tracking branch 'Prebid/master'
Feb 3, 2017
90264e8
add unit tests
Feb 3, 2017
29453af
update unit tests
Feb 3, 2017
b664ee1
fix unit test.
Feb 3, 2017
57c31a1
fix CI build
Feb 6, 2017
2915576
Merge remote-tracking branch 'Prebid/master'
Feb 9, 2017
c5c41be
Merge remote-tracking branch 'Prebid/master'
Mar 1, 2017
475eee3
add alias freewheel-ssp
Mar 2, 2017
71bfaa1
Merge remote-tracking branch 'Prebid/master'
Mar 10, 2017
410ee00
update unit tests on bidderCode value
Mar 10, 2017
8f7c947
Merge branch 'master' into master
Mar 30, 2017
1d7be59
Merge remote-tracking branch 'Prebid/master'
Jun 7, 2017
b09dfdd
fix component id values and add unit tests
Jun 16, 2017
d5e6d79
Merge remote-tracking branch 'Prebid/master'
Jun 16, 2017
d52df6f
allws to use any outstream format.
Jun 20, 2017
9ad2b7f
fix ASLoader on futur outstream format versions
Jun 20, 2017
427b45c
minor: fix code format.
Jun 20, 2017
c65c62d
update unit tests
Jun 20, 2017
23639ff
minor fix code format
Jun 20, 2017
8c26777
Merge remote-tracking branch 'Prebid/master'
Jun 20, 2017
7b2ff67
minor: add missing new line at eof
Jun 20, 2017
cea7ebd
Merge remote-tracking branch 'Prebid/master'
Jun 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 43 additions & 47 deletions modules/stickyadstvBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var adaptermanager = require('src/adaptermanager');
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 = {};
Expand All @@ -34,11 +33,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;
Expand All @@ -56,6 +53,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();

Expand All @@ -79,17 +82,36 @@ 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') {
// 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

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++) {
Expand All @@ -114,14 +136,15 @@ 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,"","");' +

'</script>';

return divHtml + script;
};

var formatIntextHTML = function(bid) {
var formatOutstreamHTML = function(bid) {
var placementCode = bid.placementCode;

var config = bid.params;
Expand All @@ -136,7 +159,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
Expand All @@ -147,50 +171,20 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() {
}
script += '};' +

'topWindow.com.stickyadstv.intextroll.start(config);' +
'topWindow.com.stickyadstv.' + getAPIName(bid.params.format) + '.start(config);' +

'</script>';

return script;
};

var formatScreenRollHTML = function(bid) {
var placementCode = bid.placementCode;

var config = bid.params;

var script = "<script type='text/javascript'>" +

// 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;})();' +
'var vast = topWindow.stickyadstv_cache["' + placementCode + '"];' +
'var config = {' +
' preloadedVast:vast';

for (var key in config) {
// dont' send format parameter
// neither zone nor vastUrlParams values as Vast is already loaded
if (config.hasOwnProperty(key) && key !== 'format' && key !== 'zone' && key !== 'zoneId' && key !== 'vastUrlParams') {
script += ',' + key + ':"' + config[key] + '"';
}
}
script += '};' +

'topWindow.com.stickyadstv.screenroll.start(config);' +

'</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);
}
Expand All @@ -202,7 +196,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() {
var priceData = vast.getPricing();

if (!priceData) {
utils.logWarn("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;
Expand Down Expand Up @@ -265,6 +259,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() {
getBiggerSize: getBiggerSize,
getBid: getBid,
getTopMostWindow: getTopMostWindow,
getComponentId: getComponentId,
getAPIName: getAPIName,
createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias)
});
};
Expand Down
31 changes: 24 additions & 7 deletions test/spec/modules/stickyadstvBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,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', "<script type=\'text/javascript\'>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[\"foo\"];var config = { preloadedVast:vast};topWindow.com.stickyadstv.screenroll.start(config);</script>");
expect(bidResponse).to.have.property('ad', "<script type=\'text/javascript\'>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[\"foo\"];var config = { preloadedVast:vast, ASLoader:topWindow.stickyadstv_asLoader,domId:\"foo\"};topWindow.com.stickyadstv.screenroll.start(config);</script>");
expect(bidResponse).to.have.property('bidderCode', 'stickyadstv');
expect(bidResponse).to.have.property('currencyCode', 'USD');
expect(bidResponse).to.have.property('width', 300);
Expand Down Expand Up @@ -173,24 +173,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('<div id="stickyadstv_prebid_target"></div><script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast, autoPlay:true};var ad = new topWindow.com.stickyadstv.vpaid.Ad(document.getElementById("stickyadstv_prebid_target"),config);ad.initAd(200,300,"",0,"","");</script>');
expect(result).to.equal('<div id="stickyadstv_prebid_target"></div><script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast, 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(200,300,"",0,"","");</script>');
});

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('<script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast,auto:"v2",smartPlay:"true"};topWindow.com.stickyadstv.intextroll.start(config);</script>');
expect(result).to.equal('<script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast, ASLoader:topWindow.stickyadstv_asLoader,auto:"v2",smartPlay:"true"};topWindow.com.stickyadstv.intextroll.start(config);</script>');
});

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('<script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast,smartPlay:"true"};topWindow.com.stickyadstv.screenroll.start(config);</script>');
expect(result).to.equal('<script type=\'text/javascript\'>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["placementCodeValue"];var config = { preloadedVast:vast, ASLoader:topWindow.stickyadstv_asLoader,smartPlay:"true",domId:"placementCodeValue"};topWindow.com.stickyadstv.screenroll.start(config);</script>');
});
});

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);
Expand All @@ -199,10 +199,27 @@ 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);
});
});

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');
});
});
});