forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbidscubeBidAdapter.js
94 lines (79 loc) · 2.54 KB
/
bidscubeBidAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { logMessage, getWindowLocation } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
const BIDDER_CODE = 'bidscube'
const URL = 'https://supply.bidscube.com/?c=o&m=multi'
const URL_SYNC = 'https://supply.bidscube.com/?c=o&m=cookie'
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: function (opts) {
return Boolean(opts.bidId && opts.params && !isNaN(parseInt(opts.params.placementId)))
},
buildRequests: function (validBidRequests) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
validBidRequests = validBidRequests || []
let winTop = window
try {
window.top.location.toString()
winTop = window.top
} catch (e) { logMessage(e) }
const location = getWindowLocation()
const placements = []
for (let i = 0; i < validBidRequests.length; i++) {
const p = validBidRequests[i]
placements.push({
placementId: p.params.placementId,
bidId: p.bidId,
traffic: p.params.traffic || BANNER,
allParams: JSON.stringify(p)
})
}
return {
method: 'POST',
url: URL,
data: {
deviceWidth: winTop.screen.width,
deviceHeight: winTop.screen.height,
language: (navigator && navigator.language) ? navigator.language : '',
secure: +(location.protocol === 'https:'),
host: location.hostname,
page: location.pathname,
placements: placements
}
}
},
interpretResponse: function (opts) {
const body = opts.body
const response = []
for (let i = 0; i < body.length; i++) {
const item = body[i]
if (isBidResponseValid(item)) {
response.push(item)
}
}
return response
},
getUserSyncs: function (syncOptions, serverResponses) {
return [{ type: 'image', url: URL_SYNC }]
}
}
registerBidder(spec)
function isBidResponseValid (bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
!bid.ttl || !bid.currency) {
return false
}
switch (bid['mediaType']) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad)
case VIDEO:
return Boolean(bid.vastUrl)
case NATIVE:
return Boolean(bid.title && bid.image && bid.impressionTrackers)
default:
return false
}
}