Skip to content

Commit

Permalink
Add optable bidder (#11368)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapo authored Apr 22, 2024
1 parent 3384717 commit a3ec0ee
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
42 changes: 42 additions & 0 deletions modules/optableBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js'
const converter = ortbConverter({
context: { netRevenue: true, ttl: 300 },
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
utils.mergeDeep(imp, {
tagid: bidRequest.params.site,
});
return imp;
}
});
const BIDDER_CODE = 'optable';
const DEFAULT_REGION = 'ca'
const DEFAULT_ORIGIN = 'https://ads.optable.co'

export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) { return !!bid.params?.site },
buildRequests: function(bidRequests, bidderRequest) {
const region = config.getConfig('optable.region') ?? DEFAULT_REGION
const origin = config.getConfig('optable.origin') ?? DEFAULT_ORIGIN
const requestURL = `${origin}/${region}/ortb2/v1/ssp/bid`
const data = converter.toORTB({ bidRequests, bidderRequest, context: { mediaType: BANNER } });

return { method: 'POST', url: requestURL, data }
},
interpretResponse: function(response, request) {
const bids = converter.fromORTB({ response: response.body, request: request.data }).bids
const auctionConfigs = (response.body.ext?.optable?.fledge?.auctionconfigs ?? []).map((cfg) => {
const { impid, ...config } = cfg;
return { bidId: impid, config }
})

return { bids, fledgeAuctionConfigs: auctionConfigs }
},
supportedMediaTypes: [BANNER]
}
registerBidder(spec);
41 changes: 41 additions & 0 deletions modules/optableBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Overview

```
Module Name: Optable Bidder Adapter
Module Type: Bidder Adapter
Maintainer: prebid@optable.co
```

# Description

Module that connects to Optable's demand sources.

# Bid Parameters
## Banner

| Name | Scope | Type | Description | Example
| ---- | ----- | ---- | ----------- | -------
| `site` | required | String | Optable site ID provided by your Optable representative. | "aaaaaaaa"

## Video

Not supported at the moment.

# Example
```javascript
var adUnits = [
{
code: 'test-div',
sizes: [[728, 90]], // a display size
mediaTypes: {'banner': {}},
bids: [
{
bidder: 'optable',
params: {
site: 'aaaaaaaa',
},
},
],
},
];
```
89 changes: 89 additions & 0 deletions test/spec/modules/optableBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { expect } from 'chai';
import { spec } from 'modules/optableBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory.js';

describe('optableBidAdapter', function() {
const adapter = newBidder(spec);

describe('isBidRequestValid', function() {
const validBid = {
bidder: 'optable',
params: { site: '123' },
};

it('should return true when required params are present', function() {
expect(spec.isBidRequestValid(validBid)).to.be.true;
});

it('should return false when site is missing', function() {
const invalidBid = { ...validBid };
delete invalidBid.params.site;
expect(spec.isBidRequestValid(invalidBid)).to.be.false;
});
});

describe('buildRequests', function() {
const validBid = {
bidder: 'optable',
params: {
site: '123',
},
};

const bidderRequest = {
bidderRequestId: 'bid123',
refererInfo: {
domain: 'example.com',
page: 'https://example.com/page',
ref: 'https://referrer.com'
},
};

it('should include site as tagid in imp', function() {
const request = spec.buildRequests([validBid], bidderRequest);
expect(request.url).to.equal('https://ads.optable.co/ca/ortb2/v1/ssp/bid');
expect(request.method).to.equal('POST');
expect(request.data.imp[0].tagid).to.equal('123')
});
});

describe('interpretResponse', function() {
const validBid = {
bidder: 'optable',
params: {
site: '123',
},
};

const bidderRequest = {
bidderRequestId: 'bid123',
refererInfo: {
domain: 'example.com',
page: 'https://example.com/page',
ref: 'https://referrer.com'
},
};

const response = {
body: {
ext: {
optable: {
fledge: {
auctionconfigs: [
{ impid: 'bid123', seller: 'https://ads.optable.co' },
]
}
}
}
}
};

it('maps fledgeAuctionConfigs from ext.optable.fledge.auctionconfigs', function() {
const request = spec.buildRequests([validBid], bidderRequest);
const result = spec.interpretResponse(response, request);
expect(result.fledgeAuctionConfigs).to.deep.equal([
{ bidId: 'bid123', config: { seller: 'https://ads.optable.co' } }
]);
});
});
});

0 comments on commit a3ec0ee

Please sign in to comment.