|
| 1 | +import {registerBidder} from '../src/adapters/bidderFactory.js'; |
| 2 | +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; |
| 3 | +import * as utils from '../src/utils.js'; |
| 4 | + |
| 5 | +const BIDDER_CODE = 'e_volution'; |
| 6 | +const AD_URL = 'https://service.e-volution.ai/?c=o&m=multi'; |
| 7 | +const URL_SYNC = 'https://service.e-volution.ai/?c=o&m=sync'; |
| 8 | +const NO_SYNC = true; |
| 9 | + |
| 10 | +function isBidResponseValid(bid) { |
| 11 | + if (!bid.requestId || !bid.cpm || !bid.creativeId || |
| 12 | + !bid.ttl || !bid.currency) { |
| 13 | + return false; |
| 14 | + } |
| 15 | + switch (bid.mediaType) { |
| 16 | + case BANNER: |
| 17 | + return Boolean(bid.width && bid.height && bid.ad); |
| 18 | + case VIDEO: |
| 19 | + return Boolean(bid.vastUrl); |
| 20 | + case NATIVE: |
| 21 | + return Boolean(bid.native && bid.native.title && bid.native.image && bid.native.impressionTrackers); |
| 22 | + default: |
| 23 | + return false; |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +export const spec = { |
| 28 | + code: BIDDER_CODE, |
| 29 | + supportedMediaTypes: [BANNER, VIDEO, NATIVE], |
| 30 | + noSync: NO_SYNC, |
| 31 | + |
| 32 | + isBidRequestValid: (bid) => { |
| 33 | + return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.placementId))); |
| 34 | + }, |
| 35 | + |
| 36 | + buildRequests: (validBidRequests = [], bidderRequest) => { |
| 37 | + let winTop = window; |
| 38 | + let location; |
| 39 | + try { |
| 40 | + location = new URL(bidderRequest.refererInfo.referer) |
| 41 | + winTop = window.top; |
| 42 | + } catch (e) { |
| 43 | + location = winTop.location; |
| 44 | + utils.logMessage(e); |
| 45 | + }; |
| 46 | + let placements = []; |
| 47 | + let request = { |
| 48 | + 'deviceWidth': winTop.screen.width, |
| 49 | + 'deviceHeight': winTop.screen.height, |
| 50 | + 'language': (navigator && navigator.language) ? navigator.language.split('-')[0] : '', |
| 51 | + 'secure': 1, |
| 52 | + 'host': location.host, |
| 53 | + 'page': location.pathname, |
| 54 | + 'placements': placements |
| 55 | + }; |
| 56 | + if (bidderRequest) { |
| 57 | + if (bidderRequest.uspConsent) { |
| 58 | + request.ccpa = bidderRequest.uspConsent; |
| 59 | + } |
| 60 | + if (bidderRequest.gdprConsent) { |
| 61 | + request.gdpr = bidderRequest.gdprConsent |
| 62 | + } |
| 63 | + } |
| 64 | + const len = validBidRequests.length; |
| 65 | + |
| 66 | + for (let i = 0; i < len; i++) { |
| 67 | + let bid = validBidRequests[i]; |
| 68 | + let traff = bid.params.traffic || BANNER |
| 69 | + |
| 70 | + placements.push({ |
| 71 | + placementId: bid.params.placementId, |
| 72 | + bidId: bid.bidId, |
| 73 | + sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [], |
| 74 | + traffic: traff |
| 75 | + }); |
| 76 | + if (bid.schain) { |
| 77 | + placements.schain = bid.schain; |
| 78 | + } |
| 79 | + } |
| 80 | + return { |
| 81 | + method: 'POST', |
| 82 | + url: AD_URL, |
| 83 | + data: request |
| 84 | + }; |
| 85 | + }, |
| 86 | + |
| 87 | + interpretResponse: (serverResponse) => { |
| 88 | + let response = []; |
| 89 | + for (let i = 0; i < serverResponse.body.length; i++) { |
| 90 | + let resItem = serverResponse.body[i]; |
| 91 | + if (isBidResponseValid(resItem)) { |
| 92 | + response.push(resItem); |
| 93 | + } |
| 94 | + } |
| 95 | + return response; |
| 96 | + }, |
| 97 | + |
| 98 | + getUserSyncs: (syncOptions, serverResponses) => { |
| 99 | + if (NO_SYNC) { |
| 100 | + return false |
| 101 | + } else { |
| 102 | + return [{ |
| 103 | + type: 'image', |
| 104 | + url: URL_SYNC |
| 105 | + }]; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | +}; |
| 110 | + |
| 111 | +registerBidder(spec); |
0 commit comments