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

ZetaSsp Bid Adapter: add new bid adapter #6432

Merged
merged 6 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
152 changes: 152 additions & 0 deletions modules/zetaSspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const BIDDER_CODE = 'zeta_global_ssp';
const ENDPOINT_URL = 'https:/ssp.disqus.com/bid';
const USER_SYNC_URL = 'https:/ssp.disqus.com/match';
const DEFAULT_CUR = 'USD';
const TTL = 200;
const NET_REV = true;

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

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
// check for all required bid fields
if (!(bid &&
bid.bidId &&
bid.params)) {
utils.logWarn('Invalid bid request - missing required bid data');
return false;
}
return true;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {Bids[]} validBidRequests - an array of bidRequest objects
* @param {BidderRequest} bidderRequest - master bidRequest object
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
const secure = 1; // treat all requests as secure
const request = validBidRequests[0];
const params = request.params;
let impData = {
id: request.bidId,
secure: secure,
banner: buildBanner(request)
};
let payload = {
id: bidderRequest.auctionId,
cur: [DEFAULT_CUR],
imp: [impData],
site: params.site ? params.site : {},
device: params.device ? params.device : {},
user: params.user ? params.user : {},
app: params.app ? params.app : {},
ext: {
tags: params.tags ? params.tags : {}
}
};

payload.device.ua = navigator.userAgent;
payload.site.page = bidderRequest.refererInfo.referer;
payload.site.mobile = /(ios|ipod|ipad|iphone|android)/i.test(navigator.userAgent) ? 1 : 0;

if (params.test) {
payload.test = params.test;
}
if (request.gdprConsent) {
payload.regs = {
ext: {
gdpr: request.gdprConsent.gdprApplies === true ? 1 : 0
}
};
}
if (request.gdprConsent && request.gdprConsent.gdprApplies) {
payload.user = {
ext: {
consent: request.gdprConsent.consentString
}
};
}
return {
method: 'POST',
url: ENDPOINT_URL,
data: JSON.stringify(payload),
};
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest The payload from the server's response.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
let bidResponse = [];
if (Object.keys(serverResponse.body).length !== 0) {
let zetaResponse = serverResponse.body;
let zetaBid = zetaResponse.seatbid[0].bid[0];
let bid = {
requestId: zetaBid.impid,
cpm: zetaBid.price,
currency: zetaResponse.cur,
width: zetaBid.w,
height: zetaBid.h,
ad: zetaBid.adm,
ttl: TTL,
creativeId: zetaBid.crid,
netRevenue: NET_REV
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
};
bidResponse.push(bid);
}
return bidResponse;
},

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @param gdprConsent The GDPR consent parameters
* @param uspConsent The USP consent parameters
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: USER_SYNC_URL
});
}
return syncs;
}
}

function buildBanner(request) {
let sizes = request.sizes;
if (request.mediaTypes &&
request.mediaTypes.banner &&
request.mediaTypes.banner.sizes) {
sizes = request.mediaTypes.banner.sizes;
}
return {
w: sizes[0][0],
h: sizes[0][1]
};
}

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

```
Module Name: Zeta Ssp Bidder Adapter
Module Type: Bidder Adapter
Maintainer: miakovlev@zetaglobal.com
```

# Description

Module that connects to Zeta's SSP

# Test Parameters
```
var adUnits = [
{
mediaTypes: {
banner: {
sizes: [[300, 250]], // a display size
}
},
bids: [
{
bidder: 'zeta_global_ssp',
bidId: 12345,
params: {
placement: 12345,
user: {
uid: 12345,
buyeruid: 12345
},
device: {
ip: '111.222.33.44',
geo: {
country: 'USA'
}
},
tags: {
someTag: 123
},
test: 1
}
}
]
}
];
```
86 changes: 86 additions & 0 deletions test/spec/modules/zetaSspBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { spec } from '../../../modules/zetaSspBidAdapter.js'

describe('Zeta Ssp Bid Adapter', function() {
const bannerRequest = [{
bidId: 12345,
auctionId: 67890,
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
refererInfo: {
referer: 'zetaglobal.com'
},
params: {
placement: 12345,
user: {
uid: 12345,
buyeruid: 12345
},
device: {
ip: '111.222.33.44',
geo: {
country: 'USA'
}
},
tags: {
someTag: 123
},
test: 1
}
}];

it('Test the bid validation function', function() {
const validBid = spec.isBidRequestValid(bannerRequest[0]);
const invalidBid = spec.isBidRequestValid(null);

expect(validBid).to.be.true;
expect(invalidBid).to.be.false;
});

it('Test the request processing function', function () {
const request = spec.buildRequests(bannerRequest, bannerRequest[0]);
expect(request).to.not.be.empty;

const payload = request.data;
expect(payload).to.not.be.empty;
});

const responseBody = {
id: '12345',
seatbid: [
{
bid: [
{
id: 'auctionId',
impid: 'impId',
price: 0.0,
adm: 'adMarkup',
crid: 'creativeId',
h: 250,
w: 300
}
]
}
],
cur: 'USD'
};

it('Test the response parsing function', function () {
const receivedBid = responseBody.seatbid[0].bid[0];
const response = {};
response.body = responseBody;

const bidResponse = spec.interpretResponse(response, null);
expect(bidResponse).to.not.be.empty;

const bid = bidResponse[0];
expect(bid).to.not.be.empty;
expect(bid.ad).to.equal(receivedBid.adm);
expect(bid.cpm).to.equal(receivedBid.price);
expect(bid.height).to.equal(receivedBid.h);
expect(bid.width).to.equal(receivedBid.w);
expect(bid.requestId).to.equal(receivedBid.impid);
});
});