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

Telaria Bid Adapter: add adCode & srcPageUrl query string param only once. #4833

Merged
merged 2 commits into from
Feb 10, 2020
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
16 changes: 11 additions & 5 deletions modules/telariaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export const spec = {
}
};

function getSrcPageUrl(params) {
return (params && params['srcPageUrl']) || encodeURIComponent(document.location.href);
function getDefaultSrcPageUrl() {
return encodeURIComponent(document.location.href);
}

function getEncodedValIfNotEmpty(val) {
Expand Down Expand Up @@ -175,7 +175,10 @@ export const getTimeoutUrl = function(timeoutData) {
if (!utils.isEmpty(params)) {
let url = `https://${EVENTS_ENDPOINT}`;

url += `?srcPageUrl=${getSrcPageUrl(params)}`;
params = Object.assign({
srcPageUrl: getDefaultSrcPageUrl()
}, params);

url += `${getUrlParams(params)}`;

url += '&hb=1&evt=TO';
Expand Down Expand Up @@ -221,9 +224,12 @@ function generateUrl(bid, bidderRequest) {
url += (`&playerHeight=${height}`);
}

url += `${getUrlParams(bid.params, bid.schain)}`;
const params = Object.assign({
srcPageUrl: getDefaultSrcPageUrl()
}, bid.params);
delete params.adCode;

url += `&srcPageUrl=${getSrcPageUrl(bid.params)}`;
url += `${getUrlParams(params, bid.schain)}`;

url += (`&transactionId=${bid.transactionId}`);

Expand Down
40 changes: 33 additions & 7 deletions test/spec/modules/telariaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('TelariaAdapter', () => {
});

describe('buildRequests', () => {
const stub = [{
const stub = () => ([{
mediaTypes: {
video: {
playerSize: [[640, 480]],
Expand All @@ -131,7 +131,7 @@ describe('TelariaAdapter', () => {
adCode: 'ssp-!demo!-lufip',
videoId: 'MyCoolVideo'
}
}];
}]);

const schainStub = REQUEST_WITH_SCHAIN;

Expand All @@ -140,12 +140,12 @@ describe('TelariaAdapter', () => {
});

it('requires supply code & ad code to make a request', () => {
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
const tempRequest = spec.buildRequests(stub(), BIDDER_REQUEST);
expect(tempRequest.length).to.equal(1);
});

it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => {
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
const tempRequest = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
expect(tempRequest[0].method).to.equal('GET');
Expand All @@ -155,15 +155,15 @@ describe('TelariaAdapter', () => {
});

it('doesn\'t require player size but is highly recommended', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].mediaTypes.video.playerSize = null;
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
});

it('generates a valid request with sizes as an array of two elements', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].mediaTypes.video.playerSize = [640, 480];
tempBid[0].params.adCode = 'ssp-!demo!-lufip';
tempBid[0].params.supplyCode = 'ssp-demo-rm6rh';
Expand All @@ -172,7 +172,7 @@ describe('TelariaAdapter', () => {
});

it('requires ad code and supply code to make a request', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].params.adCode = null;
tempBid[0].params.supplyCode = null;

Expand All @@ -188,6 +188,32 @@ describe('TelariaAdapter', () => {
let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);
expect(builtRequests.length).to.equal(1);
});

it('adds adUnitCode to the request url', () => {
const builtRequests = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('adCode=');
expect(parts.length).to.equal(2);
});

it('adds srcPageUrl to the request url', () => {
const builtRequests = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('srcPageUrl=');
expect(parts.length).to.equal(2);
});

it('adds srcPageUrl from params to the request only once', () => {
const tempBid = stub();
tempBid[0].params.srcPageUrl = 'http://www.test.com';
const builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('srcPageUrl=');
expect(parts.length).to.equal(2);
});
});

describe('interpretResponse', () => {
Expand Down