Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apacdex Adapter: change endpoint url and TCF purpose 1 enforcement #8247

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 52 additions & 41 deletions modules/apacdexBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@ import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '.
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'apacdex';
const CONFIG = {
'apacdex': {
'ENDPOINT': 'https://useast.quantumdex.io/auction/apacdex',
'USERSYNC': 'https://sync.quantumdex.io/usersync/apacdex'
},
'quantumdex': {
'ENDPOINT': 'https://useast.quantumdex.io/auction/quantumdex',
'USERSYNC': 'https://sync.quantumdex.io/usersync/quantumdex'
},
'valueimpression': {
'ENDPOINT': 'https://useast.quantumdex.io/auction/adapter',
'USERSYNC': 'https://sync.quantumdex.io/usersync/adapter'
}
};
const ENDPOINT = 'https://useast.quantumdex.io/auction/pbjs'
const USERSYNC = 'https://sync.quantumdex.io/usersync/pbjs'

var bidderConfig = CONFIG[BIDDER_CODE];
var bySlotTargetKey = {};
var bySlotSizesCount = {}

Expand Down Expand Up @@ -56,8 +43,6 @@ export const spec = {
let test;
let bids = [];

bidderConfig = CONFIG[validBidRequests[0].bidder];

test = config.getConfig('debug');

validBidRequests.forEach(bidReq => {
Expand Down Expand Up @@ -156,13 +141,14 @@ export const spec = {
transactionId: bid.transactionId,
sizes: bid.sizes,
bidId: bid.bidId,
adUnitCode: bid.adUnitCode,
bidFloor: bid.bidFloor
}
});

return {
method: 'POST',
url: bidderConfig.ENDPOINT,
url: ENDPOINT,
data: payload,
withCredentials: true,
bidderRequests: bids
Expand Down Expand Up @@ -209,32 +195,47 @@ export const spec = {
});
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses) {
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
try {
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: bidderConfig.USERSYNC
});
if (hasPurpose1Consent(gdprConsent)) {
let params = '';
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
params = `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
params = `?gdpr_consent=${gdprConsent.consentString}`;
}
}
if (serverResponses.length > 0 && serverResponses[0].body && serverResponses[0].body.pixel) {
serverResponses[0].body.pixel.forEach(px => {
if (px.type === 'image' && syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: px.url
});
}
if (px.type === 'iframe' && syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: px.url
});
}
});
if (uspConsent) {
params += `${params ? '&' : '?'}us_privacy=${encodeURIComponent(uspConsent)}`;
}
} catch (e) { }

try {
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: USERSYNC + params
});
}
if (serverResponses.length > 0 && serverResponses[0].body && serverResponses[0].body.pixel) {
serverResponses[0].body.pixel.forEach(px => {
if (px.type === 'image' && syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: px.url + params
});
}
if (px.type === 'iframe' && syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: px.url + params
});
}
});
}
} catch (e) { }
}
return syncs;
}
};
Expand Down Expand Up @@ -377,4 +378,14 @@ function getBidFloor(bid) {
return null;
}

function hasPurpose1Consent(gdprConsent) {
let result = true;
if (gdprConsent) {
if (gdprConsent.gdprApplies && gdprConsent.apiVersion === 2) {
result = !!(deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true);
}
}
return result;
}

registerBidder(spec);
12 changes: 6 additions & 6 deletions test/spec/modules/apacdexBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ describe('ApacdexBidAdapter', function () {

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

it('should return a properly formatted request with GDPR applies set to true', function () {
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
expect(bidRequests.method).to.equal('POST')
expect(bidRequests.data.gdpr.gdprApplies).to.equal(true)
expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
Expand All @@ -268,7 +268,7 @@ describe('ApacdexBidAdapter', function () {
it('should return a properly formatted request with GDPR applies set to false', function () {
bidderRequests.gdprConsent.gdprApplies = false;
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
expect(bidRequests.method).to.equal('POST')
expect(bidRequests.data.gdpr.gdprApplies).to.equal(false)
expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
Expand All @@ -288,7 +288,7 @@ describe('ApacdexBidAdapter', function () {
}
};
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
expect(bidRequests.method).to.equal('POST')
expect(bidRequests.data.gdpr.gdprApplies).to.equal(false)
expect(bidRequests.data.gdpr).to.not.include.keys('consentString')
Expand All @@ -308,7 +308,7 @@ describe('ApacdexBidAdapter', function () {
}
};
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/apacdex')
expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs')
expect(bidRequests.method).to.equal('POST')
expect(bidRequests.data.gdpr.gdprApplies).to.equal(true)
expect(bidRequests.data.gdpr).to.not.include.keys('consentString')
Expand Down Expand Up @@ -384,7 +384,7 @@ describe('ApacdexBidAdapter', function () {
describe('.interpretResponse', function () {
const bidRequests = {
'method': 'POST',
'url': 'https://useast.quantumdex.io/auction/apacdex',
'url': 'https://useast.quantumdex.io/auction/pbjs',
'withCredentials': true,
'data': {
'device': {
Expand Down