Skip to content

JW Demand: Implemented buildRequests. #26

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

Merged
Merged
Changes from 1 commit
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
92 changes: 91 additions & 1 deletion modules/jwplayerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
// import { config } from 'src/config';
import { VIDEO } from '../src/mediaTypes.js';
import { deepSetValue, isFn } from '../src/utils.js';

const BIDDER_CODE = 'jwplayer';
const URL = 'https://ib.adnxs.com/openrtb2/prebid';

const GVLID = 1046;
const SUPPORTED_AD_TYPES = [VIDEO];

Expand All @@ -30,9 +33,24 @@ export const spec = {
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @param bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {},
buildRequests: function(bidRequests, bidderRequest) {
if (!bidRequests) {
return;
}

return bidRequests.map(bidRequest => {
const payload = buildRequest(bidRequest, bidderRequests);

return {
method: 'POST',
url: URL,
data: payload
}
});
},

/**
* Unpack the response from the server into a list of bids.
Expand All @@ -50,4 +68,76 @@ export const spec = {
// onBidderError: function({ error, bidderRequest }) {}
};

function buildRequest(bidRequest, bidderRequest) {
const {params} = bidRequest;

const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {});
const videoBidderParams = deepAccess(bidRequest, 'params.video', {});

const videoParams = {
...videoAdUnit,
...videoBidderParams
}

const video = {
w: parseInt(videoParams.playerSize[0][0], 10),
h: parseInt(videoParams.playerSize[0][1], 10)
}

// Bid FLoor
const bidFloorRequest = {
currency: bidRequest.params.cur || 'USD',
mediaType: 'video',
size: '*'
};

let floorData = bidRquest.params;
if (isFn(bidRequest.getFloor)) {
floorData = bidRequest.getFloor(bidFloorRequest);
} else {
if (params.bidfloor) {
floorData = {floor: params.bidfloor, currency: params.currency || 'USD'};
}
}

// Open RTB Request Object
const openrtbRequest = {
id: bidRequest.bidId,
imp: [
{
id: '1',
video: video,
secure: isSecure() ? 1 : 0,
bidfloor: floorData.floor,
bidfloorcur: floorData.currency
}
],
site: {
domain: window.location.hostname,
page: window.location.href,
ref: bidRequest.refererInfo ? bidRequest.refererInfo.referer || null : null
},
ext: {
hb: 1,
prebidver: '$prebid.version$',
adapterver: spec.VERSION
}
}

// content

// Attaching GDPR Consent Params
if (bidderRequest.gdprConsent) {
deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
}

// CCPA
if (bidderRequest.uspConsent) {
deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

return JSON.stringify(openrtbRequest);
}

registerBidder(spec);