forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadspiritBidAdapter.js
124 lines (106 loc) · 3.69 KB
/
adspiritBidAdapter.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
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
const RTB_URL = '/rtb/getbid.php?rtbprovider=prebid';
const SCRIPT_URL = '/adasync.min.js';
export const spec = {
code: 'adspirit',
aliases: ['twiago'],
supportedMediaTypes: [BANNER, NATIVE],
isBidRequestValid: function (bid) {
let host = spec.getBidderHost(bid);
if (!host || !bid.params.placementId) {
return false;
}
return true;
},
buildRequests: function (validBidRequests, bidderRequest) {
let requests = [];
for (let i = 0; i < validBidRequests.length; i++) {
let bidRequest = validBidRequests[i];
bidRequest.adspiritConId = spec.genAdConId(bidRequest);
let reqUrl = spec.getBidderHost(bidRequest);
let placementId = utils.getBidIdParameter('placementId', bidRequest.params);
reqUrl = '//' + reqUrl + RTB_URL + '&pid=' + placementId +
'&ref=' + encodeURIComponent(bidderRequest.refererInfo.topmostLocation) +
'&scx=' + (screen.width) +
'&scy=' + (screen.height) +
'&wcx=' + (window.innerWidth || document.documentElement.clientWidth) +
'&wcy=' + (window.innerHeight || document.documentElement.clientHeight) +
'&async=' + bidRequest.adspiritConId +
'&t=' + Math.round(Math.random() * 100000);
let data = {};
if (bidderRequest && bidderRequest.gdprConsent) {
const gdprConsentString = bidderRequest.gdprConsent.consentString;
reqUrl += '&gdpr=' + encodeURIComponent(gdprConsentString);
}
if (bidRequest.schain && bidderRequest.schain) {
data.schain = bidRequest.schain;
}
requests.push({
method: 'GET',
url: reqUrl,
data: data,
bidRequest: bidRequest
});
}
return requests;
},
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
let bidObj = bidRequest.bidRequest;
if (!serverResponse || !serverResponse.body || !bidObj) {
utils.logWarn(`No valid bids from ${spec.code} bidder!`);
return [];
}
let adData = serverResponse.body;
let cpm = adData.cpm;
if (!cpm) {
return [];
}
let host = spec.getBidderHost(bidObj);
const bidResponse = {
requestId: bidObj.bidId,
cpm: cpm,
width: adData.w,
height: adData.h,
creativeId: bidObj.params.placementId,
currency: 'EUR',
netRevenue: true,
ttl: 300,
meta: {
advertiserDomains: bidObj && bidObj.adomain ? bidObj.adomain : []
}
};
if ('mediaTypes' in bidObj && 'native' in bidObj.mediaTypes) {
bidResponse.native = {
title: adData.title,
body: adData.body,
cta: adData.cta,
image: { url: adData.image },
clickUrl: adData.click,
impressionTrackers: [adData.view]
};
bidResponse.mediaType = NATIVE;
} else {
let adm = '<script>window.inDapIF=false</script><script src="//' + host + SCRIPT_URL + '"></script><ins id="' + bidObj.adspiritConId + '"></ins>' + adData.adm;
bidResponse.ad = adm;
bidResponse.mediaType = BANNER;
}
bidResponses.push(bidResponse);
return bidResponses;
},
getBidderHost: function (bid) {
if (bid.bidder === 'adspirit') {
return utils.getBidIdParameter('host', bid.params);
}
if (bid.bidder === 'twiago') {
return 'a.twiago.com';
}
return null;
},
genAdConId: function (bid) {
return bid.bidder + Math.round(Math.random() * 100000);
}
};
registerBidder(spec);