Skip to content

Commit d1a0f09

Browse files
authored
update apacdex bid adapter (#8247)
1 parent b56b3bc commit d1a0f09

File tree

2 files changed

+58
-47
lines changed

2 files changed

+58
-47
lines changed

modules/apacdexBidAdapter.js

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,9 @@ import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '.
22
import { config } from '../src/config.js';
33
import { registerBidder } from '../src/adapters/bidderFactory.js';
44
const BIDDER_CODE = 'apacdex';
5-
const CONFIG = {
6-
'apacdex': {
7-
'ENDPOINT': 'https://useast.quantumdex.io/auction/apacdex',
8-
'USERSYNC': 'https://sync.quantumdex.io/usersync/apacdex'
9-
},
10-
'quantumdex': {
11-
'ENDPOINT': 'https://useast.quantumdex.io/auction/quantumdex',
12-
'USERSYNC': 'https://sync.quantumdex.io/usersync/quantumdex'
13-
},
14-
'valueimpression': {
15-
'ENDPOINT': 'https://useast.quantumdex.io/auction/adapter',
16-
'USERSYNC': 'https://sync.quantumdex.io/usersync/adapter'
17-
}
18-
};
5+
const ENDPOINT = 'https://useast.quantumdex.io/auction/pbjs'
6+
const USERSYNC = 'https://sync.quantumdex.io/usersync/pbjs'
197

20-
var bidderConfig = CONFIG[BIDDER_CODE];
218
var bySlotTargetKey = {};
229
var bySlotSizesCount = {}
2310

@@ -56,8 +43,6 @@ export const spec = {
5643
let test;
5744
let bids = [];
5845

59-
bidderConfig = CONFIG[validBidRequests[0].bidder];
60-
6146
test = config.getConfig('debug');
6247

6348
validBidRequests.forEach(bidReq => {
@@ -156,13 +141,14 @@ export const spec = {
156141
transactionId: bid.transactionId,
157142
sizes: bid.sizes,
158143
bidId: bid.bidId,
144+
adUnitCode: bid.adUnitCode,
159145
bidFloor: bid.bidFloor
160146
}
161147
});
162148

163149
return {
164150
method: 'POST',
165-
url: bidderConfig.ENDPOINT,
151+
url: ENDPOINT,
166152
data: payload,
167153
withCredentials: true,
168154
bidderRequests: bids
@@ -209,32 +195,47 @@ export const spec = {
209195
});
210196
return bidResponses;
211197
},
212-
getUserSyncs: function (syncOptions, serverResponses) {
198+
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
213199
const syncs = [];
214-
try {
215-
if (syncOptions.iframeEnabled) {
216-
syncs.push({
217-
type: 'iframe',
218-
url: bidderConfig.USERSYNC
219-
});
200+
if (hasPurpose1Consent(gdprConsent)) {
201+
let params = '';
202+
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
203+
// add 'gdpr' only if 'gdprApplies' is defined
204+
if (typeof gdprConsent.gdprApplies === 'boolean') {
205+
params = `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
206+
} else {
207+
params = `?gdpr_consent=${gdprConsent.consentString}`;
208+
}
220209
}
221-
if (serverResponses.length > 0 && serverResponses[0].body && serverResponses[0].body.pixel) {
222-
serverResponses[0].body.pixel.forEach(px => {
223-
if (px.type === 'image' && syncOptions.pixelEnabled) {
224-
syncs.push({
225-
type: 'image',
226-
url: px.url
227-
});
228-
}
229-
if (px.type === 'iframe' && syncOptions.iframeEnabled) {
230-
syncs.push({
231-
type: 'iframe',
232-
url: px.url
233-
});
234-
}
235-
});
210+
if (uspConsent) {
211+
params += `${params ? '&' : '?'}us_privacy=${encodeURIComponent(uspConsent)}`;
236212
}
237-
} catch (e) { }
213+
214+
try {
215+
if (syncOptions.iframeEnabled) {
216+
syncs.push({
217+
type: 'iframe',
218+
url: USERSYNC + params
219+
});
220+
}
221+
if (serverResponses.length > 0 && serverResponses[0].body && serverResponses[0].body.pixel) {
222+
serverResponses[0].body.pixel.forEach(px => {
223+
if (px.type === 'image' && syncOptions.pixelEnabled) {
224+
syncs.push({
225+
type: 'image',
226+
url: px.url + params
227+
});
228+
}
229+
if (px.type === 'iframe' && syncOptions.iframeEnabled) {
230+
syncs.push({
231+
type: 'iframe',
232+
url: px.url + params
233+
});
234+
}
235+
});
236+
}
237+
} catch (e) { }
238+
}
238239
return syncs;
239240
}
240241
};
@@ -377,4 +378,14 @@ function getBidFloor(bid) {
377378
return null;
378379
}
379380

381+
function hasPurpose1Consent(gdprConsent) {
382+
let result = true;
383+
if (gdprConsent) {
384+
if (gdprConsent.gdprApplies && gdprConsent.apiVersion === 2) {
385+
result = !!(deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true);
386+
}
387+
}
388+
return result;
389+
}
390+
380391
registerBidder(spec);

test/spec/modules/apacdexBidAdapter_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ describe('ApacdexBidAdapter', function () {
252252

253253
it('should return a properly formatted request', function () {
254254
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
255-
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
255+
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
256256
expect(bidRequests.method).to.equal('POST')
257257
expect(bidRequests.bidderRequests).to.eql(bidRequest);
258258
})
259259

260260
it('should return a properly formatted request with GDPR applies set to true', function () {
261261
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
262-
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
262+
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
263263
expect(bidRequests.method).to.equal('POST')
264264
expect(bidRequests.data.gdpr.gdprApplies).to.equal(true)
265265
expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
@@ -268,7 +268,7 @@ describe('ApacdexBidAdapter', function () {
268268
it('should return a properly formatted request with GDPR applies set to false', function () {
269269
bidderRequests.gdprConsent.gdprApplies = false;
270270
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
271-
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
271+
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
272272
expect(bidRequests.method).to.equal('POST')
273273
expect(bidRequests.data.gdpr.gdprApplies).to.equal(false)
274274
expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
@@ -288,7 +288,7 @@ describe('ApacdexBidAdapter', function () {
288288
}
289289
};
290290
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
291-
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
291+
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
292292
expect(bidRequests.method).to.equal('POST')
293293
expect(bidRequests.data.gdpr.gdprApplies).to.equal(false)
294294
expect(bidRequests.data.gdpr).to.not.include.keys('consentString')
@@ -308,7 +308,7 @@ describe('ApacdexBidAdapter', function () {
308308
}
309309
};
310310
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
311-
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
311+
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
312312
expect(bidRequests.method).to.equal('POST')
313313
expect(bidRequests.data.gdpr.gdprApplies).to.equal(true)
314314
expect(bidRequests.data.gdpr).to.not.include.keys('consentString')
@@ -384,7 +384,7 @@ describe('ApacdexBidAdapter', function () {
384384
describe('.interpretResponse', function () {
385385
const bidRequests = {
386386
'method': 'POST',
387-
'url': 'https://useast.quantumdex.io/auction/apacdex',
387+
'url': 'https://useast.quantumdex.io/auction/pbjs',
388388
'withCredentials': true,
389389
'data': {
390390
'device': {

0 commit comments

Comments
 (0)