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

Cedato new bid adapter #3629

Merged
merged 2 commits into from
Mar 26, 2019
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
154 changes: 154 additions & 0 deletions modules/cedatoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const BIDDER_CODE = 'cedato';
const BID_URL = '//h.cedatoplayer.com/hb';
const SYNC_URL = '//h.cedatoplayer.com/hb_usync?uid={UUID}';
const COOKIE_NAME = 'hb-cedato-id';
const UUID_LEN = 36;
const TTL = 10000;
const CURRENCY = 'USD';
const FIRST_PRICE = 1;
const NET_REVENUE = true;

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

isBidRequestValid: function(bid) {
return !!(
bid &&
bid.params &&
bid.params.player_id &&
utils.checkCookieSupport() &&
utils.cookiesAreEnabled()
);
},

buildRequests: function(bidRequests, bidderRequest) {
const req = bidRequests[Math.floor(Math.random() * bidRequests.length)];
const params = req.params;
const at = FIRST_PRICE;
const site = { id: params.player_id, domain: document.domain };
const device = { ua: navigator.userAgent, ip: '' };
const user = { id: getUserID() }
const cur = [ CURRENCY ];
const tmax = bidderRequest.timeout;

const imp = bidRequests.map(req => {
const banner = { 'format': getFormats(utils.deepAccess(req, 'mediaTypes.banner.sizes')) };
const bidfloor = params.bidfloor !== undefined
? Number(params.bidfloor) : 1;
const bidfloorcur = CURRENCY;
const bidId = req.bidId;

return {
bidId,
banner,
bidfloor,
bidfloorcur,
};
});

const payload = {
at,
site,
device,
user,
imp,
cur,
tmax,
};

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr_consent = {
consent_string: bidderRequest.gdprConsent.consentString,
consent_required: bidderRequest.gdprConsent.gdprApplies
};
}

return {
method: 'POST',
url: BID_URL,
data: JSON.stringify(payload),
};
},

interpretResponse: function(resp) {
if (resp.body === '') return [];

const bids = resp.body.seatbid[0].bid.map(bid => {
const cpm = bid.price;
const requestId = bid.uuid;
const width = bid.w;
const height = bid.h;
const creativeId = bid.crid;
const dealId = bid.dealid;
const currency = resp.body.cur;
const netRevenue = NET_REVENUE;
const ttl = TTL;
const ad = bid.adm;

return {
cpm,
requestId,
width,
height,
creativeId,
dealId,
currency,
netRevenue,
ttl,
ad,
};
});

return bids;
},

getUserSyncs: function(syncOptions, resps, gdprConsent) {
const syncs = [];
if (syncOptions.pixelEnabled) {
resps.forEach(() => {
const uuid = getUserID();
const syncUrl = SYNC_URL;
let params = '';
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
if (typeof gdprConsent.gdprApplies === 'boolean') {
params += `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
params += `?gdpr_consent=${gdprConsent.consentString}`;
}
}
syncs.push({
type: 'image',
url: syncUrl.replace('{UUID}', uuid) + params,
});
});
}
return syncs;
}
}

const getUserID = () => {
const cookieName = COOKIE_NAME;
const uuidLen = UUID_LEN;

const i = document.cookie.indexOf(cookieName);

if (i === -1) {
const uuid = utils.generateUUID();
document.cookie = `${cookieName}=${uuid}; path=/`;
return uuid;
}

const j = i + cookieName.length + 1;
return document.cookie.substring(j, j + uuidLen);
};

const getFormats = arr => arr.map((s) => {
return { w: s[0], h: s[1] };
});

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

```
Module Name: Cedato Bidder Adapter
Module Type: Bidder Adapter
Maintainer: alexk@cedato.com
```

# Description

Connects to Cedato bidder.
Cedato adapter supports only Banner at the moment.

# Test Parameters
```
var adUnits = [
// Banner
{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
// You can choose one of them
sizes: [
[300, 250],
[300, 600],
[240, 400],
[728, 90],
]
}
},
bids: [
{
bidder: "cedato",
params: {
player_id: 1450133326,
}
}
]
}
];

pbjs.que.push(() => {
pbjs.setConfig({
userSync: {
syncEnabled: true,
enabledBidders: ['cedato'],
pixelEnabled: true,
syncsPerBidder: 200,
syncDelay: 100,
},
});
});
```
87 changes: 87 additions & 0 deletions test/spec/modules/cedatoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {expect} from 'chai';
import {spec} from 'modules/cedatoBidAdapter';

describe('the cedato adapter', function () {
function getValidBidObject() {
return {
bidId: 123,
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
player_id: 1450133326,
}
};
};

describe('isBidRequestValid', function() {
var bid;

beforeEach(function() {
bid = getValidBidObject();
});

it('should fail validation if the bid isn\'t defined or not an object', function() {
var result = spec.isBidRequestValid();

expect(result).to.equal(false);

result = spec.isBidRequestValid('not an object');

expect(result).to.equal(false);
});
});
describe('buildRequests', function() {
var bid, bidRequestObj;

beforeEach(function() {
bid = getValidBidObject();
bidRequestObj = {refererInfo: {referer: 'prebid.js'}};
});

it('should build a very basic request', function() {
var request = spec.buildRequests([bid], bidRequestObj);
expect(request.method).to.equal('POST');
});
});

describe('interpretResponse', function() {
var serverResponse;

beforeEach(function() {
serverResponse = {
body: {
bidid: '0.36157306192821',
seatbid: [
{
seat: '0',
bid: [{
gp: {
'negative': 0.496954,
'positive': 0.503046,
'class': '0'
},
id: '0.75549202124378',
adomain: 'cedato.com',
uuid: '2f4a613a702b6c',
crid: '1450133326',
adm: "<div id=\"cedato-unit\"></div>\n<script src=\"https://p.cedatoplayer.com/zplayer.js?p=952030718&cb=874433&d=localhost\" type=\"text/javascript\"></script>\n<img src='//h.cedatoplayer.com/hbwon?cb=874433&p=0.1&pi=952030718&w=300&h=250&s=952030718&d=localhost&u=a4657bf1-c373-4676-b79a-0d9de0129e38&ab=2' width=\"1\" height=\"1\"/>\n",
h: 250,
w: 300,
price: '0.1'
}]
}
],
cur: 'USD'
}
};
});

it('should return an array of bid responses', function() {
var responses = spec.interpretResponse(serverResponse);
expect(responses).to.be.an('array').with.length(1);
});
});
});