Skip to content

Commit

Permalink
Feature/support macros (#11)
Browse files Browse the repository at this point in the history
* 2.44.6-pre release

* feat(ccpa) : ccpa and pos added to legacy adapter (prebid#4817)

* 2.44.6 release

* Increment pre version

* ViewdeosDX outstream support in legacy (prebid#4766)

* add outstream params extension

* update outsream version

* Change enpoint to geo-balanced

* Coverage increased

* Prebid 2.44.7 Release

* Add support AUCTION_PRICE:B64

Co-authored-by: Matt Kendall <1870166+mkendall07@users.noreply.github.com>
Co-authored-by: sourabhg <sourabhg@users.noreply.github.com>
Co-authored-by: Mike Chowla <mike.chowla@pubmatic.com>
Co-authored-by: Gena <wertixvost@gmail.com>
Co-authored-by: Jaimin Panchal <email@example.com>
  • Loading branch information
6 people committed Jul 2, 2020
1 parent 11e633a commit 96dc925
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 15 deletions.
12 changes: 9 additions & 3 deletions modules/deepintentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ export const spec = {
imp: validBidRequests.map(bid => buildImpression(bid)),
site: buildSite(bidderRequest),
device: buildDevice(),
user: user && user.length == 1 ? user[0] : {}
user: user && user.length == 1 ? user[0] : {},
};

if (bidderRequest && bidderRequest.uspConsent) {
utils.deepSetValue(openRtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

return {
method: 'POST',
url: BIDDER_ENDPOINT,
Expand Down Expand Up @@ -127,13 +131,15 @@ function buildBanner(bid) {
if (utils.isArray(sizes) && sizes.length > 0) {
return {
h: sizes[0][1],
w: sizes[0][0]
w: sizes[0][0],
pos: bid && bid.params && bid.params.pos ? bid.params.pos : 0
}
}
} else {
return {
h: bid.params.height,
w: bid.params.width
w: bid.params.width,
pos: bid && bid.params && bid.params.pos ? bid.params.pos : 0
}
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/deepintentBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Module that connects to Deepintent's demand sources.
tagId: '1300', // Required parameter
w: 300, // Width and Height here will override sizes in mediatype
h: 250,
pos: 1,
custom: { // Custom parameters in form of key value pairs
user_min_age: 18
}
Expand Down
39 changes: 39 additions & 0 deletions modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ function validateSizes(sizes) {
);
}

function base64Encode(string) {
string = String(string);

if (typeof window.btoa !== 'undefined') {
return window.btoa(string)
}

// Polyfill
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var bitmap;
var a;
var b;
var c;
var result = '';
var i = 0;
var rest = string.length % 3;

for (; i < string.length;) {
if ((a = string.charCodeAt(i++)) > 255 ||
(b = string.charCodeAt(i++)) > 255 ||
(c = string.charCodeAt(i++)) > 255) { throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."); }

bitmap = (a << 16) | (b << 8) | c;
result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) +
b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
}

return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
Expand Down Expand Up @@ -269,6 +299,15 @@ export const spec = {

return syncs;
},

onBidWon: function(winObj) {
const cpm = winObj.cpm;

winObj.ad = winObj.ad.replace(
/\${AUCTION_PRICE:B64}/,
base64Encode(cpm)
);
},
};

registerBidder(spec);
23 changes: 15 additions & 8 deletions modules/viewdeosDXBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {VIDEO, BANNER} from '../src/mediaTypes';
import {Renderer} from '../src/Renderer';
import findIndex from 'core-js/library/fn/array/find-index';

const URL = '//hb.sync.viewdeos.com/auction/';
const OUTSTREAM_SRC = '//player.sync.viewdeos.com/outstream-unit/2.01/outstream.min.js';
const URL = '//ghb.sync.viewdeos.com/auction/';
const OUTSTREAM_SRC = '//player.sync.viewdeos.com/outstream-unit/2.11/outstream-unit.min.js';
const BIDDER_CODE = 'viewdeosDX';
const OUTSTREAM = 'outstream';
const DISPLAY = 'display';
Expand Down Expand Up @@ -112,7 +112,8 @@ function parseRTBResponse(serverResponse, bidderRequest) {
});

if (serverBid.cpm !== 0 && requestId !== -1) {
const bid = createBid(serverBid, getMediaType(bidderRequest.bids[requestId]));
const bidReq = bidderRequest.bids[requestId];
const bid = createBid(serverBid, getMediaType(bidReq), bidReq.params);

bids.push(bid);
}
Expand All @@ -131,6 +132,10 @@ function bidToTag(bidRequests, bidderRequest) {
tag.gdpr_consent = utils.deepAccess(bidderRequest, 'gdprConsent.consentString');
}

if (utils.deepAccess(bidderRequest, 'bidderRequest.uspConsent')) {
tag.us_privacy = bidderRequest.uspConsent;
}

for (let i = 0, length = bidRequests.length; i < length; i++) {
Object.assign(tag, prepareRTBRequestParams(i, bidRequests[i]));
}
Expand Down Expand Up @@ -174,7 +179,7 @@ function getMediaType(bidderRequest) {
* @param mediaType {Object}
* @returns {object}
*/
function createBid(bidResponse, mediaType) {
function createBid(bidResponse, mediaType, bidderParams) {
const bid = {
requestId: bidResponse.requestId,
creativeId: bidResponse.cmpId,
Expand All @@ -201,7 +206,7 @@ function createBid(bidResponse, mediaType) {
Object.assign(bid, {
mediaType: 'video',
adResponse: bidResponse,
renderer: newRenderer(bidResponse.requestId)
renderer: newRenderer(bidResponse.requestId, bidderParams)
});
}

Expand All @@ -213,10 +218,11 @@ function createBid(bidResponse, mediaType) {
* @param requestId
* @returns {*}
*/
function newRenderer(requestId) {
function newRenderer(requestId, bidderParams) {
const renderer = Renderer.install({
id: requestId,
url: OUTSTREAM_SRC,
config: bidderParams.outstream || {},
loaded: false
});

Expand All @@ -231,12 +237,13 @@ function newRenderer(requestId) {
*/
function outstreamRender(bid) {
bid.renderer.push(() => {
window.VOutstreamAPI.initOutstreams([{
const opts = Object.assign({}, bid.renderer.getConfig(), {
width: bid.width,
height: bid.height,
vastUrl: bid.vastUrl,
elId: bid.adUnitCode
}]);
});
window.VOutstreamAPI.initOutstreams([opts]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "2.44.5",
"version": "2.44.7",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down
20 changes: 19 additions & 1 deletion test/spec/modules/deepintentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Deepintent adapter', function () {
tagId: '100013',
w: 728,
h: 90,
pos: 1,
user: {
id: 'di_testuid',
buyeruid: 'di_testbuyeruid',
Expand Down Expand Up @@ -129,6 +130,11 @@ describe('Deepintent adapter', function () {
expect(data.imp[0].ext).to.be.a('object');
expect(data.imp[0].ext.deepintent.position).to.equal('right-box');
});
it('bid request check: position check', function () {
let bRequest = spec.buildRequests(request);
let data = JSON.parse(bRequest.data);
expect(data.imp[0].banner.pos).to.equal(1);
});
it('bid request check: displaymanager check', function() {
let bRequest = spec.buildRequests(request);
let data = JSON.parse(bRequest.data);
Expand All @@ -143,7 +149,19 @@ describe('Deepintent adapter', function () {
expect(data.user.buyeruid).to.equal('di_testbuyeruid');
expect(data.user.yob).to.equal(2002);
expect(data.user.gender).to.equal('F');
})
});
it('bid request check: CCPA Check', function () {
let bidRequest = {
uspConsent: '1NYN'
};
let bRequest = spec.buildRequests(request, bidRequest);
let data = JSON.parse(bRequest.data);
expect(data.regs.ext.us_privacy).to.equal('1NYN');
let bidRequest2 = {};
let bRequest2 = spec.buildRequests(request, bidRequest2);
let data2 = JSON.parse(bRequest2.data);
expect(data2.regs).to.equal(undefined);
});
});
describe('user sync check', function () {
it('user sync url check', function () {
Expand Down
33 changes: 31 additions & 2 deletions test/spec/modules/viewdeosDXBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect} from 'chai';
import {spec} from 'modules/viewdeosDXBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';

const ENDPOINT = '//hb.sync.viewdeos.com/auction/';
const ENDPOINT = '//ghb.sync.viewdeos.com/auction/';

const DISPLAY_REQUEST = {
'bidder': 'viewdeos',
Expand Down Expand Up @@ -44,6 +44,8 @@ const SERVER_VIDEO_RESPONSE = {
]
};

const SERVER_OUSTREAM_VIDEO_RESPONSE = SERVER_VIDEO_RESPONSE;

const SERVER_DISPLAY_RESPONSE = {
'source': {'aid': 12345, 'pubId': 54321},
'bids': [{
Expand Down Expand Up @@ -74,6 +76,25 @@ const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = {
'cookieURLSTypes': ['image', 'iframe']
};

const outstreamVideoBidderRequest = {
bidderCode: 'bidderCode',
bids: [{
'params': {
'aid': 12345,
'outstream': {
'video_controls': 'show'
}
},
mediaTypes: {
video: {
context: 'outstream',
playerSize: [640, 480]
}
},
bidId: '2e41f65424c87c'
}]
};

const videoBidderRequest = {
bidderCode: 'bidderCode',
bids: [{mediaTypes: {video: {}}, bidId: '2e41f65424c87c'}]
Expand Down Expand Up @@ -119,9 +140,17 @@ const displayEqResponse = [{
cpm: 0.9
}];

describe('viewdeosDXBidAdapter', function () { // todo remove only
describe('viewdeosDXBidAdapter', function () {
const adapter = newBidder(spec);

describe('when outstream params are passing properly', function() {
const videoBids = spec.interpretResponse({body: SERVER_OUSTREAM_VIDEO_RESPONSE}, {bidderRequest: outstreamVideoBidderRequest});
it('should return renderer with expected outstream params config', function() {
expect(!!videoBids[0].renderer).to.equal(true);
expect(videoBids[0].renderer.getConfig().video_controls).to.equal('show');
})
})

describe('user syncs as image', function () {
it('should be returned if pixel enabled', function () {
const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]);
Expand Down

0 comments on commit 96dc925

Please sign in to comment.