Skip to content

Introduce Dailyhunt Bid Adapter for legacy prebid 2.x - LEGACY #4670

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 2 commits into from
Jan 6, 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
192 changes: 192 additions & 0 deletions modules/dailyhuntBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { registerBidder } from '../src/adapters/bidderFactory';
import * as mediaTypes from '../src/mediaTypes';
import * as utils from '../src/utils';

const BIDDER_CODE = 'dailyhunt';
const BIDDER_ALIAS = 'dh';
const SUPPORTED_MEDIA_TYPES = [mediaTypes.BANNER, mediaTypes.NATIVE];

const PROD_PREBID_ENDPOINT_URL = 'https://money.dailyhunt.in/openrtb2/auction';

const PROD_ENDPOINT_URL = 'https://money.dailyhunt.in/openx/ads/index.php';

function buildParams(bid) {
let params = { ...bid.params };
params.pagetype = 'sources';
params.placementId = 12345;
params.env = 'prod';
if (params.testmode && params.testmode === true) {
params.customEvent = 'pb-testmode';
}
let hasWeb5Size = false;
let hasWeb3Size = false;
bid && bid.sizes && bid.sizes.forEach((size, i) => {
if (!hasWeb3Size && size[0] == 300 && size[1] == 250) {
hasWeb3Size = true;
}
if (!hasWeb5Size && (size[0] == 300 || size[0] == 320) && size[1] == 50) {
hasWeb5Size = true;
}
})
params.zone = 'web';
if (!hasWeb3Size && hasWeb5Size) {
params.subSlots = 'web-5';
} else {
params.subSlots = 'web-3';
}
if (bid.nativeParams) {
params.subSlots = 'web-3';
params.ad_type = '2,3';
}
if (!params.partnerId) {
params.partnerId = 'unknown-pb-partner';
}
params.pbRequestId = bid.bidId;
params.format = 'json';
return params;
}

const _encodeURIComponent = function (a) {
let b = window.encodeURIComponent(a);
b = b.replace(/'/g, '%27');
return b;
}

export const spec = {
code: BIDDER_CODE,

aliases: [BIDDER_ALIAS],

supportedMediaTypes: SUPPORTED_MEDIA_TYPES,

isBidRequestValid: bid => !!bid.params.partnerId,

buildRequests: function (validBidRequests, bidderRequest) {
let serverRequests = [];
const userAgent = navigator.userAgent;
const page = bidderRequest.refererInfo.referer;

validBidRequests.forEach((bid, i) => {
let params = buildParams(bid);
let request = '';
if (bid.nativeParams) {
request = {
method: 'GET',
url: PROD_ENDPOINT_URL,
data: utils.parseQueryStringParameters(params)
};
} else {
let ortbReq = {
id: bidderRequest.auctionId,
imp: [{
id: i.toString(),
banner: {
id: 'banner-' + bidderRequest.auctionId,
format: [
{
'h': 250,
'w': 300
},
{
'h': 50,
'w': 320
}
]
},
bidfloor: 0,
ext: {
dailyhunt: {
...params
}
}
}],
site: { id: i.toString(), page },
device: { userAgent },
user: {
id: params.clientId || '',
}
};
request = {
method: 'POST',
url: PROD_PREBID_ENDPOINT_URL,
data: JSON.stringify(ortbReq),
options: {
contentType: 'application/json',
withCredentials: true
},
bids: validBidRequests
};
}
serverRequests.push(request);
});
return serverRequests;
},

interpretResponse: function (serverResponse, request) {
let bidResponses = [];
if (!request.bids) {
let bid = serverResponse.body[0][0].ad;
if (bid.typeId != 2 && bid.typeId != 3) {
return bidResponses;
}
let impTrackers = [];
impTrackers.push(bid.beaconUrl);
impTrackers = (bid.beaconUrlAdditional && bid.beaconUrlAdditional.length !== 0) ? impTrackers.concat(bid.beaconUrlAdditional) : impTrackers;
let bidResponse = {
requestId: bid.pbRequestId,
cpm: bid.price,
creativeId: bid.bannerid,
currency: 'USD',
ttl: 360,
netRevenue: true,
};
bidResponse.mediaType = 'native'
bidResponse.native = {
title: bid.content.itemTitle.data,
body: bid.content.itemSubtitle1.data,
body2: bid.content.itemSubtitle1.data,
cta: bid.content.itemSubtitle2.data,
clickUrl: _encodeURIComponent(bid.action),
impressionTrackers: impTrackers,
clickTrackers: bid.landingUrlAdditional && bid.landingUrlAdditional.length !== 0 ? bid.landingUrlAdditional : [],
image: {
url: bid.content.iconLink,
height: bid.height,
width: bid.width
},
icon: {
url: bid.content.iconLink,
height: bid.height,
width: bid.width
}
}
bidResponses.push(bidResponse);
return bidResponses;
} else {
if (!serverResponse.body) {
return;
}
const { seatbid } = serverResponse.body;
let bids = request.bids;
return bids.reduce((accumulator, bid, index) => {
const _cbid = seatbid && seatbid[index] && seatbid[index].bid;
const bidResponse = _cbid && _cbid[0];
if (bidResponse) {
accumulator.push({
requestId: bid.bidId,
cpm: bidResponse.price,
creativeId: bidResponse.crid,
width: bidResponse.w,
height: bidResponse.h,
ttl: 360,
netRevenue: bid.netRevenue === 'net',
currency: 'USD',
ad: bidResponse.adm
});
}
return accumulator;
}, []);
}
},
}
registerBidder(spec);
69 changes: 69 additions & 0 deletions modules/dailyhuntBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Overview

```
Module Name: Dailyhunt Bid Adapter
Module Type: Bidder Adapter
Maintainer: Dailyhunt
```

# Description

Connects to dailyhunt for bids.

Dailyhunt bid adapter supports Banner and Native.

# Test Parameters
```
var adUnits = [
{
code: '/83414793/prebid_test_display',
sizes: [[300, 250], [320, 50]],
mediaTypes: {
banner : {
sizes: [[300, 250], [320, 50]],
}
},
bids: [
{
bidder: 'dailyhunt',
params: {
partnerId: 'pb-partnerId'
}
}
]
},
{
code: '/83414793/prebid_test_native',
sizes: [[300, 250]],
mediaTypes: {
native: {
title: {
required: true
},
body: {
required: true
},
image: {
required: true
},
cta: {
required: true
}
}
},
bids: [
{
bidder: 'dailyhunt',
params: {
partnerId: 'pb-partnerId'
}
}
]
}
];
```

# CheckList
```
https://drive.google.com/open?id=1t4rmcyHl5OmRF3sYiqBi-VKEjzX6iN-A
```
Loading