|
| 1 | +import {BANNER, VIDEO} from '../src/mediaTypes.js'; |
| 2 | +import {config} from '../src/config.js'; |
| 3 | +import {registerBidder} from '../src/adapters/bidderFactory.js'; |
| 4 | +import {spec as baseAdapter} from './appnexusBidAdapter.js'; // eslint-disable-line prebid/validate-imports |
| 5 | + |
| 6 | +const BIDDER_CODE = 'big-richmedia'; |
| 7 | + |
| 8 | +const metadataByRequestId = {}; |
| 9 | + |
| 10 | +export const spec = { |
| 11 | + version: '1.4.0', |
| 12 | + code: BIDDER_CODE, |
| 13 | + gvlid: baseAdapter.GVLID, // use base adapter gvlid |
| 14 | + supportedMediaTypes: [ BANNER, VIDEO ], |
| 15 | + |
| 16 | + /** |
| 17 | + * Determines whether or not the given bid request is valid. |
| 18 | + * |
| 19 | + * @param {object} bid The bid to validate. |
| 20 | + * @return boolean True if this is a valid bid, and false otherwise. |
| 21 | + */ |
| 22 | + isBidRequestValid: function (bid) { |
| 23 | + if (!baseAdapter.isBidRequestValid) { return true; } |
| 24 | + return baseAdapter.isBidRequestValid(bid); |
| 25 | + }, |
| 26 | + |
| 27 | + /** |
| 28 | + * Make a server request from the list of BidRequests. |
| 29 | + * |
| 30 | + * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. |
| 31 | + * @return ServerRequest Info describing the request to the server. |
| 32 | + */ |
| 33 | + buildRequests: function (bidRequests, bidderRequest) { |
| 34 | + if (!baseAdapter.buildRequests) { return []; } |
| 35 | + |
| 36 | + const publisherId = config.getConfig('bigRichmedia.publisherId'); |
| 37 | + if (typeof publisherId !== 'string') { return []; } |
| 38 | + |
| 39 | + bidRequests.forEach(bidRequest => { |
| 40 | + if (bidRequest.params.format === 'skin' && bidRequest.mediaTypes.banner) { |
| 41 | + bidRequest.mediaTypes.banner.sizes.push([1800, 1000]); |
| 42 | + } |
| 43 | + metadataByRequestId[bidRequest.bidId] = { placementId: bidRequest.adUnitCode, bidder: bidRequest.bidder }; |
| 44 | + }); |
| 45 | + return baseAdapter.buildRequests(bidRequests, bidderRequest); |
| 46 | + }, |
| 47 | + |
| 48 | + /** |
| 49 | + * Unpack the response from the server into a list of bids. |
| 50 | + * |
| 51 | + * @param {*} serverResponse A successful response from the server. |
| 52 | + * @return {Bid[]} An array of bids which were nested inside the server. |
| 53 | + */ |
| 54 | + interpretResponse: function (serverResponse, params) { |
| 55 | + const publisherId = config.getConfig('bigRichmedia.publisherId'); |
| 56 | + if (typeof publisherId !== 'string') { return []; } |
| 57 | + |
| 58 | + const bids = baseAdapter.interpretResponse(serverResponse, params); |
| 59 | + bids.forEach(bid => { |
| 60 | + const { placementId, bidder } = metadataByRequestId[bid.requestId] || {}; |
| 61 | + const { width = 1, height = 1, ad, creativeId = '', cpm, vastXml, vastUrl } = bid; |
| 62 | + const bidRequest = params.bidderRequest.bids.find(({ bidId }) => bidId === bid.requestId); |
| 63 | + const format = (bidRequest && bidRequest.params && bidRequest.params.format) || 'video-sticky-footer'; |
| 64 | + const isReplayable = bidRequest && bidRequest.params && bidRequest.params.isReplayable; |
| 65 | + const customSelector = bidRequest && bidRequest.params && bidRequest.params.customSelector; |
| 66 | + const renderParams = { |
| 67 | + adm: ad, |
| 68 | + vastXml, |
| 69 | + vastUrl, |
| 70 | + width, |
| 71 | + height, |
| 72 | + placementId, |
| 73 | + bidId: bid.requestId, |
| 74 | + creativeId: `${creativeId}`, |
| 75 | + bidder, |
| 76 | + cpm, |
| 77 | + format, |
| 78 | + customSelector, |
| 79 | + isReplayable |
| 80 | + }; |
| 81 | + const encoded = window.btoa(JSON.stringify(renderParams)); |
| 82 | + bid.ad = `<script src="//cdn.hubvisor.io/wrapper/${publisherId}/richmedia-renderer.js" async="true"></script> |
| 83 | + <script>var hbvrm = hbvrm || {}; hbvrm.cmd = hbvrm.cmd || []; hbvrm.cmd.push(function() { hbvrm.render('${encoded}'); });</script>`; |
| 84 | + |
| 85 | + if (bid.mediaType !== 'banner') { // in case this is a video |
| 86 | + bid.mediaType = 'banner'; |
| 87 | + delete bid.renderer; |
| 88 | + delete bid.vastUrl; |
| 89 | + delete bid.vastXml; |
| 90 | + bid.width = 1; |
| 91 | + bid.height = 1; |
| 92 | + } |
| 93 | + }); |
| 94 | + return bids; |
| 95 | + }, |
| 96 | + |
| 97 | + getUserSyncs: function (syncOptions, responses, gdprConsent) { |
| 98 | + if (!baseAdapter.getUserSyncs) { return []; } |
| 99 | + return baseAdapter.getUserSyncs(syncOptions, responses, gdprConsent); |
| 100 | + }, |
| 101 | + |
| 102 | + transformBidParams: function (params, isOpenRtb) { |
| 103 | + if (!baseAdapter.transformBidParams) { return params; } |
| 104 | + return baseAdapter.transformBidParams(params, isOpenRtb); |
| 105 | + }, |
| 106 | + |
| 107 | + /** |
| 108 | + * Add element selector to javascript tracker to improve native viewability |
| 109 | + * @param {Bid} bid |
| 110 | + */ |
| 111 | + onBidWon: function (bid) { |
| 112 | + if (!baseAdapter.onBidWon) { return; } |
| 113 | + baseAdapter.onBidWon(bid); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +registerBidder(spec); |
0 commit comments