forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha4gBidAdapter.js
92 lines (80 loc) · 2.63 KB
/
a4gBidAdapter.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
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { _each } from '../src/utils.js';
const A4G_BIDDER_CODE = 'a4g';
const A4G_CURRENCY = 'USD';
const A4G_DEFAULT_BID_URL = 'https://ads.ad4game.com/v1/bid';
const A4G_TTL = 120;
const LOCATION_PARAM_NAME = 'siteurl';
const ID_PARAM_NAME = 'id';
const IFRAME_PARAM_NAME = 'if';
const ZONE_ID_PARAM_NAME = 'zoneId';
const SIZE_PARAM_NAME = 'size';
const ARRAY_PARAM_SEPARATOR = ';';
const ARRAY_SIZE_SEPARATOR = ',';
const SIZE_SEPARATOR = 'x';
export const spec = {
code: A4G_BIDDER_CODE,
isBidRequestValid: function(bid) {
return bid.params && !!bid.params.zoneId;
},
buildRequests: function(validBidRequests, bidderRequest) {
let deliveryUrl = '';
const idParams = [];
const sizeParams = [];
const zoneIds = [];
_each(validBidRequests, function(bid) {
if (!deliveryUrl && typeof bid.params.deliveryUrl === 'string') {
deliveryUrl = bid.params.deliveryUrl;
}
idParams.push(bid.bidId);
let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes;
sizeParams.push(bidSizes.map(size => size.join(SIZE_SEPARATOR)).join(ARRAY_SIZE_SEPARATOR));
zoneIds.push(bid.params.zoneId);
});
if (!deliveryUrl) {
deliveryUrl = A4G_DEFAULT_BID_URL;
}
let data = {
[IFRAME_PARAM_NAME]: 0,
[LOCATION_PARAM_NAME]: bidderRequest.refererInfo?.page,
[SIZE_PARAM_NAME]: sizeParams.join(ARRAY_PARAM_SEPARATOR),
[ID_PARAM_NAME]: idParams.join(ARRAY_PARAM_SEPARATOR),
[ZONE_ID_PARAM_NAME]: zoneIds.join(ARRAY_PARAM_SEPARATOR)
};
if (bidderRequest && bidderRequest.gdprConsent) {
data.gdpr = {
applies: bidderRequest.gdprConsent.gdprApplies,
consent: bidderRequest.gdprConsent.consentString
};
}
return {
method: 'GET',
url: deliveryUrl,
data: data
};
},
interpretResponse: function(serverResponses, request) {
const bidResponses = [];
_each(serverResponses.body, function(response) {
if (response.cpm > 0) {
const bidResponse = {
requestId: response.id,
creativeId: response.crid || response.id,
cpm: response.cpm,
width: response.width,
height: response.height,
currency: A4G_CURRENCY,
netRevenue: true,
ttl: A4G_TTL,
ad: response.ad,
meta: {
advertiserDomains: response.adomain && response.adomain.length > 0 ? response.adomain : []
}
};
bidResponses.push(bidResponse);
}
});
return bidResponses;
}
};
registerBidder(spec);