|
| 1 | +import { registerBidder } from '../src/adapters/bidderFactory.js'; |
| 2 | +import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js'; |
| 3 | +import { logError } from '../src/utils.js'; |
| 4 | +import { ortbConverter } from '../libraries/ortbConverter/converter.js' |
| 5 | +import { ortb25Translator } from '../libraries/ortb2.5Translator/translator.js'; |
| 6 | + |
| 7 | +const BIDDER_CODE = 'startio'; |
| 8 | +const METHOD = 'POST'; |
| 9 | +const GVLID = 1216; |
| 10 | +const ENDPOINT_URL = `http://pbc-rtb.startappnetwork.com/1.3/2.5/getbid?account=pbc`; |
| 11 | + |
| 12 | +const converter = ortbConverter({ |
| 13 | + imp(buildImp, bidRequest, context) { |
| 14 | + const imp = buildImp(bidRequest, context); |
| 15 | + |
| 16 | + if (imp?.banner?.format?.[0]) { |
| 17 | + imp.banner.w ??= imp.banner.format[0]?.w; |
| 18 | + imp.banner.h ??= imp.banner.format[0]?.h; |
| 19 | + } |
| 20 | + |
| 21 | + return imp; |
| 22 | + }, |
| 23 | + request(buildRequest, imps, bidderRequest, context) { |
| 24 | + const request = buildRequest(imps, bidderRequest, context); |
| 25 | + const publisherId = bidderRequest?.bids?.[0]?.params?.publisherId; |
| 26 | + if (request?.site) { |
| 27 | + request.site.publisher = request.site.publisher || {}; |
| 28 | + request.site.publisher.id = publisherId; |
| 29 | + } else if (request?.app) { |
| 30 | + request.app.publisher = request.app.publisher || {}; |
| 31 | + request.app.publisher.id = publisherId; |
| 32 | + } |
| 33 | + request.ext = request.ext || {}; |
| 34 | + request.ext.prebid = request.ext.prebid || {}; |
| 35 | + |
| 36 | + return request; |
| 37 | + }, |
| 38 | + bidResponse(buildBidResponse, bid, context) { |
| 39 | + const isValidBidType = bid?.ext?.prebid?.type === context?.mediaType; |
| 40 | + |
| 41 | + if (context.mediaType === NATIVE) { |
| 42 | + const ortb = JSON.parse(bid.adm); |
| 43 | + bid.adm = ortb.native; |
| 44 | + } |
| 45 | + |
| 46 | + if (isValidBidType) { |
| 47 | + return buildBidResponse(bid, context); |
| 48 | + } |
| 49 | + |
| 50 | + logError('Bid type is incorrect for bid: ', bid['id']) |
| 51 | + }, |
| 52 | + context: { |
| 53 | + netRevenue: true, |
| 54 | + ttl: 30 |
| 55 | + }, |
| 56 | + translator: ortb25Translator() |
| 57 | +}); |
| 58 | + |
| 59 | +export const spec = { |
| 60 | + code: BIDDER_CODE, |
| 61 | + supportedMediaTypes: [VIDEO, BANNER, NATIVE], |
| 62 | + gvlid: GVLID, |
| 63 | + isBidRequestValid: (bid) => !!bid, |
| 64 | + |
| 65 | + buildRequests: (bidRequests, bidderRequest) => { |
| 66 | + return bidRequests.map((bidRequest) => { |
| 67 | + const mediaType = Object.keys(bidRequest.mediaTypes || {})[0] || BANNER; |
| 68 | + const data = converter.toORTB({ bidRequests: [bidRequest], bidderRequest, context: { mediaType } }); |
| 69 | + |
| 70 | + return { |
| 71 | + method: METHOD, |
| 72 | + url: ENDPOINT_URL, |
| 73 | + options: { |
| 74 | + contentType: 'text/plain', |
| 75 | + withCredentials: false, |
| 76 | + crossOrigin: true |
| 77 | + }, |
| 78 | + data: data, |
| 79 | + }; |
| 80 | + }); |
| 81 | + }, |
| 82 | + |
| 83 | + interpretResponse: ({ body }, req) => { |
| 84 | + if (!body || !body.seatbid || body.seatbid.length === 0) { |
| 85 | + return []; |
| 86 | + } |
| 87 | + return converter.fromORTB({ |
| 88 | + response: body, |
| 89 | + request: req.data |
| 90 | + }); |
| 91 | + }, |
| 92 | + |
| 93 | + onTimeout: (data) => { }, |
| 94 | + |
| 95 | + onBidWon: (bid) => { |
| 96 | + if (bid.nurl) { |
| 97 | + const url = new URL(bid.nurl); |
| 98 | + url.searchParams.set('cpm', bid.cpm); |
| 99 | + fetch(url.toString(), { method: 'GET', keepalive: true }).catch(err => |
| 100 | + logError('Error triggering win notification', err) |
| 101 | + ); |
| 102 | + } |
| 103 | + }, |
| 104 | + |
| 105 | + onSetTargeting: (bid) => { }, |
| 106 | +}; |
| 107 | + |
| 108 | +registerBidder(spec); |
0 commit comments