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

Readpeak Bid Adapter: add banner support #8179

Merged
merged 1 commit into from
Mar 24, 2022
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
41 changes: 30 additions & 11 deletions modules/readpeakBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError, replaceAuctionPrice, parseUrl } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { NATIVE } from '../src/mediaTypes.js';
import { NATIVE, BANNER } from '../src/mediaTypes.js';

export const ENDPOINT = 'https://app.readpeak.com/header/prebid';

Expand All @@ -19,10 +19,9 @@ const BIDDER_CODE = 'readpeak';
export const spec = {
code: BIDDER_CODE,

supportedMediaTypes: [NATIVE],
supportedMediaTypes: [NATIVE, BANNER],

isBidRequestValid: bid =>
!!(bid && bid.params && bid.params.publisherId && bid.nativeParams),
isBidRequestValid: bid => !!(bid && bid.params && bid.params.publisherId),

buildRequests: (bidRequests, bidderRequest) => {
const currencyObj = config.getConfig('currency');
Expand All @@ -31,8 +30,7 @@ export const spec = {
const request = {
id: bidRequests[0].bidderRequestId,
imp: bidRequests
.map(slot => impression(slot))
.filter(imp => imp.native != null),
.map(slot => impression(slot)),
site: site(bidRequests, bidderRequest),
app: app(bidRequests),
device: device(),
Expand Down Expand Up @@ -96,10 +94,16 @@ function bidResponseAvailable(bidRequest, bidResponse) {
creativeId: idToBidMap[id].crid,
ttl: 300,
netRevenue: true,
mediaType: NATIVE,
currency: bidResponse.cur,
native: nativeResponse(idToImpMap[id], idToBidMap[id])
mediaType: idToImpMap[id].native ? NATIVE : BANNER,
currency: bidResponse.cur
};
if (idToImpMap[id].native) {
bid.native = nativeResponse(idToImpMap[id], idToBidMap[id]);
} else if (idToImpMap[id].banner) {
bid.ad = idToBidMap[id].adm
bid.width = idToBidMap[id].w
bid.height = idToBidMap[id].h
}
if (idToBidMap[id].adomain) {
bid.meta = {
advertiserDomains: idToBidMap[id].adomain
Expand All @@ -121,13 +125,19 @@ function impression(slot) {
});
bidFloorFromModule = floorInfo.currency === 'USD' ? floorInfo.floor : undefined;
}
return {
const imp = {
id: slot.bidId,
native: nativeImpression(slot),
bidfloor: bidFloorFromModule || slot.params.bidfloor || 0,
bidfloorcur: (bidFloorFromModule && 'USD') || slot.params.bidfloorcur || 'USD',
tagId: slot.params.tagId || '0'
};

if (slot.mediaTypes.native) {
imp.native = nativeImpression(slot);
} else if (slot.mediaTypes.banner) {
imp.banner = bannerImpression(slot);
}
return imp
}

function nativeImpression(slot) {
Expand Down Expand Up @@ -218,6 +228,15 @@ function dataAsset(id, params, type, defaultLen) {
: null;
}

function bannerImpression(slot) {
var sizes = slot.mediaTypes.banner.sizes || slot.sizes;
return {
format: sizes.map((s) => ({ w: s[0], h: s[1] })),
w: sizes[0][0],
h: sizes[0][1],
}
}

function site(bidRequests, bidderRequest) {
const url =
config.getConfig('pageUrl') ||
Expand Down
55 changes: 43 additions & 12 deletions modules/readpeakBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,48 @@ Please reach out to your account team or hello@readpeak.com for more information

# Test Parameters
```javascript
var adUnits = [{
code: '/19968336/prebid_native_example_2',
mediaTypes: { native: { type: 'image' } },
bids: [{
bidder: 'readpeak',
params: {
bidfloor: 5.00,
publisherId: 'test',
siteId: 'test',
tagId: 'test-tag-1'
var adUnits = [
{
code: '/19968336/prebid_native_example_2',
mediaTypes: {
native: {
title: {
required: true
},
image: {
required: true
},
body: {
required: true
},
}
},
}]
}];
bids: [{
bidder: 'readpeak',
params: {
bidfloor: 5.00,
publisherId: 'test',
siteId: 'test',
tagId: 'test-tag-1'
},
}]
},
{
code: '/19968336/prebid_banner_example_2',
mediaTypes: {
banner: {
sizes: [[640, 320], [300, 600]],
}
},
bids: [{
bidder: 'readpeak',
params: {
bidfloor: 5.00,
publisherId: 'test',
siteId: 'test',
tagId: 'test-tag-2'
},
}]
}
];
```
Loading