prebid.js 6.7.0 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/integrationExamples/gpt/x-domain/creative.html +53 -26
- package/modules/adagioBidAdapter.js +0 -8
- package/modules/adagioBidAdapter.md +1 -1
- package/modules/appnexusBidAdapter.js +11 -0
- package/modules/brandmetricsRtdProvider.js +168 -0
- package/modules/brandmetricsRtdProvider.md +40 -0
- package/modules/criteoBidAdapter.js +9 -0
- package/modules/currency.js +26 -1
- package/modules/displayioBidAdapter.js +157 -0
- package/modules/displayioBidAdapter.md +148 -0
- package/modules/e_volutionBidAdapter.js +158 -0
- package/modules/gumgumBidAdapter.js +52 -38
- package/modules/interactiveOffersBidAdapter.js +9 -6
- package/modules/sovrnBidAdapter.js +93 -18
- package/modules/sovrnBidAdapter.md +80 -2
- package/modules/undertoneBidAdapter.js +17 -1
- package/modules/yahoosspBidAdapter.js +2 -0
- package/package.json +1 -1
- package/src/adRendering.js +38 -0
- package/src/auction.js +44 -9
- package/src/prebid.js +3 -19
- package/src/secureCreatives.js +111 -42
- package/src/utils.js +13 -3
- package/test/helpers/syncPromise.js +71 -0
- package/test/spec/auctionmanager_spec.js +148 -16
- package/test/spec/modules/adagioBidAdapter_spec.js +0 -10
- package/test/spec/modules/appnexusBidAdapter_spec.js +27 -0
- package/test/spec/modules/brandmetricsRtdProvider_spec.js +191 -0
- package/test/spec/modules/criteoBidAdapter_spec.js +21 -0
- package/test/spec/modules/currency_spec.js +21 -6
- package/test/spec/modules/displayioBidAdapter_spec.js +239 -0
- package/test/spec/modules/e_volutionBidAdapter_spec.js +242 -0
- package/test/spec/modules/gumgumBidAdapter_spec.js +46 -0
- package/test/spec/modules/sovrnBidAdapter_spec.js +413 -333
- package/test/spec/modules/undertoneBidAdapter_spec.js +55 -2
- package/test/spec/modules/yahoosspBidAdapter_spec.js +10 -0
- package/test/spec/unit/pbjs_api_spec.js +17 -1
- package/test/spec/unit/secureCreatives_spec.js +85 -0
|
@@ -2,37 +2,40 @@
|
|
|
2
2
|
// this script can be returned by an ad server delivering a cross domain iframe, into which the
|
|
3
3
|
// creative will be rendered, e.g. DFP delivering a SafeFrame
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const windowLocation = window.location;
|
|
6
|
+
const urlParser = document.createElement('a');
|
|
7
7
|
urlParser.href = '%%PATTERN:url%%';
|
|
8
|
-
|
|
8
|
+
const publisherDomain = urlParser.protocol + '//' + urlParser.hostname;
|
|
9
|
+
const adId = '%%PATTERN:hb_adid%%';
|
|
9
10
|
|
|
10
11
|
function renderAd(ev) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const key = ev.message ? 'message' : 'data';
|
|
13
|
+
let adObject = {};
|
|
14
|
+
try {
|
|
15
|
+
adObject = JSON.parse(ev[key]);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const origin = ev.origin || ev.originalEvent.origin;
|
|
21
|
+
if (adObject.message && adObject.message === 'Prebid Response' &&
|
|
22
|
+
publisherDomain === origin &&
|
|
23
|
+
adObject.adId === adId) {
|
|
24
|
+
try {
|
|
25
|
+
const body = window.document.body;
|
|
26
|
+
const ad = adObject.ad;
|
|
27
|
+
const url = adObject.adUrl;
|
|
28
|
+
const width = adObject.width;
|
|
29
|
+
const height = adObject.height;
|
|
29
30
|
|
|
30
31
|
if (adObject.mediaType === 'video') {
|
|
32
|
+
signalRenderResult(false, {
|
|
33
|
+
reason: 'preventWritingOnMainDocument',
|
|
34
|
+
message: `Cannot render video ad ${adId}`
|
|
35
|
+
});
|
|
31
36
|
console.log('Error trying to write ad.');
|
|
32
|
-
} else
|
|
33
|
-
|
|
34
|
-
if (ad) {
|
|
35
|
-
var frame = document.createElement('iframe');
|
|
37
|
+
} else if (ad) {
|
|
38
|
+
const frame = document.createElement('iframe');
|
|
36
39
|
frame.setAttribute('FRAMEBORDER', 0);
|
|
37
40
|
frame.setAttribute('SCROLLING', 'no');
|
|
38
41
|
frame.setAttribute('MARGINHEIGHT', 0);
|
|
@@ -46,18 +49,42 @@ function renderAd(ev) {
|
|
|
46
49
|
frame.contentDocument.open();
|
|
47
50
|
frame.contentDocument.write(ad);
|
|
48
51
|
frame.contentDocument.close();
|
|
52
|
+
signalRenderResult(true);
|
|
49
53
|
} else if (url) {
|
|
50
54
|
body.insertAdjacentHTML('beforeend', '<IFRAME SRC="' + url + '" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true" WIDTH="' + width + '" HEIGHT="' + height + '"></IFRAME>');
|
|
55
|
+
signalRenderResult(true);
|
|
51
56
|
} else {
|
|
52
|
-
|
|
57
|
+
signalRenderResult(false, {
|
|
58
|
+
reason: 'noAd',
|
|
59
|
+
message: `No ad for ${adId}`
|
|
60
|
+
});
|
|
61
|
+
console.log(`Error trying to write ad. No ad markup or adUrl for ${adId}`);
|
|
53
62
|
}
|
|
63
|
+
} catch (e) {
|
|
64
|
+
signalRenderResult(false, {reason: 'exception', message: e.message});
|
|
65
|
+
console.log(`Error in rendering ad`, e);
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
|
|
69
|
+
function signalRenderResult(success, {reason, message} = {}) {
|
|
70
|
+
const payload = {
|
|
71
|
+
message: 'Prebid Event',
|
|
72
|
+
adId,
|
|
73
|
+
event: success ? 'adRenderSucceeded' : 'adRenderFailed',
|
|
74
|
+
}
|
|
75
|
+
if (!success) {
|
|
76
|
+
payload.info = {reason, message};
|
|
77
|
+
}
|
|
78
|
+
ev.source.postMessage(JSON.stringify(payload), publisherDomain);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
57
84
|
function requestAdFromPrebid() {
|
|
58
85
|
var message = JSON.stringify({
|
|
59
86
|
message: 'Prebid Request',
|
|
60
|
-
adId
|
|
87
|
+
adId
|
|
61
88
|
});
|
|
62
89
|
window.parent.postMessage(message, publisherDomain);
|
|
63
90
|
}
|
|
@@ -268,8 +268,6 @@ function getSite(bidderRequest) {
|
|
|
268
268
|
} else if (refererInfo.stack && refererInfo.stack.length && refererInfo.stack[0]) {
|
|
269
269
|
// important note check if refererInfo.stack[0] is 'thruly' because a `null` value
|
|
270
270
|
// will be considered as "localhost" by the parseUrl function.
|
|
271
|
-
// As the isBidRequestValid returns false when it does not reach the referer
|
|
272
|
-
// this should never called.
|
|
273
271
|
const url = parseUrl(refererInfo.stack[0]);
|
|
274
272
|
domain = url.hostname;
|
|
275
273
|
}
|
|
@@ -873,12 +871,6 @@ export const spec = {
|
|
|
873
871
|
|
|
874
872
|
autoFillParams(bid);
|
|
875
873
|
|
|
876
|
-
if (!internal.getRefererInfo().reachedTop) {
|
|
877
|
-
logWarn(`${LOG_PREFIX} the main page url is unreachabled.`);
|
|
878
|
-
// internal.enqueue(debugData());
|
|
879
|
-
return false;
|
|
880
|
-
}
|
|
881
|
-
|
|
882
874
|
if (!(bid.params.organizationId && bid.params.site && bid.params.placement)) {
|
|
883
875
|
logWarn(`${LOG_PREFIX} at least one required param is missing.`);
|
|
884
876
|
// internal.enqueue(debugData());
|
|
@@ -18,7 +18,7 @@ Below, the list of Adagio params and where they can be set.
|
|
|
18
18
|
| ---------- | ------------- | ------------- |
|
|
19
19
|
| siteId | x |
|
|
20
20
|
| organizationId (obsolete) | | x
|
|
21
|
-
|
|
|
21
|
+
| site (obsolete) | | x
|
|
22
22
|
| pagetype | x | x
|
|
23
23
|
| environment | x | x
|
|
24
24
|
| category | x | x
|
|
@@ -201,6 +201,17 @@ export const spec = {
|
|
|
201
201
|
payload.app = appIdObj;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
let auctionKeywords = config.getConfig('appnexusAuctionKeywords');
|
|
205
|
+
if (isPlainObject(auctionKeywords)) {
|
|
206
|
+
let aucKeywords = transformBidderParamKeywords(auctionKeywords);
|
|
207
|
+
|
|
208
|
+
if (aucKeywords.length > 0) {
|
|
209
|
+
aucKeywords.forEach(deleteValues);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
payload.keywords = aucKeywords;
|
|
213
|
+
}
|
|
214
|
+
|
|
204
215
|
if (config.getConfig('adpod.brandCategoryExclusion')) {
|
|
205
216
|
payload.brand_category_uniqueness = true;
|
|
206
217
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module adds brandmetrics provider to the real time data module
|
|
3
|
+
* The {@link module:modules/realTimeData} module is required
|
|
4
|
+
* The module will load load the brandmetrics script and set survey- targeting to ad units of specific bidders.
|
|
5
|
+
* @module modules/brandmetricsRtdProvider
|
|
6
|
+
* @requires module:modules/realTimeData
|
|
7
|
+
*/
|
|
8
|
+
import { config } from '../src/config.js'
|
|
9
|
+
import { submodule } from '../src/hook.js'
|
|
10
|
+
import { deepSetValue, mergeDeep, logError, deepAccess } from '../src/utils.js'
|
|
11
|
+
import {loadExternalScript} from '../src/adloader.js'
|
|
12
|
+
const MODULE_NAME = 'brandmetrics'
|
|
13
|
+
const MODULE_CODE = MODULE_NAME
|
|
14
|
+
const RECEIVED_EVENTS = []
|
|
15
|
+
const GVL_ID = 422
|
|
16
|
+
const TCF_PURPOSES = [1, 7]
|
|
17
|
+
|
|
18
|
+
function init (config, userConsent) {
|
|
19
|
+
const hasConsent = checkConsent(userConsent)
|
|
20
|
+
|
|
21
|
+
if (hasConsent) {
|
|
22
|
+
const moduleConfig = getMergedConfig(config)
|
|
23
|
+
initializeBrandmetrics(moduleConfig.params.scriptId)
|
|
24
|
+
}
|
|
25
|
+
return hasConsent
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks TCF and USP consents
|
|
30
|
+
* @param {Object} userConsent
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
function checkConsent (userConsent) {
|
|
34
|
+
let consent = false
|
|
35
|
+
|
|
36
|
+
if (userConsent && userConsent.gdpr && userConsent.gdpr.gdprApplies) {
|
|
37
|
+
const gdpr = userConsent.gdpr
|
|
38
|
+
|
|
39
|
+
if (gdpr.vendorData) {
|
|
40
|
+
const vendor = gdpr.vendorData.vendor
|
|
41
|
+
const purpose = gdpr.vendorData.purpose
|
|
42
|
+
|
|
43
|
+
let vendorConsent = false
|
|
44
|
+
if (vendor.consents) {
|
|
45
|
+
vendorConsent = vendor.consents[GVL_ID]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (vendor.legitimateInterests) {
|
|
49
|
+
vendorConsent = vendorConsent || vendor.legitimateInterests[GVL_ID]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const purposes = TCF_PURPOSES.map(id => {
|
|
53
|
+
return (purpose.consents && purpose.consents[id]) || (purpose.legitimateInterests && purpose.legitimateInterests[id])
|
|
54
|
+
})
|
|
55
|
+
const purposesValid = purposes.filter(p => p === true).length === TCF_PURPOSES.length
|
|
56
|
+
consent = vendorConsent && purposesValid
|
|
57
|
+
}
|
|
58
|
+
} else if (userConsent.usp) {
|
|
59
|
+
const usp = userConsent.usp
|
|
60
|
+
consent = usp[1] !== 'N' && usp[2] !== 'Y'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return consent
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Add event- listeners to hook in to brandmetrics events
|
|
68
|
+
* @param {Object} reqBidsConfigObj
|
|
69
|
+
* @param {function} callback
|
|
70
|
+
*/
|
|
71
|
+
function processBrandmetricsEvents (reqBidsConfigObj, moduleConfig, callback) {
|
|
72
|
+
const callBidTargeting = (event) => {
|
|
73
|
+
if (event.available && event.conf) {
|
|
74
|
+
const targetingConf = event.conf.displayOption || {}
|
|
75
|
+
if (targetingConf.type === 'pbjs') {
|
|
76
|
+
setBidderTargeting(reqBidsConfigObj, moduleConfig, targetingConf.targetKey || 'brandmetrics_survey', event.survey.measurementId)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
callback()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (RECEIVED_EVENTS.length > 0) {
|
|
83
|
+
callBidTargeting(RECEIVED_EVENTS[RECEIVED_EVENTS.length - 1])
|
|
84
|
+
} else {
|
|
85
|
+
window._brandmetrics = window._brandmetrics || []
|
|
86
|
+
window._brandmetrics.push({
|
|
87
|
+
cmd: '_addeventlistener',
|
|
88
|
+
val: {
|
|
89
|
+
event: 'surveyloaded',
|
|
90
|
+
reEmitLast: true,
|
|
91
|
+
handler: (ev) => {
|
|
92
|
+
RECEIVED_EVENTS.push(ev)
|
|
93
|
+
if (RECEIVED_EVENTS.length === 1) {
|
|
94
|
+
// Call bid targeting only for the first received event, if called subsequently, last event from the RECEIVED_EVENTS array is used
|
|
95
|
+
callBidTargeting(ev)
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Sets bid targeting of specific bidders
|
|
105
|
+
* @param {Object} reqBidsConfigObj
|
|
106
|
+
* @param {string} key Targeting key
|
|
107
|
+
* @param {string} val Targeting value
|
|
108
|
+
*/
|
|
109
|
+
function setBidderTargeting (reqBidsConfigObj, moduleConfig, key, val) {
|
|
110
|
+
const bidders = deepAccess(moduleConfig, 'params.bidders')
|
|
111
|
+
if (bidders && bidders.length > 0) {
|
|
112
|
+
const ortb2 = {}
|
|
113
|
+
deepSetValue(ortb2, 'ortb2.user.ext.data.' + key, val)
|
|
114
|
+
config.setBidderConfig({
|
|
115
|
+
bidders: bidders,
|
|
116
|
+
config: ortb2
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Add the brandmetrics script to the page.
|
|
123
|
+
* @param {string} scriptId - The script- id provided by brandmetrics or brandmetrics partner
|
|
124
|
+
*/
|
|
125
|
+
function initializeBrandmetrics(scriptId) {
|
|
126
|
+
if (scriptId) {
|
|
127
|
+
const path = 'https://cdn.brandmetrics.com/survey/script/'
|
|
128
|
+
const file = scriptId + '.js'
|
|
129
|
+
const url = path + file
|
|
130
|
+
|
|
131
|
+
loadExternalScript(url, MODULE_CODE)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Merges a provided config with default values
|
|
137
|
+
* @param {Object} customConfig
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
function getMergedConfig(customConfig) {
|
|
141
|
+
return mergeDeep({
|
|
142
|
+
waitForIt: false,
|
|
143
|
+
params: {
|
|
144
|
+
bidders: [],
|
|
145
|
+
scriptId: undefined,
|
|
146
|
+
}
|
|
147
|
+
}, customConfig)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @type {RtdSubmodule} */
|
|
151
|
+
export const brandmetricsSubmodule = {
|
|
152
|
+
name: MODULE_NAME,
|
|
153
|
+
getBidRequestData: function (reqBidsConfigObj, callback, customConfig) {
|
|
154
|
+
try {
|
|
155
|
+
const moduleConfig = getMergedConfig(customConfig)
|
|
156
|
+
if (moduleConfig.waitForIt) {
|
|
157
|
+
processBrandmetricsEvents(reqBidsConfigObj, moduleConfig, callback)
|
|
158
|
+
} else {
|
|
159
|
+
callback()
|
|
160
|
+
}
|
|
161
|
+
} catch (e) {
|
|
162
|
+
logError(e)
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
init: init
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
submodule('realTimeData', brandmetricsSubmodule)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Brandmetrics Real-time Data Submodule
|
|
2
|
+
This module is intended to be used by brandmetrics (https://brandmetrics.com) partners and sets targeting keywords to bids if the browser is eligeble to see a brandmetrics survey.
|
|
3
|
+
The module hooks in to brandmetrics events and requires a brandmetrics script to be running. The module can optionally load and initialize brandmetrics by providing the 'scriptId'- parameter.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
Compile the Brandmetrics RTD module into your Prebid build:
|
|
7
|
+
```
|
|
8
|
+
gulp build --modules=rtdModule,brandmetricsRtdProvider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
> Note that the global RTD module, `rtdModule`, is a prerequisite of the Brandmetrics RTD module.
|
|
12
|
+
|
|
13
|
+
Enable the Brandmetrics RTD in your Prebid configuration, using the below format:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
pbjs.setConfig({
|
|
17
|
+
...,
|
|
18
|
+
realTimeData: {
|
|
19
|
+
auctionDelay: 500, // auction delay
|
|
20
|
+
dataProviders: [{
|
|
21
|
+
name: 'brandmetrics',
|
|
22
|
+
waitForIt: true // should be true if there's an `auctionDelay`,
|
|
23
|
+
params: {
|
|
24
|
+
scriptId: '00000000-0000-0000-0000-000000000000',
|
|
25
|
+
bidders: ['ozone']
|
|
26
|
+
}
|
|
27
|
+
}]
|
|
28
|
+
},
|
|
29
|
+
...
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Parameters
|
|
34
|
+
| Name | Type | Description | Default |
|
|
35
|
+
| ----------------- | -------------------- | ------------------ | ------------------ |
|
|
36
|
+
| name | String | This should always be `brandmetrics` | - |
|
|
37
|
+
| waitForIt | Boolean | Should be `true` if there's an `auctionDelay` defined (recommended) | `false` |
|
|
38
|
+
| params | Object | | - |
|
|
39
|
+
| params.bidders | String[] | An array of bidders which should receive targeting keys. | `[]` |
|
|
40
|
+
| params.scriptId | String | A script- id GUID if the brandmetrics- script should be initialized. | `undefined` |
|
|
@@ -281,6 +281,7 @@ function checkNativeSendId(bidRequest) {
|
|
|
281
281
|
*/
|
|
282
282
|
function buildCdbRequest(context, bidRequests, bidderRequest) {
|
|
283
283
|
let networkId;
|
|
284
|
+
let schain;
|
|
284
285
|
const request = {
|
|
285
286
|
publisher: {
|
|
286
287
|
url: context.url,
|
|
@@ -288,6 +289,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
|
|
|
288
289
|
},
|
|
289
290
|
slots: bidRequests.map(bidRequest => {
|
|
290
291
|
networkId = bidRequest.params.networkId || networkId;
|
|
292
|
+
schain = bidRequest.schain || schain;
|
|
291
293
|
const slot = {
|
|
292
294
|
impid: bidRequest.adUnitCode,
|
|
293
295
|
transactionid: bidRequest.transactionId,
|
|
@@ -344,6 +346,13 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
|
|
|
344
346
|
if (networkId) {
|
|
345
347
|
request.publisher.networkid = networkId;
|
|
346
348
|
}
|
|
349
|
+
if (schain) {
|
|
350
|
+
request.source = {
|
|
351
|
+
ext: {
|
|
352
|
+
schain: schain
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
347
356
|
request.user = {
|
|
348
357
|
ext: bidderRequest.userExt
|
|
349
358
|
};
|
package/modules/currency.js
CHANGED
|
@@ -20,6 +20,25 @@ export var currencyRates = {};
|
|
|
20
20
|
var bidderCurrencyDefault = {};
|
|
21
21
|
var defaultRates;
|
|
22
22
|
|
|
23
|
+
export const ready = (() => {
|
|
24
|
+
let isDone, resolver, promise;
|
|
25
|
+
function reset() {
|
|
26
|
+
isDone = false;
|
|
27
|
+
resolver = null;
|
|
28
|
+
promise = new Promise((resolve) => {
|
|
29
|
+
resolver = resolve;
|
|
30
|
+
if (isDone) resolve();
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
function done() {
|
|
34
|
+
isDone = true;
|
|
35
|
+
if (resolver != null) { resolver() }
|
|
36
|
+
}
|
|
37
|
+
reset();
|
|
38
|
+
|
|
39
|
+
return {done, reset, promise: () => promise}
|
|
40
|
+
})();
|
|
41
|
+
|
|
23
42
|
/**
|
|
24
43
|
* Configuration function for currency
|
|
25
44
|
* @param {string} [config.adServerCurrency = 'USD']
|
|
@@ -138,11 +157,15 @@ function initCurrency(url) {
|
|
|
138
157
|
logInfo('currencyRates set to ' + JSON.stringify(currencyRates));
|
|
139
158
|
currencyRatesLoaded = true;
|
|
140
159
|
processBidResponseQueue();
|
|
160
|
+
ready.done();
|
|
141
161
|
} catch (e) {
|
|
142
162
|
errorSettingsRates('Failed to parse currencyRates response: ' + response);
|
|
143
163
|
}
|
|
144
164
|
},
|
|
145
|
-
error:
|
|
165
|
+
error: function (...args) {
|
|
166
|
+
errorSettingsRates(...args);
|
|
167
|
+
ready.done();
|
|
168
|
+
}
|
|
146
169
|
}
|
|
147
170
|
);
|
|
148
171
|
}
|
|
@@ -197,6 +220,8 @@ export function addBidResponseHook(fn, adUnitCode, bid) {
|
|
|
197
220
|
bidResponseQueue.push(wrapFunction(fn, this, [adUnitCode, bid]));
|
|
198
221
|
if (!currencySupportEnabled || currencyRatesLoaded) {
|
|
199
222
|
processBidResponseQueue();
|
|
223
|
+
} else {
|
|
224
|
+
fn.bail(ready.promise());
|
|
200
225
|
}
|
|
201
226
|
}
|
|
202
227
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {registerBidder} from '../src/adapters/bidderFactory.js';
|
|
2
|
+
import {BANNER, VIDEO} from '../src/mediaTypes.js';
|
|
3
|
+
|
|
4
|
+
const BIDDER_VERSION = '1.0.0';
|
|
5
|
+
const BIDDER_CODE = 'displayio';
|
|
6
|
+
const GVLID = 999;
|
|
7
|
+
const BID_TTL = 300;
|
|
8
|
+
const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
|
|
9
|
+
const DEFAULT_CURRENCY = 'USD';
|
|
10
|
+
|
|
11
|
+
export const spec = {
|
|
12
|
+
code: BIDDER_CODE,
|
|
13
|
+
gvlid: GVLID,
|
|
14
|
+
supportedMediaTypes: SUPPORTED_AD_TYPES,
|
|
15
|
+
isBidRequestValid: function(bid) {
|
|
16
|
+
return !!(bid.params && bid.params.placementId && bid.params.siteId &&
|
|
17
|
+
bid.params.adsSrvDomain && bid.params.cdnDomain);
|
|
18
|
+
},
|
|
19
|
+
buildRequests: function (bidRequests, bidderRequest) {
|
|
20
|
+
return bidRequests.map(bid => {
|
|
21
|
+
let url = '//' + bid.params.adsSrvDomain + '/srv?method=getPlacement&app=' +
|
|
22
|
+
bid.params.siteId + '&placement=' + bid.params.placementId;
|
|
23
|
+
const data = this._getPayload(bid, bidderRequest);
|
|
24
|
+
return {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
|
27
|
+
url,
|
|
28
|
+
data
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
interpretResponse: function (serverResponse, serverRequest) {
|
|
33
|
+
const ads = serverResponse.body.data.ads;
|
|
34
|
+
const bidResponses = [];
|
|
35
|
+
const { data } = serverRequest.data;
|
|
36
|
+
if (ads.length) {
|
|
37
|
+
const adData = ads[0].ad.data;
|
|
38
|
+
const bidResponse = {
|
|
39
|
+
requestId: data.id,
|
|
40
|
+
cpm: adData.ecpm,
|
|
41
|
+
width: adData.w,
|
|
42
|
+
height: adData.h,
|
|
43
|
+
netRevenue: true,
|
|
44
|
+
ttl: BID_TTL,
|
|
45
|
+
creativeId: adData.adId || 0,
|
|
46
|
+
currency: DEFAULT_CURRENCY,
|
|
47
|
+
referrer: data.data.ref,
|
|
48
|
+
mediaType: ads[0].ad.subtype,
|
|
49
|
+
ad: adData.markup,
|
|
50
|
+
placement: data.placement,
|
|
51
|
+
adData: adData
|
|
52
|
+
};
|
|
53
|
+
if (bidResponse.vastUrl === 'videoVast') {
|
|
54
|
+
bidResponse.vastUrl = adData.videos[0].url
|
|
55
|
+
}
|
|
56
|
+
bidResponses.push(bidResponse);
|
|
57
|
+
}
|
|
58
|
+
return bidResponses;
|
|
59
|
+
},
|
|
60
|
+
_getPayload: function (bid, bidderRequest) {
|
|
61
|
+
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
62
|
+
const userSession = 'us_web_xxxxxxxxxxxx'.replace(/[x]/g, c => {
|
|
63
|
+
let r = Math.random() * 16 | 0;
|
|
64
|
+
let v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
65
|
+
return v.toString(16);
|
|
66
|
+
});
|
|
67
|
+
const { params } = bid;
|
|
68
|
+
const { siteId, placementId } = params;
|
|
69
|
+
const { refererInfo, uspConsent, gdprConsent } = bidderRequest;
|
|
70
|
+
const mediation = {consent: '-1', gdpr: '-1'};
|
|
71
|
+
if (gdprConsent) {
|
|
72
|
+
if (gdprConsent.consentString !== undefined) {
|
|
73
|
+
mediation.consent = gdprConsent.consentString;
|
|
74
|
+
}
|
|
75
|
+
if (gdprConsent.gdprApplies !== undefined) {
|
|
76
|
+
mediation.gdpr = gdprConsent.gdprApplies ? '1' : '0';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const payload = {
|
|
80
|
+
userSession,
|
|
81
|
+
data: {
|
|
82
|
+
id: bid.bidId,
|
|
83
|
+
action: 'getPlacement',
|
|
84
|
+
app: siteId,
|
|
85
|
+
placement: placementId,
|
|
86
|
+
data: {
|
|
87
|
+
pagecat: params.pageCategory ? params.pageCategory.split(',').map(k => k.trim()) : [],
|
|
88
|
+
keywords: params.keywords ? params.keywords.split(',').map(k => k.trim()) : [],
|
|
89
|
+
lang_content: document.documentElement.lang,
|
|
90
|
+
lang: window.navigator.language,
|
|
91
|
+
domain: window.location.hostname,
|
|
92
|
+
page: window.location.href,
|
|
93
|
+
ref: refererInfo.referer,
|
|
94
|
+
userids: _getUserIDs(),
|
|
95
|
+
geo: '',
|
|
96
|
+
},
|
|
97
|
+
complianceData: {
|
|
98
|
+
child: '-1',
|
|
99
|
+
us_privacy: uspConsent,
|
|
100
|
+
dnt: window.navigator.doNotTrack,
|
|
101
|
+
iabConsent: {},
|
|
102
|
+
mediation: {
|
|
103
|
+
consent: mediation.consent,
|
|
104
|
+
gdpr: mediation.gdpr,
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
integration: 'JS',
|
|
108
|
+
omidpn: 'Displayio',
|
|
109
|
+
mediationPlatform: 0,
|
|
110
|
+
prebidVersion: BIDDER_VERSION,
|
|
111
|
+
device: {
|
|
112
|
+
w: window.screen.width,
|
|
113
|
+
h: window.screen.height,
|
|
114
|
+
connection_type: connection ? connection.effectiveType : '',
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (navigator.permissions) {
|
|
119
|
+
navigator.permissions.query({ name: 'geolocation' })
|
|
120
|
+
.then((result) => {
|
|
121
|
+
if (result.state === 'granted') {
|
|
122
|
+
payload.data.data.geo = _getGeoData();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return payload
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
function _getUserIDs () {
|
|
131
|
+
let ids = {};
|
|
132
|
+
try {
|
|
133
|
+
ids = window.owpbjs.getUserIdsAsEids();
|
|
134
|
+
} catch (e) {}
|
|
135
|
+
return ids;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function _getGeoData () {
|
|
139
|
+
let geoData = null;
|
|
140
|
+
const getCurrentPosition = () => {
|
|
141
|
+
return new Promise((resolve, reject) =>
|
|
142
|
+
navigator.geolocation.getCurrentPosition(resolve, reject)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const position = await getCurrentPosition();
|
|
147
|
+
let {latitude, longitude, accuracy} = position.coords;
|
|
148
|
+
geoData = {
|
|
149
|
+
'lat': latitude,
|
|
150
|
+
'lng': longitude,
|
|
151
|
+
'precision': accuracy
|
|
152
|
+
};
|
|
153
|
+
} catch (e) {}
|
|
154
|
+
return geoData
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
registerBidder(spec);
|