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

New adapter: Adhese #3384

Merged
merged 9 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
165 changes: 165 additions & 0 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
'use strict';

import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';

const BIDDER_CODE = 'adhese';
const USER_SYNC_BASE_URL = 'https://user-sync.adhese.com/iframe/user_sync.html';

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

isBidRequestValid: function(bid) {
return !!(bid.params.account && bid.params.location && bid.params.format);
},

mergeTargets: function(targets, target) {
if (target) {
Object.keys(target).forEach(function (key) {
const val = target[key];
const values = Array.isArray(val) ? val : [val];
if (targets[key]) {
const distinctValues = values.filter(v => targets[key].indexOf(v) < 0);
targets[key].push.apply(targets[key], distinctValues);
} else {
targets[key] = values;
}
});
}
return targets;
},

bidToSlotName: function(bid) {
return bid.params.location + '-' + bid.params.format;
},

getAccount: function(validBidRequests) {
return validBidRequests[0].params.account;
},

buildRequests: function(validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return null;
}

const account = this.getAccount(validBidRequests);
const targets = validBidRequests.map(bid => bid.params.data).reduce(this.mergeTargets, {});
const gdprParams = (bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) ? [ 'xt' + bidderRequest.gdprConsent.consentString ] : [];
const targetsParams = Object.keys(targets).map(targetCode => targetCode + targets[targetCode].join(';'));
const slotsParams = validBidRequests.map(bid => 'sl' + this.bidToSlotName(bid));
const params = [...slotsParams, ...targetsParams, ...gdprParams].map(s => '/' + s).join('');
const cacheBuster = '?t=' + new Date().getTime();
const uri = 'https://ads-' + account + '.adhese.com/json' + params + cacheBuster;

return {
method: 'GET',
url: uri,
bids: validBidRequests
};
},

baseAdResponse: function(response) {
return Object.assign({ netRevenue: true, ttl: 360 }, response);
},

isAdheseAd: function(ad) {
return !ad.origin || ad.origin === 'JERLICIA';
},

getMediaType: function(markup) {
const isVideo = markup.trim().toLowerCase().match(/<\?xml|<vast/);
return isVideo ? VIDEO : BANNER;
},

getAdMarkup: function(ad) {
if (!this.isAdheseAd(ad) || (ad.ext === 'js' && ad.body !== undefined && ad.body !== '' && ad.body.match(/<script|<SCRIPT|<html|<HTML|<\?xml/))) {
return ad.body
} else {
return ad.tag;
}
},

getPrice: function (ad) {
if (ad.extension && ad.extension.prebid && ad.extension.prebid.cpm) {
return ad.extension.prebid.cpm;
}
return { amount: 0, currency: 'USD' };
},

getAdDetails: function (ad) {
let creativeId = '';
let dealId = '';

if (this.isAdheseAd(ad)) {
creativeId = ad.id;
dealId = ad.orderId;
} else {
creativeId = ad.origin + (ad.originInstance ? '-' + ad.originInstance : '');
if (ad.originData && ad.originData.seatbid && ad.originData.seatbid.length) {
const seatbid = ad.originData.seatbid[0];
if (seatbid.bid && seatbid.bid.length) {
const bid = seatbid.bid[0];
creativeId = String(bid.crid || '');
dealId = String(bid.dealid || '');
}
}
}
return { creativeId: creativeId, dealId: dealId };
},

adResponse: function(bid, ad) {
const price = this.getPrice(ad);
const adDetails = this.getAdDetails(ad);
const markup = this.getAdMarkup(ad);

const bidResponse = this.baseAdResponse({
requestId: bid.bidId,
mediaType: this.getMediaType(markup),
cpm: Number(price.amount),
currency: price.currency,
width: Number(ad.width),
height: Number(ad.height),
creativeId: adDetails.creativeId,
dealId: adDetails.dealId
});

if (bidResponse.mediaType === VIDEO) {
bidResponse.vastXml = markup;
} else {
const counter = ad.impressionCounter ? "<img src='" + ad.impressionCounter + "' style='height:1px; width:1px; margin: -1px -1px; display:none;'/>" : '';
bidResponse.ad = markup + counter;
}
return bidResponse;
},

interpretResponse: function(serverResponse, request) {
const serverAds = serverResponse.body.reduce(function(map, ad) {
map[ad.slotName] = ad;
return map;
}, {});

serverResponse.account = this.getAccount(request.bids);

return request.bids
.map(bid => ({
bid: bid,
ad: serverAds[this.bidToSlotName(bid)]
}))
.filter(item => item.ad)
.map(item => this.adResponse(item.bid, item.ad));
},

getUserSyncs: function(syncOptions, serverResponse, gdprConsent) {
const account = serverResponse.account || '';
if (syncOptions.iframeEnabled) {
let syncurl = USER_SYNC_BASE_URL + '?account=' + account;
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&consentString=' + encodeURIComponent(gdprConsent.consentString || '');
}
return [{ type: 'iframe', url: syncurl }];
}
}
};
registerBidder(spec);
57 changes: 57 additions & 0 deletions modules/adheseBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Overview

```
Module Name: Adhese Bidder Adapter
Module Type: Bidder Adapter
Maintainer: info@adhese.com
```

# Description

Module that connects with Adhese Adserver and Adhese Gateway. Banner and Video are supported.

# Test Parameters
```
var adUnits = [
{
code: 'test-div1',
mediaTypes: {
banner: {
sizes: [[300, 250]], // a display size
}
},
bids: [
{
bidder: "adhese",
params: {
account: 'demo', // required - the name of your adhese account, if unknown, please contact your sales rep
location: '_main_page_', // required - the location you want to refer to for a specific section or page, as defined in your Adhese inventory
format: 'middle', // required - the format you accept for this unit, as defined in your Adhese inventory
data: { // optional - target params, as defined in your Adhese setup
'ci': ['gent', 'brussels']
'ag': ['55']
'tl': ['all']
}
}
}
]
},{
code: 'test-div2',
mediaTypes: {
banner: {
sizes: [[320, 50]], // a mobile size
}
},
bids: [
{
bidder: "adhese",
params: {
account: 'demo',
location: '_main_page_',
format: 'middle'
}
}
]
}
];
```
Loading