|
| 1 | +import {registerBidder} from 'src/adapters/bidderFactory'; |
| 2 | +import {BANNER} from 'src/mediaTypes'; |
| 3 | +import * as utils from '../src/utils'; |
| 4 | +import {config} from 'src/config'; |
| 5 | + |
| 6 | +export const BIDDER_CODE = 'adikteev'; |
| 7 | +export const ENDPOINT_URL = 'https://serve-adserver.adikteev.com/api/prebid/bid'; |
| 8 | +export const ENDPOINT_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/bid'; |
| 9 | +export const USER_SYNC_IFRAME_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-iframe'; |
| 10 | +export const USER_SYNC_IFRAME_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-iframe'; |
| 11 | +export const USER_SYNC_IMAGE_URL = 'https://serve-adserver.adikteev.com/api/prebid/sync-image'; |
| 12 | +export const USER_SYNC_IMAGE_URL_STAGING = 'https://serve-adserver-staging.adikteev.com/api/prebid/sync-image'; |
| 13 | + |
| 14 | +export let stagingEnvironmentSwitch = false; // Don't use it. Allow us to make tests on staging |
| 15 | + |
| 16 | +export function setstagingEnvironmentSwitch(value) { |
| 17 | + stagingEnvironmentSwitch = value; |
| 18 | +} |
| 19 | + |
| 20 | +function validateSizes(sizes) { |
| 21 | + if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') { |
| 22 | + return false; |
| 23 | + } |
| 24 | + return sizes.every(size => utils.isArray(size) && size.length === 2); |
| 25 | +} |
| 26 | + |
| 27 | +export const spec = { |
| 28 | + code: BIDDER_CODE, |
| 29 | + supportedMediaTypes: [BANNER], |
| 30 | + |
| 31 | + isBidRequestValid: (bid) => { |
| 32 | + setstagingEnvironmentSwitch(stagingEnvironmentSwitch || !!bid.params.stagingEnvironment); |
| 33 | + return !!( |
| 34 | + bid && |
| 35 | + bid.params && |
| 36 | + bid.params.bidFloorPrice && |
| 37 | + bid.params.placementId && |
| 38 | + bid.bidder === BIDDER_CODE && |
| 39 | + validateSizes(bid.mediaTypes.banner.sizes) |
| 40 | + ); |
| 41 | + }, |
| 42 | + |
| 43 | + buildRequests: (validBidRequests, bidderRequest) => { |
| 44 | + const payload = { |
| 45 | + validBidRequests, |
| 46 | + bidderRequest, |
| 47 | + refererInfo: bidderRequest.refererInfo, |
| 48 | + currency: config.getConfig('currency'), |
| 49 | + userAgent: navigator.userAgent, |
| 50 | + screen: { |
| 51 | + width: window.screen.width, |
| 52 | + height: window.screen.height |
| 53 | + }, |
| 54 | + language: navigator.language, |
| 55 | + cookies: document.cookie.split(';'), |
| 56 | + prebidUpdateVersion: '1.29.0', |
| 57 | + }; |
| 58 | + return { |
| 59 | + method: 'POST', |
| 60 | + url: stagingEnvironmentSwitch ? ENDPOINT_URL_STAGING : ENDPOINT_URL, |
| 61 | + data: JSON.stringify(payload), |
| 62 | + }; |
| 63 | + }, |
| 64 | + |
| 65 | + interpretResponse: (serverResponse, bidRequests) => { |
| 66 | + const returnedBids = []; |
| 67 | + const validBidRequests = JSON.parse(bidRequests.data).validBidRequests; |
| 68 | + serverResponse.body.forEach((value, index) => { |
| 69 | + const overrides = { |
| 70 | + requestId: validBidRequests[index].bidId, |
| 71 | + }; |
| 72 | + returnedBids.push(Object.assign({}, value, overrides)); |
| 73 | + }); |
| 74 | + return returnedBids; |
| 75 | + }, |
| 76 | + |
| 77 | + getUserSyncs: (syncOptions, serverResponses) => { |
| 78 | + const syncs = []; |
| 79 | + if (syncOptions.iframeEnabled) { |
| 80 | + syncs.push({ |
| 81 | + type: 'iframe', |
| 82 | + url: stagingEnvironmentSwitch ? USER_SYNC_IFRAME_URL_STAGING : USER_SYNC_IFRAME_URL, |
| 83 | + }); |
| 84 | + } |
| 85 | + if (syncOptions.pixelEnabled && serverResponses.length > 0) { |
| 86 | + syncs.push({ |
| 87 | + type: 'image', |
| 88 | + url: stagingEnvironmentSwitch ? USER_SYNC_IMAGE_URL_STAGING : USER_SYNC_IMAGE_URL, |
| 89 | + }); |
| 90 | + } |
| 91 | + return syncs; |
| 92 | + }, |
| 93 | +}; |
| 94 | +registerBidder(spec); |
0 commit comments