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

Freewheel: Better size detection and allow multiple bid requests #5065

Merged
merged 2 commits into from
Apr 3, 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
124 changes: 65 additions & 59 deletions modules/freewheel-sspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as utils from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'freewheel-ssp';
Expand Down Expand Up @@ -213,7 +214,7 @@ var getOutstreamScript = function(bid) {

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
supportedMediaTypes: [BANNER, VIDEO],
aliases: ['stickyadstv'], // former name for freewheel-ssp
/**
* Determines whether or not the given bid request is valid.
Expand All @@ -234,77 +235,82 @@ export const spec = {
buildRequests: function(bidRequests, bidderRequest) {
// var currency = config.getConfig(currency);

var currentBidRequest = bidRequests[0];
if (bidRequests.length > 1) {
utils.logMessage('Prebid.JS - freewheel bid adapter: only one ad unit is required.');
}

var zone = currentBidRequest.params.zoneId;
var timeInMillis = new Date().getTime();
var keyCode = hashcode(zone + '' + timeInMillis);
var requestParams = {
reqType: 'AdsSetup',
protocolVersion: '2.0',
zoneId: zone,
componentId: getComponentId(currentBidRequest.params.format),
timestamp: timeInMillis,
pKey: keyCode
};
let buildRequest = (currentBidRequest, bidderRequest) => {
var zone = currentBidRequest.params.zoneId;
var timeInMillis = new Date().getTime();
var keyCode = hashcode(zone + '' + timeInMillis);
var requestParams = {
reqType: 'AdsSetup',
protocolVersion: '2.0',
zoneId: zone,
componentId: getComponentId(currentBidRequest.params.format),
timestamp: timeInMillis,
pKey: keyCode
};

// Add GDPR flag and consent string
if (bidderRequest && bidderRequest.gdprConsent) {
requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString;
// Add GDPR flag and consent string
if (bidderRequest && bidderRequest.gdprConsent) {
requestParams._fw_gdpr_consent = bidderRequest.gdprConsent.consentString;

if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
requestParams._fw_gdpr = bidderRequest.gdprConsent.gdprApplies;
if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
requestParams._fw_gdpr = bidderRequest.gdprConsent.gdprApplies;
}
}
}

if (currentBidRequest.params.gdpr_consented_providers) {
requestParams._fw_gdpr_consented_providers = currentBidRequest.params.gdpr_consented_providers;
}
if (currentBidRequest.params.gdpr_consented_providers) {
requestParams._fw_gdpr_consented_providers = currentBidRequest.params.gdpr_consented_providers;
}

// Add CCPA consent string
if (bidderRequest && bidderRequest.uspConsent) {
requestParams._fw_us_privacy = bidderRequest.uspConsent;
}
// Add CCPA consent string
if (bidderRequest && bidderRequest.uspConsent) {
requestParams._fw_us_privacy = bidderRequest.uspConsent;
}

var vastParams = currentBidRequest.params.vastUrlParams;
if (typeof vastParams === 'object') {
for (var key in vastParams) {
if (vastParams.hasOwnProperty(key)) {
requestParams[key] = vastParams[key];
var vastParams = currentBidRequest.params.vastUrlParams;
if (typeof vastParams === 'object') {
for (var key in vastParams) {
if (vastParams.hasOwnProperty(key)) {
requestParams[key] = vastParams[key];
}
}
}
}

var location = (bidderRequest && bidderRequest.refererInfo) ? bidderRequest.refererInfo.referer : getTopMostWindow().location.href;
if (isValidUrl(location)) {
requestParams.loc = location;
}
var location = (bidderRequest && bidderRequest.refererInfo) ? bidderRequest.refererInfo.referer : getTopMostWindow().location.href;
if (isValidUrl(location)) {
requestParams.loc = location;
}

var playerSize = [];
if (currentBidRequest.mediaTypes.video && currentBidRequest.mediaTypes.video.playerSize) {
// If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3
playerSize = currentBidRequest.mediaTypes.video.playerSize;
} else if (currentBidRequest.mediaTypes.banner.sizes) {
// If mediaTypes is banner, get size from mediaTypes.banner.sizes per http://prebid.org/blog/pbjs-3
playerSize = getBiggerSizeWithLimit(currentBidRequest.mediaTypes.banner.sizes, currentBidRequest.mediaTypes.banner.minSizeLimit, currentBidRequest.mediaTypes.banner.maxSizeLimit);
} else {
// Backward compatible code, in case size still pass by sizes in bid request
playerSize = getBiggerSize(currentBidRequest.sizes);
}
var playerSize = [];
if (currentBidRequest.mediaTypes.video && currentBidRequest.mediaTypes.video.playerSize) {
// If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3
if (utils.isArray(currentBidRequest.mediaTypes.video.playerSize[0])) {
playerSize = currentBidRequest.mediaTypes.video.playerSize[0];
} else {
playerSize = currentBidRequest.mediaTypes.video.playerSize;
}
} else if (currentBidRequest.mediaTypes.banner.sizes) {
// If mediaTypes is banner, get size from mediaTypes.banner.sizes per http://prebid.org/blog/pbjs-3
playerSize = getBiggerSizeWithLimit(currentBidRequest.mediaTypes.banner.sizes, currentBidRequest.mediaTypes.banner.minSizeLimit, currentBidRequest.mediaTypes.banner.maxSizeLimit);
} else {
// Backward compatible code, in case size still pass by sizes in bid request
playerSize = getBiggerSize(currentBidRequest.sizes);
}

if (playerSize[0] > 0 || playerSize[1] > 0) {
requestParams.playerSize = playerSize[0] + 'x' + playerSize[1];
}
if (playerSize[0] > 0 || playerSize[1] > 0) {
requestParams.playerSize = playerSize[0] + 'x' + playerSize[1];
}

return {
method: 'GET',
url: FREEWHEEL_ADSSETUP,
data: requestParams,
bidRequest: currentBidRequest
return {
method: 'GET',
url: FREEWHEEL_ADSSETUP,
data: requestParams,
bidRequest: currentBidRequest
};
};

return bidRequests.map(function(currentBidRequest) {
return buildRequest(currentBidRequest, bidderRequest);
});
},

/**
Expand Down
36 changes: 18 additions & 18 deletions test/spec/modules/freewheel-sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('freewheelSSP BidAdapter Test', () => {

it('should add parameters to the tag', () => {
const request = spec.buildRequests(bidRequests);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand All @@ -113,16 +113,16 @@ describe('freewheelSSP BidAdapter Test', () => {

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');
expect(request[0].url).to.contain(ENDPOINT);
expect(request[0].method).to.equal('GET');
});

it('should add usp consent to the request', () => {
let uspConsentString = '1FW-SSP-uspConsent-';
let bidderRequest = {};
bidderRequest.uspConsent = uspConsentString;
const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand All @@ -141,7 +141,7 @@ describe('freewheelSSP BidAdapter Test', () => {
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('freewheelSSP BidAdapter Test', () => {

it('should add parameters to the tag', () => {
const request = spec.buildRequests(bidRequests);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand All @@ -184,16 +184,16 @@ describe('freewheelSSP BidAdapter Test', () => {

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');
expect(request[0].url).to.contain(ENDPOINT);
expect(request[0].method).to.equal('GET');
});

it('should add usp consent to the request', () => {
let uspConsentString = '1FW-SSP-uspConsent-';
let bidderRequest = {};
bidderRequest.uspConsent = uspConsentString;
const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand All @@ -212,7 +212,7 @@ describe('freewheelSSP BidAdapter Test', () => {
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
const payload = request[0].data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('freewheelSSP BidAdapter Test', () => {
}
];

let result = spec.interpretResponse(response, request);
let result = spec.interpretResponse(response, request[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

Expand All @@ -348,15 +348,15 @@ describe('freewheelSSP BidAdapter Test', () => {
}
];

let result = spec.interpretResponse(response, request);
let result = spec.interpretResponse(response, request[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

it('handles nobid responses', () => {
var reqest = spec.buildRequests(formattedBidRequests);
var request = spec.buildRequests(formattedBidRequests);
let response = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><VAST version=\'2.0\'></VAST>';

let result = spec.interpretResponse(response, reqest);
let result = spec.interpretResponse(response, request[0]);
expect(result.length).to.equal(0);
});
});
Expand Down Expand Up @@ -460,7 +460,7 @@ describe('freewheelSSP BidAdapter Test', () => {
}
];

let result = spec.interpretResponse(response, request);
let result = spec.interpretResponse(response, request[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

Expand All @@ -483,15 +483,15 @@ describe('freewheelSSP BidAdapter Test', () => {
}
];

let result = spec.interpretResponse(response, request);
let result = spec.interpretResponse(response, request[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

it('handles nobid responses', () => {
var reqest = spec.buildRequests(formattedBidRequests);
var request = spec.buildRequests(formattedBidRequests);
let response = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><VAST version=\'2.0\'></VAST>';

let result = spec.interpretResponse(response, reqest);
let result = spec.interpretResponse(response, request[0]);
expect(result.length).to.equal(0);
});
});
Expand Down