From 02aeae074da8dff8e8f320c8638ec60fa5e6daaa Mon Sep 17 00:00:00 2001 From: Dmitri Date: Fri, 26 Mar 2021 18:13:08 +0100 Subject: [PATCH 01/12] Adding smartico adapter --- modules/smarticoBidAdapter.js | 131 +++++++++++++++++++ modules/smarticoBidAdapter.md | 38 ++++++ test/spec/modules/smarticoBidAdapter_spec.js | 118 +++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 modules/smarticoBidAdapter.js create mode 100644 modules/smarticoBidAdapter.md create mode 100644 test/spec/modules/smarticoBidAdapter_spec.js diff --git a/modules/smarticoBidAdapter.js b/modules/smarticoBidAdapter.js new file mode 100644 index 00000000000..4c952f1f6a4 --- /dev/null +++ b/modules/smarticoBidAdapter.js @@ -0,0 +1,131 @@ +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER } from '../src/mediaTypes.js'; + +const SMARTICO_CONFIG = { + bidRequestUrl: 'https://trmads.eu/preBidRequest', + widgetUrl: 'https://trmads.eu/get', + method: 'POST' +} + +const BIDDER_CODE = 'smartico'; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + isBidRequestValid: function (bid) { + return !!(bid.params.token && bid.params.placementId); + }, + buildRequests: function (validBidRequests, bidderRequest) { + var i + var j + var bid + var bidParam + var bidParams = [] + var sizes + var frameWidth = Math.round(window.screen.width) + var frameHeight = Math.round(window.screen.height) + for (i = 0; i < validBidRequests.length; i++) { + bid = validBidRequests[i] + if (bid.sizes) { + sizes = bid.sizes + } else if (typeof (BANNER) != 'undefined' && bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { + sizes = bid.mediaTypes[BANNER].sizes + } else if (frameWidth && frameHeight) { + sizes = [[frameWidth, frameHeight]] + } else { + sizes = [] + } + for (j = 0; j < sizes.length; j++) { + bidParam = { + token: bid.params.token || '', + bidId: bid.bidId, + 'banner-format-width': sizes[j][0], + 'banner-format-height': sizes[j][1] + } + if (bid.params.bannerFormat) { + bidParam['banner-format'] = bid.params.bannerFormat + } + if (bid.params.language) { + bidParam.language = bid.params.language + } + if (bid.params.regions) { + bidParam.regions = bid.params.regions + } + if (bid.params.region) { + bidParam.region = bid.params.region + } + if (bidParam.regions && bidParam.regions instanceof Array && bidParam.regions.length) { + bidParam.regions = bidParam.regions.join(',') + } else { + delete bidParam.regions + } + bidParams.push(bidParam) + } + } + + var ServerRequestObjects = { + method: SMARTICO_CONFIG.method, + url: SMARTICO_CONFIG.bidRequestUrl, + bids: validBidRequests, + data: {bidParams: bidParams, auctionId: bidderRequest.auctionId} + } + + return ServerRequestObjects; + }, + interpretResponse: function (serverResponse, bidRequest) { + function getBidById(responceBidId) { + if (responceBidId) { + var i, bid + for (i = 0; i < bidRequest.bids.length; i++) { + bid = bidRequest.bids[i] + if (bid.bidId == responceBidId) { + return bid + } + } + } + return false + } + + var i + var bid + var bidObject + var url + var html + var ad + var token + var language + var scriptId + var bidRespones = [] + + for (i = 0; i < serverResponse.length; i++) { + ad = serverResponse[i]; + bid = getBidById(ad.bidId); + + if (bid) { + token = bid.params.token || ''; + + language = bid.params.language || SMARTICO_CONFIG.language || '' + + scriptId = encodeURIComponent('smartico-widget-' + bid.params.placementId + '-' + i) + + url = SMARTICO_CONFIG.widgetUrl + '?token=' + encodeURIComponent(token) + '&auction-id=' + encodeURIComponent(bid.auctionId) + '&from-auction-buffer=1&own_session=1&ad=' + encodeURIComponent(ad.id) + '&scriptid=' + scriptId + (ad.bannerFormatAlias ? '&banner-format=' + encodeURIComponent(ad.bannerFormatAlias) : '') + (language ? '&language=' + encodeURIComponent(language) : '') + + html = '