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

InteractiveOffers : parameters changed & dynamic endpoint #7286

Merged
merged 7 commits into from
Aug 11, 2021
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
68 changes: 42 additions & 26 deletions modules/interactiveOffersBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {config} from '../src/config.js';
import * as utils from '../src/utils.js';

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

const DEFAULT = {
'OpenRTBBidRequest': {},
Expand Down Expand Up @@ -35,8 +35,8 @@ export const spec = {
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');
if (!bid.params.partnerId) {
utils.logWarn('partnerId must be a valid ID');
ret = false;
}
if (bid.params.tmax && !utils.isNumber(bid.params.tmax)) {
Expand All @@ -50,25 +50,33 @@ export const spec = {
return ret;
},
buildRequests: function(validBidRequests, bidderRequest) {
let payload = parseRequestPrebidjsToOpenRTB(bidderRequest);
let aux = parseRequestPrebidjsToOpenRTB(bidderRequest);
let payload = aux.payload;
return {
method: 'POST',
url: ENDPOINT,
url: ENDPOINT + aux.partnerId,
data: JSON.stringify(payload),
bidderRequest: bidderRequest
};
},

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

function parseRequestPrebidjsToOpenRTB(prebidRequest) {
let ret = {
payload: {},
partnerId: null
};
let pageURL = window.location.href;
let domain = window.location.hostname;
let secure = (window.location.protocol == 'https:' ? 1 : 0);
Expand Down Expand Up @@ -105,12 +113,15 @@ function parseRequestPrebidjsToOpenRTB(prebidRequest) {
openRTBRequest.imp = [];
prebidRequest.bids.forEach(function(bid, impId) {
impId++;
if (!ret.partnerId) {
ret.partnerId = bid.params.partnerId;
}
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.site.publisher.id = openRTBRequest.site.publisher.id || 0;
openRTBRequest.tmax = openRTBRequest.tmax || bid.params.tmax || 0;

Object.keys(bid.mediaTypes).forEach(function(mediaType) {
Expand All @@ -130,31 +141,36 @@ function parseRequestPrebidjsToOpenRTB(prebidRequest) {
});
openRTBRequest.imp.push(imp);
});
return openRTBRequest;
ret.payload = openRTBRequest;
return ret;
}
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;
prebid.width = bid.w;
prebid.height = bid.h;
prebid.mediaType = 'banner';
prebid.meta = {
advertiserDomains: bid.adomain,
advertiserId: bid.adid,
mediaType: 'banner',
primaryCatId: bid.cat[0] || '',
secondaryCatIds: bid.cat
if (response.seatbid && response.seatbid.forEach) {
response.seatbid.forEach(function(seatbid) {
if (seatbid.bid && seatbid.bid.forEach) {
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;
prebid.width = bid.w;
prebid.height = bid.h;
prebid.mediaType = 'banner';
prebid.meta = {
advertiserDomains: bid.adomain,
advertiserId: bid.adid,
mediaType: 'banner',
primaryCatId: bid.cat[0] || '',
secondaryCatIds: bid.cat
}
prebidResponse.push(prebid);
});
}
prebidResponse.push(prebid);
});
});
}
});
return prebidResponse;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/interactiveOffersBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Maintainer: [email protected]

# Description

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

# Test Parameters
```
Expand All @@ -24,7 +24,7 @@ Module that connects to interactiveOffers demand sources. Param pubid is require
{
bidder: "interactiveOffers",
params: {
pubid: 10,
partnerId: "abcd1234",
tmax: 250
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/spec/modules/interactiveOffersBidAdapter_spec.js

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