forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasealBidAdapter.js
107 lines (90 loc) · 2.73 KB
/
asealBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { generateUUID, getWindowTop, getWindowSelf } from '../src/utils.js';
import { getStorageManager } from '../src/storageManager.js';
export const BIDDER_CODE = 'aseal';
export const SUPPORTED_AD_TYPES = [BANNER];
export const API_ENDPOINT = 'https://tkprebid.aotter.net/prebid/adapter';
export const WEB_SESSION_ID_KEY = '__tkwsid';
export const HEADER_AOTTER_VERSION = 'prebid_0.0.2';
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
const getTrekWebSessionId = () => {
let wsid =
storage.localStorageIsEnabled() &&
storage.getDataFromLocalStorage(WEB_SESSION_ID_KEY);
if (!wsid) {
wsid = generateUUID();
setTrekWebSessionId(wsid);
}
return wsid;
};
const setTrekWebSessionId = (wsid) => {
if (storage.localStorageIsEnabled()) {
storage.setDataInLocalStorage(WEB_SESSION_ID_KEY, wsid);
}
};
const canAccessTopWindow = () => {
try {
return !!getWindowTop().location.href;
} catch (errro) {
return false;
}
};
export const spec = {
code: BIDDER_CODE,
aliases: ['aotter', 'trek'],
supportedMediaTypes: SUPPORTED_AD_TYPES,
isBidRequestValid: (bid) =>
!!bid.params.placeUid && typeof bid.params.placeUid === 'string',
buildRequests: (validBidRequests, bidderRequest) => {
if (validBidRequests.length === 0) {
return [];
}
const clientId = config.getConfig('aseal.clientId') || '';
const windowTop = getWindowTop();
const windowSelf = getWindowSelf();
const w = canAccessTopWindow() ? windowTop : windowSelf;
const data = {
bids: validBidRequests,
// TODO: please do not pass internal data structures over to the network
refererInfo: bidderRequest.refererInfo?.legacy,
device: {
webSessionId: getTrekWebSessionId(),
},
payload: {
meta: {
dr: w.document.referrer,
drs: windowSelf.document.referrer,
drt: (canAccessTopWindow() && windowTop.document.referrer) || '',
dt: w.document.title,
dl: w.location.href,
},
},
};
const options = {
contentType: 'application/json',
withCredentials: true,
customHeaders: {
'x-aotter-clientid': clientId,
'x-aotter-version': HEADER_AOTTER_VERSION,
},
};
return [
{
method: 'POST',
url: API_ENDPOINT,
data,
options,
},
];
},
interpretResponse: (serverResponse, bidRequest) => {
if (!Array.isArray(serverResponse.body)) {
return [];
}
const bidResponses = serverResponse.body;
return bidResponses;
},
};
registerBidder(spec);