forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartyadsBidAdapter.js
82 lines (68 loc) · 2.49 KB
/
smartyadsBidAdapter.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
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { getAdUrlByRegion } from '../libraries/smartyadsUtils/getAdUrlByRegion.js';
import { interpretResponse, getUserSyncs } from '../libraries/teqblazeUtils/bidderUtils.js';
const BIDDER_CODE = 'smartyads';
const GVLID = 534;
const URL_SYNC = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a';
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.sourceid) && !isNaN(bid.params.accountid) && bid.params.host == 'prebid');
},
buildRequests: (validBidRequests = [], bidderRequest) => {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);
let winTop = window;
let location;
location = bidderRequest?.refererInfo ?? null;
let placements = [];
let request = {
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'host': location?.domain ?? '',
'page': location?.page ?? '',
'coppa': config.getConfig('coppa') === true ? 1 : 0,
'placements': placements,
'eeid': validBidRequests[0]?.userIdAsEids,
'ifa': bidderRequest?.ortb2?.device?.ifa,
};
if (bidderRequest) {
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
if (bidderRequest.gppConsent) {
request.gpp = bidderRequest.gppConsent;
}
}
const len = validBidRequests.length;
let adUrl;
for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
if (i === 0) adUrl = getAdUrlByRegion(bid);
let traff = bid.params.traffic || BANNER;
placements.push({
placementId: bid.params.sourceid,
bidId: bid.bidId,
sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [],
traffic: traff,
publisherId: bid.params.accountid
});
if (bid.schain) {
placements.schain = bid.schain;
}
}
return {
method: 'POST',
url: adUrl,
data: request
}
},
interpretResponse,
getUserSyncs: getUserSyncs(URL_SYNC),
};
registerBidder(spec);