forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuzzoolaBidAdapter.js
117 lines (99 loc) · 3.48 KB
/
buzzoolaBidAdapter.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
import { deepAccess, deepClone } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js';
import {Renderer} from '../src/Renderer.js';
import {OUTSTREAM} from '../src/video.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 = 'buzzoola';
const ENDPOINT = 'https://exchange.buzzoola.com/ssp/prebidjs';
const RENDERER_SRC = 'https://tube.buzzoola.com/new/build/buzzlibrary.js';
export const spec = {
code: BIDDER_CODE,
aliases: ['buzzoolaAdapter'],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
/**
* 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) {
let types = bid.mediaTypes;
return !!(bid && bid.mediaTypes && (types.banner || types.video || types.native) && bid.params && bid.params.placementId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests an array of bids
* @param bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
bidderRequest.bids = convertOrtbRequestToProprietaryNative(bidderRequest.bids);
return {
url: ENDPOINT,
method: 'POST',
data: bidderRequest,
}
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function ({body}, {data}) {
let requestBids = {};
let response;
try {
response = JSON.parse(body);
} catch (ex) {
response = body;
}
if (!Array.isArray(response)) response = [];
data.bids.forEach(bid => requestBids[bid.bidId] = bid);
return response.map(bid => {
let requestBid = requestBids[bid.requestId];
let context = deepAccess(requestBid, 'mediaTypes.video.context');
let validBid = deepClone(bid);
if (validBid.mediaType === VIDEO && context === OUTSTREAM) {
let renderer = Renderer.install({
id: validBid.requestId,
url: RENDERER_SRC,
loaded: false
});
renderer.setRender(setOutstreamRenderer);
validBid.renderer = renderer
}
return validBid;
});
}
};
/**
* Initialize Buzzoola Outstream player
*
* @param bid
*/
function setOutstreamRenderer(bid) {
let adData = JSON.parse(bid.ad);
let unitSettings = deepAccess(adData, 'placement.unit_settings');
let extendedSettings = {
width: '' + bid.width,
height: '' + bid.height,
container_height: '' + bid.height
};
adData.placement = Object.assign({}, adData.placement);
adData.placement.unit_settings = Object.assign({}, unitSettings, extendedSettings);
bid.renderer.push(() => {
window.Buzzoola.Core.install(document.querySelector(`#${bid.adUnitCode}`), {
data: adData
});
});
}
registerBidder(spec);