|
| 1 | +import * as utils from '../src/utils'; |
| 2 | +import {registerBidder} from '../src/adapters/bidderFactory'; |
| 3 | +import {BANNER, NATIVE} from '../src/mediaTypes.js'; |
| 4 | + |
| 5 | +const RTB_URL = '/rtb/getbid.php?rtbprovider=prebid'; |
| 6 | +const SCRIPT_URL = '/adasync.min.js'; |
| 7 | +export const spec = { |
| 8 | + code : 'adspirit', |
| 9 | + aliases : ['xapadsmedia', 'connectad','twiago'], |
| 10 | + supportedMediaTypes: [BANNER, NATIVE], |
| 11 | + |
| 12 | + isBidRequestValid: function (bid) |
| 13 | + { |
| 14 | + let host = spec.getBidderHost(bid); |
| 15 | + if(!host) |
| 16 | + { |
| 17 | + return false; |
| 18 | + } |
| 19 | + if(!bid.params.placementId) |
| 20 | + { |
| 21 | + return false; |
| 22 | + } |
| 23 | + return true; |
| 24 | + }, |
| 25 | + buildRequests : function (validBidRequests, bidderRequest) |
| 26 | + { |
| 27 | + let requests = []; |
| 28 | + let bidRequest; |
| 29 | + let reqUrl; |
| 30 | + let placementId; |
| 31 | + for(let i = 0; i < validBidRequests.length; i++) |
| 32 | + { |
| 33 | + bidRequest = validBidRequests[i]; |
| 34 | + bidRequest.adspiritConId = spec.genAdConId(bidRequest); |
| 35 | + reqUrl = spec.getBidderHost(bidRequest); |
| 36 | + placementId = utils.getBidIdParameter('placementId', bidRequest.params); |
| 37 | + reqUrl = '//' + reqUrl + RTB_URL + '&pid=' + placementId + '&ref=' + encodeURIComponent(bidderRequest.refererInfo.topmostLocation) + '&scx=' + (screen.width) + '&scy=' + (screen.height) + '&wcx=' + ('innerWidth' in window ? window.innerWidth : page.clientWidth) + '&wcy=' + ('innerHeight' in window ? window.innerHeight : page.clientHeight) + '&async=' + bidRequest.adspiritConId + '&t=' + Math.round( |
| 38 | + Math.random() * 100000); |
| 39 | + requests.push({ |
| 40 | + method : 'GET', |
| 41 | + url : reqUrl, |
| 42 | + data : {}, |
| 43 | + bidRequest: bidRequest |
| 44 | + }); |
| 45 | + } |
| 46 | + return requests; |
| 47 | + }, |
| 48 | + interpretResponse: function (serverResponse, bidRequest) |
| 49 | + { |
| 50 | + const bidResponses = []; |
| 51 | + let bidObj = bidRequest.bidRequest; |
| 52 | + |
| 53 | + if(!serverResponse || !serverResponse.body || !bidObj) |
| 54 | + { |
| 55 | + utils.logWarn(`No valid bids from ${spec.code} bidder!`); |
| 56 | + return []; |
| 57 | + } |
| 58 | + let adData = serverResponse.body; |
| 59 | + let cpm = adData.cpm; |
| 60 | + if(!cpm) |
| 61 | + { |
| 62 | + return []; |
| 63 | + } |
| 64 | + |
| 65 | + let host = spec.getBidderHost(bidObj); |
| 66 | + if('mediaTypes' in bidObj && 'native' in bidObj.mediaTypes) |
| 67 | + { |
| 68 | + const bidResponse = { |
| 69 | + requestId : bidObj.bidId, |
| 70 | + cpm : cpm, |
| 71 | + width : adData.w, |
| 72 | + height : adData.h, |
| 73 | + creativeId: bidObj.params.placementId, |
| 74 | + currency : 'EUR', |
| 75 | + netRevenue: true, |
| 76 | + ttl : 300, |
| 77 | + native : { |
| 78 | + title : adData.title, |
| 79 | + body : adData.body, |
| 80 | + cta : adData.cta, |
| 81 | + image : {url: adData.image}, |
| 82 | + clickUrl : adData.click, |
| 83 | + impressionTrackers: [adData.view] |
| 84 | + }, |
| 85 | + mediaType : NATIVE |
| 86 | + }; |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + let adm = '<scr' + 'ipt>window.inDapIF=false</scr' + 'ipt><scr' + 'ipt src="//' + host + SCRIPT_URL + '"></scr' + 'ipt>' + '<ins id="' + bidObj.adspiritConId + '"></ins>' + adData.adm; |
| 91 | + |
| 92 | + const bidResponse = { |
| 93 | + requestId : bidObj.bidId, |
| 94 | + cpm : cpm, |
| 95 | + width : adData.w, |
| 96 | + height : adData.h, |
| 97 | + creativeId: bidObj.params.placementId, |
| 98 | + currency : 'EUR', |
| 99 | + netRevenue: true, |
| 100 | + ttl : 300, |
| 101 | + ad : adm, |
| 102 | + mediaType : BANNER |
| 103 | + }; |
| 104 | + } |
| 105 | + bidResponses.push(bidResponse); |
| 106 | + return bidResponses; |
| 107 | + }, |
| 108 | + getBidderHost : function (bid) |
| 109 | + { |
| 110 | + if(bid.bidder === 'adspirit') |
| 111 | + { |
| 112 | + return utils.getBidIdParameter('host', bid.params); |
| 113 | + } |
| 114 | + if(bid.bidder === 'connectad') |
| 115 | + { |
| 116 | + return 'connected-by.connectad.io'; |
| 117 | + } |
| 118 | + if(bid.bidder === 'xapadsmedia') |
| 119 | + { |
| 120 | + return 'dsp.xapads.com'; |
| 121 | + } |
| 122 | + return null; |
| 123 | + }, |
| 124 | + genAdConId : function (bid) |
| 125 | + { |
| 126 | + return bid.bidder + Math.round(Math.random() * 100000); |
| 127 | + } |
| 128 | +}; |
| 129 | +registerBidder(spec); |
0 commit comments