forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathablidaBidAdapter.js
115 lines (105 loc) · 3.83 KB
/
ablidaBidAdapter.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
import {triggerPixel} 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';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
*/
const BIDDER_CODE = 'ablida';
const ENDPOINT_URL = 'https://bidder.ablida.net/prebid';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.placementId);
},
/**
* Make a server request from the list of BidRequests.
*
* @return Array Info describing the request to the server.
* @param validBidRequests
* @param bidderRequest
*/
buildRequests: function (validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
if (validBidRequests.length === 0) {
return [];
}
return validBidRequests.map(bidRequest => {
let sizes = []
if (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER] && bidRequest.mediaTypes[BANNER].sizes) {
sizes = bidRequest.mediaTypes[BANNER].sizes;
} else if (bidRequest.mediaTypes[VIDEO] && bidRequest.mediaTypes[VIDEO].playerSize) {
sizes = bidRequest.mediaTypes[VIDEO].playerSize
}
const jaySupported = 'atob' in window && 'currentScript' in document;
const device = getDevice();
const payload = {
placementId: bidRequest.params.placementId,
sizes: sizes,
bidId: bidRequest.bidId,
categories: bidRequest.params.categories,
// TODO: should referer be 'ref'?
referer: bidderRequest.refererInfo.page,
jaySupported: jaySupported,
device: device,
adapterVersion: 5,
mediaTypes: bidRequest.mediaTypes,
gdprConsent: bidderRequest.gdprConsent
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: payload
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
response.forEach(function(bid) {
bid.ttl = 60
bidResponses.push(bid);
});
return bidResponses;
},
onBidWon: function (bid) {
if (!bid['nurl']) { return; }
triggerPixel(bid['nurl']);
}
};
function getDevice() {
const ua = navigator.userAgent;
const topWindow = window.top;
if ((/(ipad|xoom|sch-i800|playbook|silk|tablet|kindle)|(android(?!.*mobi))/i).test(ua)) {
return 'tablet';
}
if ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(ua)) {
return 'connectedtv';
}
if ((/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Windows\sCE|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i).test(ua)) {
return 'smartphone';
}
const width = topWindow.innerWidth || topWindow.document.documentElement.clientWidth || topWindow.document.body.clientWidth;
if (width > 320) {
return 'desktop';
}
return 'other';
}
registerBidder(spec);