forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocereeBidAdapter.js
104 lines (99 loc) · 3.73 KB
/
docereeBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { triggerPixel } from '../src/utils.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.js';
const BIDDER_CODE = 'doceree';
const END_POINT = 'https://bidder.doceree.com'
const TRACKING_END_POINT = 'https://tracking.doceree.com'
export const spec = {
code: BIDDER_CODE,
url: '',
supportedMediaTypes: [ BANNER ],
isBidRequestValid: (bid) => {
const { placementId } = bid.params;
return !!placementId
},
isGdprConsentPresent: (bid) => {
const { gdpr, gdprConsent } = bid.params;
if (gdpr == '1') {
return !!gdprConsent
}
return true
},
buildRequests: (validBidRequests) => {
const serverRequests = [];
const { data } = config.getConfig('doceree.user')
// TODO: this should probably look at refererInfo
const { page, domain, token } = config.getConfig('doceree.context')
const encodedUserInfo = window.btoa(encodeURIComponent(JSON.stringify(data)))
validBidRequests.forEach(function(validBidRequest) {
const { publisherUrl, placementId, gdpr, gdprConsent } = validBidRequest.params;
const url = publisherUrl || page
let queryString = '';
queryString = tryAppendQueryString(queryString, 'id', placementId);
queryString = tryAppendQueryString(queryString, 'publisherDomain', domain);
queryString = tryAppendQueryString(queryString, 'pubRequestedURL', encodeURIComponent(url));
queryString = tryAppendQueryString(queryString, 'loggedInUser', encodedUserInfo);
queryString = tryAppendQueryString(queryString, 'currentUrl', url);
queryString = tryAppendQueryString(queryString, 'prebidjs', true);
queryString = tryAppendQueryString(queryString, 'token', token);
queryString = tryAppendQueryString(queryString, 'requestId', validBidRequest.bidId);
queryString = tryAppendQueryString(queryString, 'gdpr', gdpr);
queryString = tryAppendQueryString(queryString, 'gdpr_consent', gdprConsent);
serverRequests.push({
method: 'GET',
url: END_POINT + '/v1/adrequest?' + queryString
})
})
return serverRequests;
},
interpretResponse: (serverResponse, request) => {
const responseJson = serverResponse ? serverResponse.body : {};
const placementId = responseJson.DIVID;
const bidResponse = {
ad: responseJson.sourceHTML,
width: Number(responseJson.width),
height: Number(responseJson.height),
requestId: responseJson.guid,
netRevenue: true,
ttl: 30,
cpm: responseJson.cpmBid,
currency: responseJson.currency,
mediaType: 'banner',
creativeId: placementId,
meta: {
advertiserDomains: [responseJson.advertiserDomain]
}
};
return [bidResponse];
},
onTimeout: function(timeoutData) {
if (timeoutData == null || !timeoutData.length) {
return;
}
timeoutData.forEach(td => {
const encodedBuf = window.btoa(encodeURIComponent(JSON.stringify({
bidId: td.bidId,
timeout: td.timeout,
})));
triggerPixel(TRACKING_END_POINT + '/v1/hbTimeout?adp=prebidjs&data=' + encodedBuf);
})
},
onBidWon: function (bidWon) {
if (bidWon == null) {
return;
}
const encodedBuf = window.btoa(encodeURIComponent(JSON.stringify({
requestId: bidWon.requestId,
cpm: bidWon.cpm,
adId: bidWon.adId,
currency: bidWon.currency,
netRevenue: bidWon.netRevenue,
status: bidWon.status,
hb_pb: bidWon.adserverTargeting && bidWon.adserverTargeting.hb_pb,
})));
triggerPixel(TRACKING_END_POINT + '/v1/hbBidWon?adp=prebidjs&data=' + encodedBuf);
}
};
registerBidder(spec);