Skip to content

Commit

Permalink
SpotX bid adapter: add page parameter (#5784)
Browse files Browse the repository at this point in the history
  • Loading branch information
agdillon authored Sep 28, 2020
1 parent b2f0c6d commit 280e957
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
23 changes: 17 additions & 6 deletions modules/spotxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO } from '../src/mediaTypes.js';
Expand All @@ -19,7 +20,7 @@ export const spec = {
* From Prebid.js: isBidRequestValid - Verify the the AdUnits.bids, respond with true (valid) or false (invalid).
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
* @return {boolean} True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
if (bid && typeof bid.params !== 'object') {
Expand Down Expand Up @@ -64,14 +65,24 @@ export const spec = {
* from Prebid.js: buildRequests - Takes an array of valid bid requests, all of which are guaranteed to have passed the isBidRequestValid() test.
*
* @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.
* @param {object} bidderRequest - The master bidRequest object.
* @return {ServerRequest} Info describing the request to the server.
*/
buildRequests: function(bidRequests, bidderRequest) {
const page = bidderRequest.refererInfo.referer;
const isPageSecure = !!page.match(/^https:/)
const referer = bidderRequest.refererInfo.referer;
const isPageSecure = !!referer.match(/^https:/);

const siteId = '';
const spotxRequests = bidRequests.map(function(bid) {
let page;
if (utils.getBidIdParameter('page', bid.params)) {
page = utils.getBidIdParameter('page', bid.params);
} else if (config.getConfig('pageUrl')) {
page = config.getConfig('pageUrl');
} else {
page = referer;
}

const channelId = utils.getBidIdParameter('channel_id', bid.params);
let pubcid = null;

Expand Down Expand Up @@ -436,11 +447,11 @@ function createOutstreamScript(bid) {

const customOverride = utils.getBidIdParameter('custom_override', bid.renderer.config.outstream_options);
if (customOverride && utils.isPlainObject(customOverride)) {
utils.logMessage('[SPOTX][renderer] Custom beahavior.');
utils.logMessage('[SPOTX][renderer] Custom behavior.');
for (let name in customOverride) {
if (customOverride.hasOwnProperty(name)) {
if (name === 'channel_id' || name === 'vast_url' || name === 'content_page_url' || name === 'ad_unit') {
utils.logWarn('[SPOTX][renderer] Custom beahavior: following option cannot be overrided: ' + name);
utils.logWarn('[SPOTX][renderer] Custom behavior: following option cannot be overridden: ' + name);
} else {
dataSpotXParams['data-spotx_' + name] = customOverride[name];
}
Expand Down
47 changes: 47 additions & 0 deletions test/spec/modules/spotxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expect} from 'chai';
import {config} from 'src/config.js';
import {spec, GOOGLE_CONSENT} from 'modules/spotxBidAdapter.js';

describe('the spotx adapter', function () {
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('the spotx adapter', function () {
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', function() {
var bid, bidRequestObj;

Expand Down Expand Up @@ -125,6 +127,7 @@ describe('the spotx adapter', function () {
page: 'prebid.js'
});
});

it('should change request parameters based on options sent', function() {
var request = spec.buildRequests([bid], bidRequestObj)[0];
expect(request.data.imp.video.ext).to.deep.equal({
Expand Down Expand Up @@ -332,6 +335,50 @@ describe('the spotx adapter', function () {
expect(request.data.imp.video.ext.placement).to.equal(2);
expect(request.data.imp.video.ext.pos).to.equal(5);
});

it('should pass page param and override refererInfo.referer', function() {
var request;

bid.params.page = 'https://example.com';

var origGetConfig = config.getConfig;
sinon.stub(config, 'getConfig').callsFake(function (key) {
if (key === 'pageUrl') {
return 'https://www.spotx.tv';
}
return origGetConfig.apply(config, arguments);
});

request = spec.buildRequests([bid], bidRequestObj)[0];

expect(request.data.site.page).to.equal('https://example.com');
config.getConfig.restore();
});

it('should use pageUrl from config if page param is not passed', function() {
var request;

var origGetConfig = config.getConfig;
sinon.stub(config, 'getConfig').callsFake(function (key) {
if (key === 'pageUrl') {
return 'https://www.spotx.tv';
}
return origGetConfig.apply(config, arguments);
});

request = spec.buildRequests([bid], bidRequestObj)[0];

expect(request.data.site.page).to.equal('https://www.spotx.tv');
config.getConfig.restore();
});

it('should use refererInfo.referer if no page or pageUrl are passed', function() {
var request;

request = spec.buildRequests([bid], bidRequestObj)[0];

expect(request.data.site.page).to.equal('prebid.js');
});
});

describe('interpretResponse', function() {
Expand Down

0 comments on commit 280e957

Please sign in to comment.