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

GumGum: adds support for video #4848

Merged
merged 8 commits into from
Feb 17, 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
64 changes: 56 additions & 8 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as utils from '../src/utils'

import { config } from '../src/config'
import { BANNER, VIDEO } from '../src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';
import { registerBidder } from '../src/adapters/bidderFactory'

const BIDDER_CODE = 'gumgum'
const ALIAS_BIDDER_CODE = ['gg']
const BID_ENDPOINT = `https://g2.gumgum.com/hbid/imp`
const DT_CREDENTIALS = { member: 'YcXr87z2lpbB' }
const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO]
const TIME_TO_LIVE = 60

let browserParams = {};
Expand All @@ -23,7 +25,7 @@ function _getBrowserParams(topWindowUrl) {
function getNetworkSpeed () {
const connection = window.navigator && (window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection)
const Mbps = connection && (connection.downlink || connection.bandwidth)
return Mbps ? Math.round(Mbps * 1024) : null // 1 megabit -> 1024 kilobits
return Mbps ? Math.round(Mbps * 1024) : null
}
function getOgURL () {
let ogURL = ''
Expand Down Expand Up @@ -136,6 +138,7 @@ function isBidRequestValid (bid) {
case !!(params.inScreen): break;
case !!(params.inSlot): break;
case !!(params.ICV): break;
case !!(params.video): break;
default:
utils.logWarn(`[GumGum] No product selected for the placement ${adUnitCode}, please check your implementation.`);
return false;
Expand All @@ -149,6 +152,41 @@ function isBidRequestValid (bid) {
return true;
}

/**
* Renames vid params from mediatypes.video keys
* @param {Object} attributes
* @returns {Object}
*/
function _getVidParams (attributes) {
const {
minduration: mind,
maxduration: maxd,
linearity: li,
startdelay: sd,
placement: pt,
protocols = [],
playerSize = []
} = attributes;
const sizes = utils.parseSizesInput(playerSize);
const [viw, vih] = sizes[0] && sizes[0].split('x');
let pr = '';

if (protocols.length) {
pr = protocols.join(',');
}

return {
mind,
maxd,
li,
sd,
pt,
pr,
viw,
vih
};
}

/**
* Make a server request from the list of BidRequests.
*
Expand All @@ -159,20 +197,22 @@ function buildRequests (validBidRequests, bidderRequest) {
const bids = [];
const gdprConsent = bidderRequest && bidderRequest.gdprConsent;
const uspConsent = bidderRequest && bidderRequest.uspConsent;
const timeout = config.getConfig('bidderTimeout');
const topWindowUrl = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
utils._each(validBidRequests, bidRequest => {
const timeout = config.getConfig('bidderTimeout');
const {
bidId,
mediaTypes = {},
params = {},
schain,
transactionId,
userId = {}
} = bidRequest;
const data = {};
const sizes = bidRequest.mediaTypes && bidRequest.mediaTypes.banner && bidRequest.mediaTypes.banner.sizes;
const topWindowUrl = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
const bannerSizes = mediaTypes.banner && mediaTypes.banner.sizes;
let data = {};

if (pageViewId) {
data.pv = pageViewId
data.pv = pageViewId;
}
if (params.bidfloor) {
data.fp = params.bidfloor;
Expand All @@ -193,6 +233,12 @@ function buildRequests (validBidRequests, bidderRequest) {
data.ni = parseInt(params.ICV, 10);
data.pi = 5;
}
if (params.video) {
data = Object.assign(data, _getVidParams(mediaTypes.video));
data.t = params.video;
data.pi = 7;
}

if (gdprConsent) {
data.gdprApplies = gdprConsent.gdprApplies ? 1 : 0;
}
Expand All @@ -212,7 +258,7 @@ function buildRequests (validBidRequests, bidderRequest) {
tId: transactionId,
pi: data.pi,
selector: params.selector,
sizes: sizes || bidRequest.sizes,
sizes: bannerSizes || bidRequest.sizes,
url: BID_ENDPOINT,
method: 'GET',
data: Object.assign(data, _getBrowserParams(topWindowUrl), _getDigiTrustQueryParams(userId), _getTradeDeskIDParam(userId))
Expand Down Expand Up @@ -271,6 +317,7 @@ function interpretResponse (serverResponse, bidRequest) {
bidResponses.push({
// dealId: DEAL_ID,
// referrer: REFERER,
...(product === 7 && { vastXml: markup }),
ad: wrapper ? getWrapperCode(wrapper, Object.assign({}, serverResponseBody, { bidRequest })) : markup,
cpm: isTestUnit ? 0.1 : cpm,
creativeId,
Expand Down Expand Up @@ -314,6 +361,7 @@ export const spec = {
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs
getUserSyncs,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES
}
registerBidder(spec)
34 changes: 32 additions & 2 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('gumgumAdapter', function () {
expect(request.method).to.equal('GET');
expect(request.id).to.equal('30b31c1838de1e');
});
it('should correctly set the request paramters depending on params field', function () {
it('should set t and fp parameters in bid request if inScreen request param is found', function () {
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.params = {
Expand All @@ -129,7 +129,7 @@ describe('gumgumAdapter', function () {
expect(bidRequest.data.pubId).to.equal(request.params.inScreenPubID);
expect(bidRequest.data).to.not.include.any.keys('t');
});
it('should correctly set the request paramters depending on params field', function () {
it('should set a ni parameter in bid request if ICV request param is found', function () {
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.params = {
Expand All @@ -139,6 +139,36 @@ describe('gumgumAdapter', function () {
expect(bidRequest.data.pi).to.equal(5);
expect(bidRequest.data).to.include.any.keys('ni');
});
it('should add parameters associated with video if video request param is found', function () {
const videoVals = {
playerSize: [640, 480],
context: 'instream',
minduration: 1,
maxduration: 2,
linearity: 1,
startdelay: 1,
placement: 123456,
protocols: [1, 2]
};
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.mediaTypes = {
video: videoVals
};
request.params = {
'video': '10433395'
};
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.eq(7);
expect(bidRequest.data.mind).to.eq(videoVals.minduration);
expect(bidRequest.data.maxd).to.eq(videoVals.maxduration);
expect(bidRequest.data.li).to.eq(videoVals.linearity);
expect(bidRequest.data.sd).to.eq(videoVals.startdelay);
expect(bidRequest.data.pt).to.eq(videoVals.placement);
expect(bidRequest.data.pr).to.eq(videoVals.protocols.join(','));
expect(bidRequest.data.viw).to.eq(videoVals.playerSize[0].toString());
expect(bidRequest.data.vih).to.eq(videoVals.playerSize[1].toString());
});
it('should not add additional parameters depending on params field', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.data).to.not.include.any.keys('ni');
Expand Down