Skip to content

Commit

Permalink
Interactive Offers Bid Adapter: add new bid adapter (prebid#6399)
Browse files Browse the repository at this point in the history
* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* Interactive Offers bid adapter

* manually kicking off tests

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
2 people authored and stsepelin committed May 28, 2021
1 parent c895280 commit 7cf7fd5
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 6 deletions.
149 changes: 149 additions & 0 deletions modules/interactiveOffersBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'interactiveOffers';
const ENDPOINT = 'https://rtb.ioadx.com/bidRequest/?partnerId=4a3bab187a74ac4862920cca864d6eff195ff5e4';

const DEFAULT = {
'OpenRTBBidRequest': {},
'OpenRTBBidRequestSite': {},
'OpenRTBBidRequestSitePublisher': {},
'OpenRTBBidRequestSiteContent': {
language: navigator.language,
},
'OpenRTBBidRequestSource': {},
'OpenRTBBidRequestDevice': {
ua: navigator.userAgent,
language: navigator.language
},
'OpenRTBBidRequestUser': {},
'OpenRTBBidRequestImp': {},
'OpenRTBBidRequestImpBanner': {},
'PrebidBid': {
currency: 'USD',
ttl: 60,
netRevenue: false
}
};

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

isBidRequestValid: function(bid) {
let ret = true;
if (bid && bid.params) {
if (!utils.isNumber(bid.params.pubid)) {
utils.logWarn('pubid must be a valid numeric ID');
ret = false;
}
if (bid.params.tmax && !utils.isNumber(bid.params.tmax)) {
utils.logWarn('tmax must be a valid numeric ID');
ret = false;
}
} else {
utils.logWarn('invalid request');
ret = false;
}
return ret;
},
buildRequests: function(validBidRequests, bidderRequest) {
let payload = parseRequestPrebidjsToOpenRTB(bidderRequest);
return {
method: 'POST',
url: ENDPOINT,
data: JSON.stringify(payload),
bidderRequest: bidderRequest
};
},

interpretResponse: function(response, request) {
let bidResponses = [];
if (response.body && response.body.length) {
bidResponses = parseResponseOpenRTBToPrebidjs(response.body);
}
return bidResponses;
}
};

function parseRequestPrebidjsToOpenRTB(prebidRequest) {
let pageURL = window.location.href;
let domain = window.location.hostname;
let secure = (window.location.protocol == 'https:' ? 1 : 0);
let openRTBRequest = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequest']));
openRTBRequest.id = prebidRequest.auctionId;

openRTBRequest.site = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestSite']));
openRTBRequest.site.id = domain;
openRTBRequest.site.name = domain;
openRTBRequest.site.domain = domain;
openRTBRequest.site.page = pageURL;
openRTBRequest.site.ref = prebidRequest.refererInfo.referer;

openRTBRequest.site.publisher = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestSitePublisher']));
openRTBRequest.site.publisher.id = 0;
openRTBRequest.site.publisher.name = config.getConfig('publisherDomain');
openRTBRequest.site.publisher.domain = domain;
openRTBRequest.site.publisher.domain = domain;

openRTBRequest.site.content = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestSiteContent']));

openRTBRequest.source = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestSource']));
openRTBRequest.source.fd = 0;
openRTBRequest.source.tid = prebidRequest.auctionId;
openRTBRequest.source.pchain = '';

openRTBRequest.device = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestDevice']));

openRTBRequest.user = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestUser']));

openRTBRequest.imp = [];
prebidRequest.bids.forEach(function(bid, impId) {
impId++;
let imp = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestImp']));
imp.id = impId;
imp.secure = secure;
imp.tagid = bid.bidId;

openRTBRequest.site.publisher.id = openRTBRequest.site.publisher.id || bid.params.pubid;
openRTBRequest.tmax = openRTBRequest.tmax || bid.params.tmax || 0;

Object.keys(bid.mediaTypes).forEach(function(mediaType) {
if (mediaType == 'banner') {
imp.banner = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestImpBanner']));
imp.banner.w = 0;
imp.banner.h = 0;
imp.banner.format = [];
bid.mediaTypes[mediaType].sizes.forEach(function(adSize) {
if (!imp.banner.w) {
imp.banner.w = adSize[0];
imp.banner.h = adSize[1];
}
imp.banner.format.push({w: adSize[0], h: adSize[1]});
});
}
});
openRTBRequest.imp.push(imp);
});
return openRTBRequest;
}
function parseResponseOpenRTBToPrebidjs(openRTBResponse) {
let prebidResponse = [];
openRTBResponse.forEach(function(response) {
response.seatbid.forEach(function(seatbid) {
seatbid.bid.forEach(function(bid) {
let prebid = JSON.parse(JSON.stringify(DEFAULT['PrebidBid']));
prebid.requestId = bid.ext.tagid;
prebid.ad = bid.adm;
prebid.creativeId = bid.crid;
prebid.cpm = bid.price;
prebidResponse.push(prebid);
});
});
});
return prebidResponse;
}

registerBidder(spec);
12 changes: 6 additions & 6 deletions modules/interactiveOffersBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overview

```
Module Name: interactiveOffers Bidder Adapter
Module Type: Bidder Adapter
Maintainer: devteam@interactiveoffers.com
Maintainer: faria@interactiveoffers.com
```

# Description

Module that connects to interactiveOffers demand sources. Param pubId is required.
Module that connects to interactiveOffers demand sources. Param pubid is required.

# Test Parameters
```
Expand All @@ -24,11 +24,11 @@ Module that connects to interactiveOffers demand sources. Param pubId is require
{
bidder: "interactiveOffers",
params: {
pubId: '10',
tmax: 5000
pubid: 10,
tmax: 250
}
}
]
}
];
```
```
42 changes: 42 additions & 0 deletions test/spec/modules/interactiveOffersBidAdapter_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7cf7fd5

Please sign in to comment.