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

OwnAdX Bid Adapter : initial release #11855

Merged
merged 2 commits into from
Jul 18, 2024
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
99 changes: 99 additions & 0 deletions modules/ownadxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { parseSizesInput, isEmpty } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js'

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
*/

const BIDDER_CODE = 'ownadx';
const CUR = 'USD';
const CREATIVE_TTL = 300;

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) {
return !!(bid.params.tokenId && bid.params.sspId && bid.params.seatId);
},

/**
* Make a server request from the list of BidRequests.
*
* @param validBidRequests
* @param bidderRequest
* @return Array Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes);
let mtype = 0;
if (bidRequest.mediaTypes[BANNER]) {
mtype = 1;
} else {
mtype = 2;
}

let tkn = bidRequest.params.tokenId;
let seatid = bidRequest.params.seatId;
let sspid = bidRequest.params.sspId;

const payload = {
sizes: sizes,
slotBidId: bidRequest.bidId,
PageUrl: bidderRequest.refererInfo.page,
mediaChannel: mtype
};
return {
method: 'POST',
url: `https://pbs-js.prebid-ownadx.com/publisher/prebid/${seatid}/${sspid}?token=${tkn}`,
data: payload
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse) {
const response = serverResponse.body;
const bids = [];
if (isEmpty(response)) {
return bids;
}
const responseBid = {
width: response.width,
height: response.height,
token: response.tokenId,
ttl: CREATIVE_TTL,
requestId: response.slotBidId,
aType: response.adType || '1',
cpm: response.cpm,
creativeId: response.creativeId || 0,
netRevenue: response.netRevenue || false,
currency: response.currency || CUR,
meta: {
mediaType: response.mediaType || BANNER,
advertiserDomains: response.advertiserDomains || []
},
ad: response.adm
};
bids.push(responseBid);
return bids;
}

};

registerBidder(spec);
103 changes: 103 additions & 0 deletions test/spec/modules/ownadxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { expect } from 'chai';
import { spec } from 'modules/ownadxBidAdapter.js';

describe('ownadx', function () {
const METHOD = 'POST';
const URL = 'https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4';

const bidRequest = {
bidder: 'ownadx',
params: {
tokenId: '3f2941af4f7e446f9a19ca6045f8cff4',
sspId: '1231',
seatId: '9'
},
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
sizes: [
[300, 250],
[300, 600]
],
bidId: 'bid-id-123456',
adUnitCode: 'ad-unit-code-1',
bidderRequestId: 'bidder-request-id-123456',
auctionId: 'auction-id-123456',
transactionId: 'transaction-id-123456'
};

describe('isBidRequestValid', function () {
it('should return true where required params found', function () {
expect(spec.isBidRequestValid(bidRequest)).to.equal(true);
});
});

describe('buildRequests', function () {
let bidderRequest = {
refererInfo: {
page: 'https://www.test.com',
reachedTop: true,
isAmp: false,
numIframes: 0,
stack: [
'https://www.test.com'
],
canonicalUrl: null
}
};

it('should build correct POST request for banner bid', function () {
const request = spec.buildRequests([bidRequest], bidderRequest)[0];
expect(request).to.be.an('object');
expect(request.method).to.equal('POST');
expect(request.url).to.equal('https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4');
const payload = request.data;
expect(payload).to.be.an('object');
expect(payload.sizes).to.be.an('array');
expect(payload.slotBidId).to.be.a('string');
expect(payload.PageUrl).to.be.a('string');
expect(payload.mediaChannel).to.be.a('number');
});
});

describe('interpretResponse', function () {
let serverResponse = {
body: {
tokenId: '3f2941af4f7e446f9a19ca6045f8cff4',
bid: 'BID-XXXX-XXXX',
width: '300',
height: '250',
cpm: '0.7',
adm: '<html><h1>Ad from OwnAdX</h1></html>',
slotBidId: 'bid-id-123456',
adType: '1',
statusText: 'Success'
}
};

let expectedResponse = [{
token: '3f2941af4f7e446f9a19ca6045f8cff4',
requestId: 'bid-id-123456',
cpm: '0.7',
currency: 'USD',
aType: '1',
netRevenue: false,
width: '300',
height: '250',
creativeId: 0,
ttl: 300,
ad: '<html><h1>Ad from OwnAdX</h1></html>',
meta: {
mediaType: 'banner',
advertiserDomains: []
}
}];

it('should correctly interpret valid banner response', function () {
let result = spec.interpretResponse(serverResponse);
expect(result).to.deep.equal(expectedResponse);
});
});
});