forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheightPodBidAdapter.js
249 lines (217 loc) · 7.07 KB
/
eightPodBidAdapter.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import { ortbConverter } from '../libraries/ortbConverter/converter.js'
import { registerBidder } from '../src/adapters/bidderFactory.js'
import { BANNER } from '../src/mediaTypes.js'
import * as utils from '../src/utils.js'
export const BIDDER_CODE = 'eightPod'
const url = 'https://demo.8pod.com/bidder/rtb/eightpod_exchange/bid';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid,
buildRequests,
interpretResponse,
isBannerBid,
isVideoBid,
onBidWon
}
registerBidder(spec)
const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 300,
},
request(buildRequest, imps, bidderRequest, context) {
const req = buildRequest(imps, bidderRequest, context)
return req
},
response(buildResponse, bidResponses, ortbResponse, context) {
const response = buildResponse(bidResponses, ortbResponse, context)
return response.bids
},
imp(buildImp, bidRequest, context) {
return buildImp(bidRequest, context)
},
bidResponse
})
function hasRequiredParams(bidRequest) {
return !!bidRequest?.params?.placementId
}
function isBidRequestValid(bidRequest) {
return hasRequiredParams(bidRequest)
}
function buildRequests(bids, bidderRequest) {
let bannerBids = bids.filter((bid) => isBannerBid(bid))
let requests = bannerBids.length
? createRequest(bannerBids, bidderRequest, BANNER)
: []
return requests
}
function bidResponse(buildBidResponse, bid, context) {
bid.nurl = replacePriceInUrl(bid.nurl, bid.price);
const bidResponse = buildBidResponse(bid, context);
bidResponse.height = context?.imp?.banner?.format?.[0].h;
bidResponse.width = context?.imp?.banner?.format?.[0].w;
bidResponse.cid = bid.cid;
bidResponse.burl = replacePriceInUrl(bid.burl, bidResponse.originalCpm || bidResponse.cpm);
return bidResponse;
}
function onBidWon(bid) {
if (bid.burl) {
utils.triggerPixel(bid.burl)
}
}
function replacePriceInUrl(url, price) {
return url.replace(/\${AUCTION_PRICE}/, price)
}
export function parseUserAgent() {
const ua = navigator.userAgent.toLowerCase();
// Check if it's iOS
if (/iphone|ipad|ipod/.test(ua)) {
// Extract iOS version and device type
const iosInfo = /(iphone|ipad|ipod) os (\d+[._]\d+)|((iphone|ipad|ipod)(\D+cpu) os (\d+(?:[._\s]\d+)?))/.exec(ua);
return {
platform: 'ios',
version: iosInfo ? iosInfo[1] : '',
device: iosInfo ? iosInfo[2].replace('_', '.') : ''
};
} else if (/android/.test(ua)) {
// Check if it's Android
// Extract Android version
const androidVersion = /android (\d+([._]\d+)?)/.exec(ua);
return {
platform: 'android',
version: androidVersion ? androidVersion[1].replace('_', '.') : '',
device: ''
};
} else {
// If neither iOS nor Android, return unknown
return {
platform: 'Unknown',
version: '',
device: ''
};
}
}
export function getPageKeywords(win = window) {
let element;
try {
element = win.top.document.querySelector('meta[name="keywords"]');
} catch (e) {
element = document.querySelector('meta[name="keywords"]');
}
return ((element && element.content) || '').replaceAll(' ', '');
}
function createRequest(bidRequests, bidderRequest, mediaType) {
const requests = bidRequests.map((bidRequest) => {
const data = converter.toORTB({
bidRequests: [bidRequest],
bidderRequest,
context: { mediaType },
});
data.adSlotPositionOnScreen = 'ABOVE_THE_FOLD';
data.at = 1;
const userId =
utils.deepAccess(bidRequest, 'userId.unifiedId.id') ||
utils.deepAccess(bidRequest, 'userId.id5id.uid') ||
utils.deepAccess(bidRequest, 'userId.idl_env');
const params = getBidderParams(bidRequest);
data.device = {
...data.device,
devicetype: 4,
geo: {
country: params.country || 'GRB'
},
language: params.language || data.device.language,
}
data.site = {
...data.site,
keywords: getPageKeywords(window),
publisher: {
id: params.publisherId
}
}
data.imp = [
{
...data.imp?.[0],
secure: 1,
pmp: params.dealId
? {
...data.pmp,
deals: [
{
id: params.dealId,
},
],
private_auction: 1,
}
: data.pmp,
}
]
data.adSlotPlacementId = params.placementId;
if (userId) {
data.user = {
id: userId
}
}
const req = {
method: 'POST',
url: url && params.trace ? url + '?trace=true' : url,
options: { withCredentials: false },
data
}
return req
})
return requests;
}
function getBidderParams(bid) {
return bid?.params ? bid.params : undefined;
}
function isVideoBid(bid) {
return utils.deepAccess(bid, 'mediaTypes.video')
}
function isBannerBid(bid) {
return utils.deepAccess(bid, 'mediaTypes.banner')
}
function interpretResponse(resp, req) {
const impressionId = resp.body.seatbid[0].bid[0].impid;
const bidResponses = converter.fromORTB({ request: req.data, response: resp.body });
const ad = bidResponses[0].ad;
const trackingTag = `<script src="https://cdn.doubleverify.com/dvtp_src.js?ctx=818052&cmp=APAC_Cert_20&sid=se_a551&plc=240411845&adsrv=0&btreg=ad-unit-container&auevent=${impressionId}&btadsrv=&crt=01&tagtype=&dvtagver=6.1.src" type="text/javascript"></script>
<script type="text/javascript">
(function() {
/** CONFIGURATION START **/
var _sf_async_config = window._sf_async_config = (window._sf_async_config || {});
_sf_async_config.uid = 67171;
_sf_async_config.domain = 'demo.8pod.com';
_sf_async_config.flickerControl = false;
_sf_async_config.useCanonical = true;
_sf_async_config.useCanonicalDomain = true;
_sf_async_config.sections = '';
_sf_async_config.authors = '';
/** CONFIGURATION END **/
function loadChartbeat() {
var e = document.createElement('script');
var n = document.getElementsByTagName('script')[0];
e.type = 'text/javascript';
e.async = true;
e.src = '//static.chartbeat.com/js/chartbeat.js';
n.parentNode.insertBefore(e, n);
}
loadChartbeat();
})();
</script>
<script async src="//static.chartbeat.com/js/chartbeat_mab.js"></script>
<script type="text/javascript">
var utag_data = {
}
</script>
<script type="text/javascript">
(function(a,b,c,d){
a='https://tags.tiqcdn.com/utag/sales-richard-coghlan/8pod/prod/utag.js';
b=document;c='script';d=b.createElement(c);d.src=a;d.type='text/java'+c;d.async=true;
a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a);
})();
</script>`
bidResponses[0].ad = ad.replace('</head>', trackingTag + '</head>');
return bidResponses;
}