Skip to content

Commit

Permalink
New haxmedia bidder adapter (prebid#6001)
Browse files Browse the repository at this point in the history
  • Loading branch information
haxmediagithub authored Nov 23, 2020
1 parent 022bcea commit cebae4a
Show file tree
Hide file tree
Showing 3 changed files with 483 additions and 0 deletions.
107 changes: 107 additions & 0 deletions modules/haxmediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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 = 'haxmedia';
const AD_URL = 'https://balancer.haxmedia.io/?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,
schain: bid.schain || {},
};
const mediaType = bid.mediaTypes

if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) {
placement.sizes = mediaType[BANNER].sizes;
placement.traffic = BANNER;
} else if (mediaType && mediaType[VIDEO] && mediaType[VIDEO].playerSize) {
placement.wPlayer = mediaType[VIDEO].playerSize[0];
placement.hPlayer = mediaType[VIDEO].playerSize[1];
placement.traffic = VIDEO;
} else if (mediaType && mediaType[NATIVE]) {
placement.native = mediaType[NATIVE];
placement.traffic = 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);
72 changes: 72 additions & 0 deletions modules/haxmediaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Overview

```
Module Name: haxmedia Bidder Adapter
Module Type: haxmedia Bidder Adapter
Maintainer: haxmixqk@haxmediapartners.io
```

# Description

Module that connects to haxmedia demand sources

# Test Parameters
```
var adUnits = [
{
code:'1',
mediaTypes:{
banner: {
sizes: [[300, 250]],
}
},
bids:[
{
bidder: 'haxmedia',
params: {
placementId: 0
}
}
]
},
{
code:'1',
mediaTypes:{
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids:[
{
bidder: 'haxmedia',
params: {
placementId: 0
}
}
]
},
{
code:'1',
mediaTypes:{
native: {
title: {
required: true
},
icon: {
required: true,
size: [64, 64]
}
}
},
bids:[
{
bidder: 'haxmedia',
params: {
placementId: 0
}
}
]
}
];
```
Loading

0 comments on commit cebae4a

Please sign in to comment.