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 zone and pubId params #5728

Merged
merged 1 commit into from
Sep 21, 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
107 changes: 62 additions & 45 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ function isBidRequestValid (bid) {
params,
adUnitCode
} = bid;
const id = params.inScreen || params.inScreenPubID || params.inSlot || params.ICV || params.video || params.inVideo;
const legacyParamID = params.inScreen || params.inScreenPubID || params.inSlot || params.ICV || params.video || params.inVideo;
const id = legacyParamID || params.slot || params.native || params.zone || params.pubID;

if (invalidRequestIds[id]) {
utils.logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`);
return false;
}

switch (true) {
case !!(params.zone): break;
case !!(params.pubId): break;
case !!(params.inScreen): break;
case !!(params.inScreenPubID): break;
case !!(params.inSlot): break;
Expand Down Expand Up @@ -217,8 +220,8 @@ function _getFloor (mediaTypes, bidfloor, bid) {
});

if (typeof floorInfo === 'object' &&
floorInfo.currency === 'USD' &&
!isNaN(parseFloat(floorInfo.floor))) {
floorInfo.currency === 'USD' &&
!isNaN(parseFloat(floorInfo.floor))) {
floor = Math.max(floor, parseFloat(floorInfo.floor));
}
}
Expand Down Expand Up @@ -255,6 +258,7 @@ function buildRequests (validBidRequests, bidderRequest) {
sizes = mediaTypes.banner.sizes;
} else if (mediaTypes.video) {
sizes = mediaTypes.video.playerSize;
data = _getVidParams(mediaTypes.video);
}

if (pageViewId) {
Expand All @@ -265,48 +269,27 @@ function buildRequests (validBidRequests, bidderRequest) {
data.fp = bidFloor;
}

if (params.inScreenPubID) {
data.pubId = params.inScreenPubID;
data.pi = 2;
}
if (params.inScreen) {
data.t = params.inScreen;
data.pi = 2;
}
if (params.inSlot) {
data.si = parseInt(params.inSlot, 10);
// check for sizes and type
if (params.sizes && Array.isArray(params.sizes)) {
const bf = params.sizes.reduce(function(r, i) {
// only push if it's an array of length 2
if (Array.isArray(i) && i.length === 2) {
r.push(`${i[0]}x${i[1]}`);
}
return r;
}, []);
data.bf = bf.toString();
if (params.zone) {
data.t = params.zone;
data.pi = 2; // inscreen
// override pi if the following is found
if (params.slot) {
data.si = parseInt(params.slot, 10);
data.pi = 3;
data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, '');
} else if (params.native) {
data.ni = parseInt(params.native, 10);
data.pi = 5;
} else if (mediaTypes.video) {
data.pi = mediaTypes.video.linearity === 1 ? 7 : 6; // video : invideo
}
data.pi = 3;
}
if (params.ICV) {
data.ni = parseInt(params.ICV, 10);
data.pi = 5;
}
if (params.videoPubID) {
data = Object.assign(data, _getVidParams(mediaTypes.video));
data.pubId = params.videoPubID;
data.pi = 7;
}
if (params.video) {
data = Object.assign(data, _getVidParams(mediaTypes.video));
data.t = params.video;
data.pi = 7;
}
if (params.inVideo) {
data = Object.assign(data, _getVidParams(mediaTypes.video));
data.t = params.inVideo;
data.pi = 6;
} else if (params.pubId) {
data.pubId = params.pubId
data.pi = mediaTypes.video ? 7 : 2; // video : inscreen
} else { // legacy params
data = { ...data, ...handleLegacyParams(params, sizes) }
}

if (gdprConsent) {
data.gdprApplies = gdprConsent.gdprApplies ? 1 : 0;
}
Expand Down Expand Up @@ -335,6 +318,40 @@ function buildRequests (validBidRequests, bidderRequest) {
return bids;
}

function handleLegacyParams (params, sizes) {
const data = {};
if (params.inScreenPubID) {
data.pubId = params.inScreenPubID;
data.pi = 2;
}
if (params.inScreen) {
data.t = params.inScreen;
data.pi = 2;
}
if (params.inSlot) {
data.si = parseInt(params.inSlot, 10);
data.pi = 3;
data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, '');
}
if (params.ICV) {
data.ni = parseInt(params.ICV, 10);
data.pi = 5;
}
if (params.videoPubID) {
data.pubId = params.videoPubID;
data.pi = 7;
}
if (params.video) {
data.t = params.video;
data.pi = 7;
}
if (params.inVideo) {
data.t = params.inVideo;
data.pi = 6;
}
return data;
}

/**
* Unpack the response from the server into a list of bids.
*
Expand All @@ -347,7 +364,7 @@ function interpretResponse (serverResponse, bidRequest) {

if (!serverResponseBody || serverResponseBody.err) {
const data = bidRequest.data || {}
const id = data.t || data.si || data.ni || data.pubId;
const id = data.si || data.ni || data.t || data.pubId;
const delayTime = serverResponseBody ? serverResponseBody.err.drt : DELAY_REQUEST_TIME;
invalidRequestIds[id] = { productId: data.pi, timestamp: new Date().getTime() };

Expand Down Expand Up @@ -403,7 +420,7 @@ function interpretResponse (serverResponse, bidRequest) {
bidResponses.push({
// dealId: DEAL_ID,
// referrer: REFERER,
...(product === 7 && { vastXml: markup }),
...(product === 7 && { vastXml: markup, mediaType: VIDEO }),
ad: wrapper ? getWrapperCode(wrapper, Object.assign({}, serverResponseBody, { bidRequest })) : markup,
...(product === 6 && {ad: markup}),
cpm: isTestUnit ? 0.1 : cpm,
Expand Down
71 changes: 61 additions & 10 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ describe('gumgumAdapter', function () {
};

it('should return true when required params found', function () {
const zoneBid = { ...bid, params: { 'zone': '123' } };
const pubIdBid = { ...bid, params: { 'pubId': '123' } };
expect(spec.isBidRequestValid(bid)).to.equal(true);
expect(spec.isBidRequestValid(zoneBid)).to.equal(true);
expect(spec.isBidRequestValid(pubIdBid)).to.equal(true);
});

it('should return true when required params found', function () {
Expand Down Expand Up @@ -139,20 +143,68 @@ describe('gumgumAdapter', function () {
}
};

describe('zone param', function () {
const zoneParam = { 'zone': '123a' };

it('should set t and pi param', function () {
const request = { ...bidRequests[0], params: zoneParam };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.t).to.equal(zoneParam.zone);
expect(bidRequest.data.pi).to.equal(2);
});
it('should set the correct pi param if slot param is found', function () {
const request = { ...bidRequests[0], params: { ...zoneParam, 'slot': 1 } };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(3);
});
it('should set the correct pi param if native param is found', function () {
const request = { ...bidRequests[0], params: { ...zoneParam, 'native': 2 } };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(5);
});
it('should set the correct pi param for video', function () {
const request = { ...bidRequests[0], params: zoneParam, mediaTypes: vidMediaTypes };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(7);
});
it('should set the correct pi param for invideo', function () {
const invideo = { video: { ...vidMediaTypes.video, linearity: 2 } };
const request = { ...bidRequests[0], params: zoneParam, mediaTypes: invideo };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(6);
});
});

describe('pubId zone', function () {
const pubIdParam = { 'pubId': 'abc' };

it('should set t param', function () {
const request = { ...bidRequests[0], params: pubIdParam };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pubId).to.equal(pubIdParam.pubId);
});

it('should set the correct pi depending on what is found in mediaTypes', function () {
const request = { ...bidRequests[0], params: pubIdParam };
const bidRequest = spec.buildRequests([request])[0];
const vidRequest = { ...bidRequests[0], mediaTypes: vidMediaTypes, params: { 'videoPubID': 123 } };
const vidBidRequest = spec.buildRequests([vidRequest])[0];

expect(bidRequest.data.pi).to.equal(2);
expect(vidBidRequest.data.pi).to.equal(7);
});
});

it('should return a defined sizes field for video', function () {
const request = { ...bidRequests[0], mediaTypes: vidMediaTypes, params: { 'videoPubID': 123 } };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.sizes).to.equal(vidMediaTypes.video.playerSize);
});
it('should handle multiple sizes for inslot', function () {
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.params = {
'inSlot': '123',
'sizes': [[0, 1], [0, 2]]
};
const mediaTypes = { banner: { sizes: [[300, 250], [300, 600]] } }
const request = { ...bidRequests[0], mediaTypes };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.bf).to.equal('0x1,0x2');
expect(bidRequest.data.bf).to.equal('300x250,300x600');
});
describe('floorModule', function () {
const floorTestData = {
Expand All @@ -163,9 +215,8 @@ describe('gumgumAdapter', function () {
return floorTestData;
};
it('should return the value from getFloor if present', function () {
const request = { ...bidRequests[0] };
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.fp).to.equal(floorTestData.floor);
const request = spec.buildRequests(bidRequests)[0];
expect(request.data.fp).to.equal(floorTestData.floor);
});
it('should return the getFloor.floor value if it is greater than bidfloor', function () {
const bidfloor = 0.80;
Expand Down