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

Feature/widespace update request param #1098

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions src/adapters/widespace.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { getBidRequest } from '../utils.js';

var utils = require('../utils.js');
var adloader = require('../adloader.js');
var bidmanager = require('../bidmanager.js');
var bidfactory = require('../bidfactory.js');

const utils = require('../utils.js');
const adloader = require('../adloader.js');
const bidmanager = require('../bidmanager.js');
const bidfactory = require('../bidfactory.js');
const WS_ADAPTER_VERSION = '1.0.1';

function WidespaceAdapter() {
let useSSL = 'https:' === document.location.protocol,
Expand All @@ -17,9 +17,9 @@ function WidespaceAdapter() {

for (var i = 0; i < bids.length; i++) {
const bid = bids[i],
callbackUid = bid.bidId,
sid = bid.params.sid,
currency = bid.params.currency;
callbackUid = bid.bidId,
sid = bid.params.sid,
currency = bid.params.cur || bid.params.currency;

//Handle Sizes string
let sizeQueryString = '';
Expand All @@ -29,14 +29,25 @@ function WidespaceAdapter() {
return prev ? `${prev},${curr}` : curr;
}, sizeQueryString);

var requestURL = baseURL;
requestURL = utils.tryAppendQueryString(requestURL, 'hb.name', 'prebidjs');
requestURL = utils.tryAppendQueryString(requestURL, 'hb.callback', callbackName);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.callbackUid', callbackUid);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.sizes', sizeQueryString);
requestURL = utils.tryAppendQueryString(requestURL, 'sid', sid);
requestURL = utils.tryAppendQueryString(requestURL, 'hb.currency', currency);
let requestURL = baseURL;
requestURL = utils.tryAppendQueryString(requestURL, 'hb.ver', WS_ADAPTER_VERSION);

const params = {
'hb': '1',
'hb.name': 'prebidjs',
'hb.callback': callbackName,
'hb.callbackUid': callbackUid,
'hb.sizes': sizeQueryString,
'hb.currency': currency,
'sid': sid
};

requestURL += '#';

// Append all params to requestURL
for (let key of Object.keys(params)) {
requestURL += key + '=' + params[key] + '&';
}

// Expose the callback
$$PREBID_GLOBAL$$.widespaceHandleCB = window[callbackName] = handleCallback;
Expand Down Expand Up @@ -66,6 +77,7 @@ function WidespaceAdapter() {
placementCode = inBid.placementCode;
validSizes = inBid.sizes;
}

if (bid && bid.callbackUid && bid.status !=='noad' && verifySize(bid.sizes, validSizes)) {
bidObject = bidfactory.createBid(1);
bidObject.bidderCode = bidCode;
Expand Down
2 changes: 2 additions & 0 deletions test/spec/adapters/widespace_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ describe('WidespaceAdapter', () => {
it('should include required request parameters', () => {
const endpointRequest = expect(adLoader.loadScript.firstCall.args[0]);
endpointRequest.to.include('sid');
endpointRequest.to.include('hb');
endpointRequest.to.include('hb.ver');
endpointRequest.to.include('hb.callbackUid');
endpointRequest.to.include('hb.callback');
endpointRequest.to.include('hb.sizes');
Expand Down