Skip to content

Commit

Permalink
Incrx Bid Adapter : add incrementX banner and vast (#12115)
Browse files Browse the repository at this point in the history
* IncrementX VAST Adapter

* Add incrxBidAdapter.md file for banner & video

* Resolved issue:Bidder incrementx is missing required params
  • Loading branch information
Prebid-Vertoz authored Aug 28, 2024
1 parent 87e198f commit 8932942
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 86 deletions.
96 changes: 81 additions & 15 deletions modules/incrxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { parseSizesInput, isEmpty } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js'

import { BANNER, VIDEO } from '../src/mediaTypes.js'
import { OUTSTREAM } from '../src/video.js';
import { Renderer } from '../src/Renderer.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
Expand All @@ -15,7 +16,7 @@ const CREATIVE_TTL = 300;

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],

/**
* Determines whether or not the given bid request is valid.
Expand All @@ -26,7 +27,9 @@ export const spec = {
isBidRequestValid: function (bid) {
return !!(bid.params.placementId);
},

hasTypeVideo(bid) {
return typeof bid.mediaTypes !== 'undefined' && typeof bid.mediaTypes.video !== 'undefined';
},
/**
* Make a server request from the list of BidRequests.
*
Expand All @@ -37,17 +40,29 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes);

let mdType = 0;
if (bidRequest.mediaTypes[BANNER]) {
mdType = 1;
} else {
mdType = 2;
}
const requestParams = {
_vzPlacementId: bidRequest.params.placementId,
sizes: sizes,
_slotBidId: bidRequest.bidId,
// TODO: is 'page' the right value here?
_rqsrc: bidderRequest.refererInfo.page,
mChannel: mdType
};

const payload = {
q: encodeURI(JSON.stringify(requestParams))
let payload;
if (mdType === 1) { // BANNER
payload = {
q: encodeURI(JSON.stringify(requestParams))
};
} else { // VIDEO or other types
payload = {
q: encodeURI(JSON.stringify(requestParams)),
bidderRequestData: encodeURI(JSON.stringify(bidderRequest))
};
}

return {
Expand All @@ -64,30 +79,81 @@ export const spec = {
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse) {
interpretResponse: function (serverResponse, bidderRequest) {
const response = serverResponse.body;
const bids = [];
if (isEmpty(response)) {
return bids;
}
let decodedBidderRequestData;
if (typeof bidderRequest.data.bidderRequestData === 'string') {
decodedBidderRequestData = JSON.parse(decodeURI(bidderRequest.data.bidderRequestData));
} else {
decodedBidderRequestData = bidderRequest.data.bidderRequestData;
}
const responseBid = {
requestId: response.slotBidId,
cpm: response.cpm,
cpm: response.cpm > 0 ? response.cpm : 0,
currency: response.currency || DEFAULT_CURRENCY,
adType: response.adType || '1',
settings: response.settings,
width: response.adWidth,
height: response.adHeight,
width: response.adWidth || 300,
height: response.adHeight || 250,
ttl: CREATIVE_TTL,
creativeId: response.creativeId || 0,
netRevenue: response.netRevenue || false,
mediaType: response.mediaType || BANNER,
meta: {
mediaType: response.mediaType || BANNER,
mediaType: response.mediaType,
advertiserDomains: response.advertiserDomains || []
},
ad: response.ad

};
if (response.mediaType === BANNER) {
responseBid.ad = response.ad || '';
} else if (response.mediaType === VIDEO) {
let context, adUnitCode;
for (let i = 0; i < decodedBidderRequestData.bids.length; i++) {
const item = decodedBidderRequestData.bids[i];
if (item.bidId === response.slotBidId) {
context = item.mediaTypes.video.context;
adUnitCode = item.adUnitCode;
break;
}
}
if (context === OUTSTREAM) {
responseBid.vastXml = response.ad || '';
if (response.rUrl) {
responseBid.renderer = createRenderer({ ...response, adUnitCode });
}
}
}
bids.push(responseBid);
function createRenderer(bid, rendererOptions = {}) {
const renderer = Renderer.install({
id: bid.slotBidId,
url: bid.rUrl,
config: rendererOptions,
adUnitCode: bid.adUnitCode,
loaded: false
});
try {
renderer.setRender(({ renderer, width, height, vastXml, adUnitCode }) => {
renderer.push(() => {
window.onetag.Player.init({
...bid,
width,
height,
vastXml,
nodeId: adUnitCode,
config: renderer.getConfig()
});
});
});
} catch (e) {
}
return renderer;
}
return bids;
}

Expand Down
45 changes: 45 additions & 0 deletions modules/incrxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Overview

```
Module Name: IncrementX Bid Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

IncrementX Bid Adapter supports banner and video at present.

# Test Parameters
```
var adUnits = [
{
code: "banner-space",
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: "incrementx",
params: {
placementId: "your_placementId" // required,
}
}]
}, {
code: 'video-outstream-space',
mediaTypes: {
video: {
context: "outstream",
playerSize: [640,480]
}
},
bids: [{
bidder: "incrementx",
params: {
placementId: "your_placement_id" // required,
}
}]
}];
```
Loading

0 comments on commit 8932942

Please sign in to comment.