forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecisoBidAdapter.js
66 lines (57 loc) · 2.34 KB
/
precisoBidAdapter.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
import { logInfo } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
import { buildBidResponse, buildRequests, onBidWon } from '../libraries/precisoUtils/bidUtils.js';
import { buildUserSyncs } from '../libraries/precisoUtils/bidUtilsCommon.js';
const BIDDER__CODE = 'preciso';
export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: BIDDER__CODE });
const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE];
const GVLID = 874;
let precisoId = 'NA';
let sharedId = 'NA';
const endpoint = 'https://ssp-bidder.mndtrk.com/bid_request/openrtb';
let syncEndpoint = 'https://ck.2trk.info/rtb/user/usersync.aspx?';
export const spec = {
code: BIDDER__CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
gvlid: GVLID,
isBidRequestValid: (bid) => {
sharedId = storage.getDataFromLocalStorage('_sharedid') || storage.getCookie('_sharedid');
let precisoBid = true;
const preCall = 'https://ssp-usersync.mndtrk.com/getUUID?sharedId=' + sharedId;
precisoId = storage.getDataFromLocalStorage('_pre|id');
if (Object.is(precisoId, 'NA') || Object.is(precisoId, null) || Object.is(precisoId, undefined)) {
if (!bid.precisoBid) {
precisoBid = false;
getapi(preCall);
}
}
return Boolean(bid.bidId && bid.params && bid.params.publisherId && precisoBid);
},
buildRequests: buildRequests(endpoint),
interpretResponse: buildBidResponse,
onBidWon,
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
syncEndpoint = syncEndpoint + 'id=' + sharedId;
return buildUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, syncEndpoint);
}
};
registerBidder(spec);
async function getapi(url) {
try {
const response = await fetch(url);
var data = await response.json();
const dataMap = new Map(Object.entries(data));
const uuidValue = dataMap.get('UUID');
if (!Object.is(uuidValue, null) && !Object.is(uuidValue, undefined)) {
if (storage.localStorageIsEnabled()) {
storage.setDataInLocalStorage('_pre|id', uuidValue);
}
}
return data;
} catch (error) {
logInfo('Error in preciso precall' + error);
}
}