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

Interactive Offers Bid Adapter: add new bid adapter #6399

Merged
9 commits merged into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
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';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add gvlid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what I understand, gvlid is used for the adapter alias, we are not using alias.
Do we have to have an alias so that we have an gvlid?
Captura de ecrã 2021-03-15, às 09 07 12

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i was under the impression that all adapters have gvlid

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only check for w here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As both w and h are fully controlled by the script, and both are set at the same time, I can only look at one of them and know what the other is, in this case the script is grabbing the first size available.
It will be changed in the next commit

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.