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

PE-123: Add More Metadata in site.ext.blockthrough #5

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
31 changes: 13 additions & 18 deletions modules/BTBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { deepSetValue, isBoolean, isStr, logWarn } from '../src/utils.js';
import { deepSetValue, isPlainObject, logWarn } from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';

Expand Down Expand Up @@ -32,8 +32,16 @@ function imp(buildImp, bidRequest, context) {
const { params, ortb2Imp } = bidRequest;

if (params) {
const { siteId, ab, ...btBidParams } = params;
Object.assign(imp, { ext: btBidParams });
const { blockthrough, ...btBidderParams } = params;

deepSetValue(imp, 'ext', btBidderParams);
if (blockthrough.auctionID) {
deepSetValue(
imp,
'ext.prebid.blockthrough.auctionID',
blockthrough.auctionID
);
}
}
if (ortb2Imp?.ext.gpid) {
deepSetValue(imp, 'gpid', ortb2Imp.ext.gpid);
Expand All @@ -53,12 +61,6 @@ function imp(buildImp, bidRequest, context) {
*/
function request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
const { params } = bidderRequest.bids?.[0] || {};

if (params) {
const { ab, siteId } = params;
deepSetValue(request, 'site.ext.blockthrough', { ab, siteId });
}
if (config.getConfig('debug')) {
request.test = 1;
}
Expand Down Expand Up @@ -89,15 +91,8 @@ function bidResponse(buildBidResponse, bid, context) {
* @returns {boolean} True if the bid request is valid, false otherwise.
*/
function isBidRequestValid(bid) {
const { ab, siteId } = bid.params;

if (!siteId || !isStr(siteId)) {
logWarn('BT Bid Adapter: a string type "siteId" must be provided.');
return false;
}

if (!isBoolean(ab)) {
logWarn('BT Bid Adapter: a boolean type "ab" must be provided.');
if (!isPlainObject(bid.params) || !Object.keys(bid.params).length) {
logWarn('BT Bid Adapter: bid params must be provided.');
return false;
}

Expand Down
76 changes: 51 additions & 25 deletions modules/BTBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,63 @@

The BT Bidder Adapter provides an interface to the BT Service. The BT Bidder Adapter sends one request to the BT Service per ad unit. Behind the scenes, the BT Service further disperses requests to various configured exchanges. This operational model closely resembles that of Prebid Server, where a single request is made from the client side, and responses are gathered from multiple exchanges.

The BT adapter requires setup and approval from the Blockthrough team. Please reach out to [email protected] for more information.

# Bid Params

| Key | Scope | Type | Description |
| ------ | -------- | ------- | -------------------------------------------------------------- |
| ab | Required | Boolean | Whether AdBlock is enabled. |
| siteId | Required | String | Unique site ID. |
| bidder | Required | Object | Bidder configuration. Could configure several bidders this way |
| Key | Scope | Type | Description |
| ------ | -------- | ------ | -------------------------------------------------------------- |
| bidder | Required | Object | Bidder configuration. Could configure several bidders this way |

## AdUnits configuration example
# Bidder Config

Make sure to set ab, orgID, websiteID values received after approval using `pbjs.setBidderConfig`.

## Example

```javascript
pbjs.setBidderConfig({
bidders: ['blockthrough'],
config: {
ortb2: {
site: {
ext: {
blockthrough: {
ab: false,
orgID: 'orgID',
websiteID: 'websiteID',
},
},
},
},
},
});
```
var adUnits = [{
code: 'banner-div-1',
mediaTypes: {
banner: {
sizes: [[728, 90]]
}

## AdUnits configuration example

```javascript
var adUnits = [
{
code: 'banner-div-1',
mediaTypes: {
banner: {
sizes: [[728, 90]],
},
bids: [{
},
bids: [
{
bidder: 'blockthrough',
params: {
ab: true,
siteId: '12345',
bidderA: {
publisherId: 55555,
},
bidderB: {
zoneId: 12,
}
}
}]
}];

bidderA: {
publisherId: 55555,
},
bidderB: {
zoneId: 12,
},
},
},
],
},
];
```
18 changes: 8 additions & 10 deletions test/spec/modules/BTBidAdapte_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ describe('BT Bid Adapter', () => {
adUnitCode: 'adunit-code',
mediaTypes: { [BANNER]: { sizes: [[300, 250]] } },
params: {
ab: true,
siteId: '55555',
blockthrough: {
auctionID: 'auctionID',
},
bidderA: {
pubId: '11111',
},
},
bidderRequestId: 'test-bidder-request-id',
auctionId: 'test-auction-id',
},
];
const bidderRequest = {
auctionId: 'test-auction-id',
bidderCode: 'blockthrough',
bidderRequestId: 'test-bidder-request-id',
bids: validBidRequests,
Expand All @@ -45,8 +44,6 @@ describe('BT Bid Adapter', () => {
it('should validate bid request with valid params', () => {
const validBid = {
params: {
ab: true,
siteId: 'exampleSiteId',
pubmatic: {
publisherId: 55555,
},
Expand Down Expand Up @@ -77,20 +74,21 @@ describe('BT Bid Adapter', () => {

describe('buildRequests', () => {
it('should build post request when ortb2 fields are present', () => {
const bidderParams = {
const impExtParams = {
bidderA: {
pubId: '11111',
},
prebid: {
blockthrough: { auctionID: 'auctionID' },
},
};

const requests = spec.buildRequests(validBidRequests, bidderRequest);

expect(requests[0].method).to.equal('POST');
expect(requests[0].url).to.equal(ENDPOINT_URL);
expect(requests[0].data).to.exist;
expect(requests[0].data.imp[0].ext).to.deep.equal(bidderParams);
expect(requests[0].data.site.ext.blockthrough.ab).to.be.true;
expect(requests[0].data.site.ext.blockthrough.siteId).to.equal('55555');
expect(requests[0].data.imp[0].ext).to.deep.equal(impExtParams);
});
});

Expand Down