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

LunamediaHB bid adapter #5906

Merged
merged 13 commits into from
Nov 6, 2020
104 changes: 104 additions & 0 deletions modules/lunamediahbBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'lunamediahb';
const AD_URL = 'https://balancer.lmgssp.com/?c=o&m=multi';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
!bid.ttl || !bid.currency) {
return false;
}
switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl);
case NATIVE:
return Boolean(bid.native && bid.native.impressionTrackers);
default:
return false;
}
}

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

isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.placementId)));
},

buildRequests: (validBidRequests = [], bidderRequest) => {
let winTop = window;
let location;
try {
location = new URL(bidderRequest.refererInfo.referer)
winTop = window.top;
} catch (e) {
location = winTop.location;
utils.logMessage(e);
};

const placements = [];
const request = {
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'language': (navigator && navigator.language) ? navigator.language.split('-')[0] : '',
'secure': 1,
'host': location.host,
'page': location.pathname,
'placements': placements
};

if (bidderRequest) {
if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
}

const len = validBidRequests.length;
for (let i = 0; i < len; i++) {
const bid = validBidRequests[i];
const placement = {
placementId: bid.params.placementId,
bidId: bid.bidId,
traffic: bid.params.traffic || BANNER,
ncolletti marked this conversation as resolved.
Show resolved Hide resolved
schain: bid.schain || {},
};

if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) {
placement.sizes = bid.mediaTypes[BANNER].sizes;
} else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) {
placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0];
placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1];
} else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) {
placement.native = bid.mediaTypes[NATIVE];
}
placements.push(placement);
}

return {
method: 'POST',
url: AD_URL,
data: request
};
},

interpretResponse: (serverResponse) => {
let response = [];
for (let i = 0; i < serverResponse.body.length; i++) {
let resItem = serverResponse.body[i];
if (isBidResponseValid(resItem)) {
response.push(resItem);
}
}
return response;
},
};

registerBidder(spec);
80 changes: 80 additions & 0 deletions modules/lunamediahbBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Overview

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

# Description

Module that connects to lunamedia demand sources

# Test Parameters
```
var adUnits = [
// Will return static test banner
{
code: 'adunit1',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
bids: [
{
bidder: 'lunamediahb',
params: {
placementId: 0,
traffic: 'banner'
ncolletti marked this conversation as resolved.
Show resolved Hide resolved
}
}
]
},
// Will return test vast xml. All video params are stored under placement in publishers UI
{
code: 'addunit2',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids: [
{
bidder: 'lunamediahb',
params: {
placementId: 0,
traffic: 'video'
}
}
]
},
{
code: 'addunit3',
mediaTypes: {
native: {
title: {
required: true
},
body: {
required: true
},
icon: {
required: true,
size: [64, 64]
}
}
},
bids: [
{
bidder: 'lunamediahb',
params: {
placementId: 0,
traffic: 'native'
}
}
]
}
];
```
Loading