forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchtnwBidAdapter.js
110 lines (107 loc) · 3.33 KB
/
chtnwBidAdapter.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
import {
generateUUID,
getDNT,
_each,
} from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { getStorageManager } from '../src/storageManager.js';
import { ajax } from '../src/ajax.js';
import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js';
const ENDPOINT_URL = 'https://prebid.cht.hinet.net/api/v1';
const BIDDER_CODE = 'chtnw';
const COOKIE_NAME = '__htid';
const storage = getStorageManager({bidderCode: BIDDER_CODE});
const { getConfig } = config;
function _isMobile() {
return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent);
}
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: function(bid = {}) {
return !!(bid && bid.params);
},
buildRequests: function(validBidRequests = [], bidderRequest = {}) {
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
const chtnwId = (storage.getCookie(COOKIE_NAME) != undefined) ? storage.getCookie(COOKIE_NAME) : generateUUID();
if (storage.cookiesAreEnabled()) {
storage.setCookie(COOKIE_NAME, chtnwId);
}
const device = getConfig('device') || {};
device.w = device.w || window.innerWidth;
device.h = device.h || window.innerHeight;
device.ua = device.ua || navigator.userAgent;
device.dnt = getDNT() ? 1 : 0;
device.language = (navigator && navigator.language) ? navigator.language.split('-')[0] : '';
const bidParams = [];
_each(validBidRequests, function(bid) {
bidParams.push({
bidId: bid.bidId,
placement: bid.params.placementId,
sizes: bid.sizes,
adSlot: bid.adUnitCode
});
});
return {
method: 'POST',
url: ENDPOINT_URL + '/request/prebid.json',
data: {
bids: bidParams,
uuid: chtnwId,
device: device,
version: {
prebid: '$prebid.version$',
adapter: '1.0.0',
},
site: {
numIframes: bidderRequest.refererInfo?.numIframes || 0,
isAmp: bidderRequest.refererInfo?.isAmp || false,
pageUrl: bidderRequest.refererInfo?.page || '',
ref: bidderRequest.refererInfo?.ref || '',
},
},
bids: validBidRequests
};
},
interpretResponse: function(serverResponse) {
const bidResponses = []
_each(serverResponse.body, function(response, i) {
bidResponses.push({
...response
});
});
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
if (syncOptions.pixelEnabled) {
const chtnwId = generateUUID()
const uuid = chtnwId
const type = (_isMobile()) ? 'dot' : 'pixel';
syncs.push({
type: 'image',
url: `https://t.ssp.hinet.net/${type}?bd=${uuid}&t=chtnw`
})
}
return syncs
},
onTimeout: function(timeoutData) {
if (timeoutData === null) {
return;
}
ajax(ENDPOINT_URL + '/trace/timeout/bid', null, JSON.stringify(timeoutData), {
method: 'POST',
withCredentials: false
});
},
onBidWon: function(bid) {
if (bid.nurl) {
ajax(bid.nurl, null);
}
},
onSetTargeting: function(bid) {
},
}
registerBidder(spec);