forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
temedyaBidAdapter.js
156 lines (152 loc) · 5.98 KB
/
temedyaBidAdapter.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
import { parseSizesInput, parseQueryStringParameters, logError } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } 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
* @typedef {import('../src/adapters/bidderFactory.js').ServerRequest} ServerRequest
* @typedef {import('../src/adapters/bidderFactory.js').validBidRequests} validBidRequests
*/
const BIDDER_CODE = 'temedya';
const ENDPOINT_URL = 'https://adm.vidyome.com/';
const ENDPOINT_METHOD = 'GET';
const CURRENCY = 'TRY';
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, 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) {
return !!(bid.params.widgetId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
return validBidRequests.map(req => {
const mediaType = this._isBannerRequest(req) ? 'display' : NATIVE;
const data = {
wid: req.params.widgetId,
type: mediaType,
count: (req.params.count > 6 ? 6 : req.params.count) || 1,
mediaType: mediaType,
requestid: req.bidId
};
if (mediaType === 'display') {
data.sizes = parseSizesInput(
req.mediaTypes && req.mediaTypes.banner && req.mediaTypes.banner.sizes
).join('|')
}
/** @type {ServerRequest} */
return {
method: ENDPOINT_METHOD,
url: ENDPOINT_URL,
data: parseQueryStringParameters(data),
options: { withCredentials: false, requestId: req.bidId, mediaType: mediaType }
};
});
},
/**
* 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 (serverResponse, bidRequest) {
try {
const bidResponse = serverResponse.body;
const bidResponses = [];
if (bidResponse && bidRequest.options.mediaType == NATIVE) {
bidResponse.ads.forEach(function(ad) {
bidResponses.push({
requestId: bidRequest.options.requestId,
cpm: parseFloat(ad.assets.cpm) || 1,
width: 320,
height: 240,
creativeId: ad.assets.id,
currency: ad.currency || CURRENCY,
netRevenue: false,
mediaType: NATIVE,
ttl: 360,
native: {
title: ad.assets.title,
body: ad.assets.body || '',
icon: {
url: ad.assets.files[0],
width: 320,
height: 240
},
image: {
url: ad.assets.files[0],
width: 320,
height: 240
},
privacyLink: '',
clickUrl: ad.assets.click_url,
displayUrl: ad.assets.click_url,
cta: '',
sponsoredBy: ad.assets.sponsor || '',
impressionTrackers: [bidResponse.base.widget.impression + '&ids=' + ad.id + ':' + ad.assets.id],
},
});
});
} else if (bidResponse && bidRequest.options.mediaType == 'display') {
bidResponse.ads.forEach(function(ad) {
let w = ad.assets.width || 300;
let h = ad.assets.height || 250;
let htmlTag = '<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" href="https://widget.cdn.vidyome.com/builds/neytivme.css"></head>';
htmlTag += '<body><div id="tem_banner" class="size' + w + '-' + h + '" style="width:' + w + 'px;height:' + h + 'px">';
htmlTag += '<i onclick="window.open(\'https://www.temedya.com\', \'_blank\')">TE Medya</i>';
htmlTag += '<a href="' + ad.assets.click_url + '" target="_blank">';
htmlTag += '<div class="image-with-text">';
htmlTag += '<div class="tem-img"><img src="' + ad.assets.files[0] + '" style="width:' + w + 'px;height:' + h + 'px;"/></div>';
if (ad.assets.title) {
htmlTag += '<div class="text-elements">';
htmlTag += '<h2>' + ad.assets.title + '</h2>';
htmlTag += '<p>' + (ad.assets.sponsor || '') + '</p>';
htmlTag += '<em><canvas height="100" width="100"></canvas></em>';
htmlTag += '</div>';
};
htmlTag += '</div></a><img style="display: none;" src="' + bidResponse.base.widget.impression + '&ids=' + ad.id + ':' + ad.assets.id + '">';
htmlTag += '</div></body></html>';
bidResponses.push({
requestId: bidRequest.options.requestId,
cpm: parseFloat(ad.assets.cpm) || 1,
width: w,
height: h,
creativeId: ad.assets.id,
currency: ad.currency || CURRENCY,
netRevenue: false,
ttl: 360,
mediaType: BANNER,
ad: htmlTag
});
});
}
return bidResponses;
} catch (err) {
logError(err);
return [];
}
},
/**
* @param {BidRequest} req
* @return {boolean}
* @private
*/
_isBannerRequest(req) {
return !!(req.mediaTypes && req.mediaTypes.banner);
}
}
registerBidder(spec);