Skip to content

Commit

Permalink
Adnuntius Bid Adapter : forces gdpr=1 flag if consent is required (#1…
Browse files Browse the repository at this point in the history
…0767)

* Removed linting issues

* Fixed merge issues.
  • Loading branch information
mikael-lundin authored Dec 7, 2023
1 parent cb82c47 commit 4fe6292
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
46 changes: 25 additions & 21 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const VALID_BID_TYPES = ['netBid', 'grossBid'];
const META_DATA_KEY = 'adn.metaData';

export const misc = {
getUnixTimestamp: function(addDays, asMinutes) {
getUnixTimestamp: function (addDays, asMinutes) {
const multiplication = addDays / (asMinutes ? 1440 : 1);
return Date.now() + (addDays && addDays > 0 ? (1000 * 60 * 60 * 24 * multiplication) : 0);
}
};

const storageTool = (function() {
const storage = getStorageManager({bidderCode: BIDDER_CODE});
const storageTool = (function () {
const storage = getStorageManager({ bidderCode: BIDDER_CODE });
let metaInternal;

const getMetaInternal = function() {
const getMetaInternal = function () {
if (!storage.localStorageIsEnabled()) {
return {};
}
Expand Down Expand Up @@ -57,24 +57,24 @@ const storageTool = (function() {
return filteredEntries;
};

const setMetaInternal = function(apiResponse) {
const setMetaInternal = function (apiResponse) {
if (!storage.localStorageIsEnabled()) {
return;
}

const updateVoidAuIds = function(currentVoidAuIds, auIdsAsString) {
const updateVoidAuIds = function (currentVoidAuIds, auIdsAsString) {
const newAuIds = auIdsAsString ? auIdsAsString.split(';') : [];
const notNewExistingAuIds = currentVoidAuIds.filter(auIdObj => {
return newAuIds.indexOf(auIdObj.value) < -1;
}) || [];
const oneDayFromNow = misc.getUnixTimestamp(1);
const apiIdsArray = newAuIds.map(auId => {
return {exp: oneDayFromNow, auId: auId};
return { exp: oneDayFromNow, auId: auId };
}) || [];
return notNewExistingAuIds.concat(apiIdsArray) || [];
}

const metaAsObj = getMetaInternal().reduce((a, entry) => ({...a, [entry.key]: {value: entry.value, exp: entry.exp}}), {});
const metaAsObj = getMetaInternal().reduce((a, entry) => ({ ...a, [entry.key]: { value: entry.value, exp: entry.exp } }), {});
for (const key in apiResponse) {
if (key !== 'voidAuIds') {
metaAsObj[key] = {
Expand All @@ -85,7 +85,7 @@ const storageTool = (function() {
}
const currentAuIds = updateVoidAuIds(metaAsObj.voidAuIds || [], apiResponse.voidAuIds || []);
if (currentAuIds.length > 0) {
metaAsObj.voidAuIds = {value: currentAuIds};
metaAsObj.voidAuIds = { value: currentAuIds };
}
const metaDataForSaving = Object.entries(metaAsObj).map((entrySet) => {
if (entrySet[0] === 'voidAuIds') {
Expand All @@ -103,7 +103,7 @@ const storageTool = (function() {
storage.setDataInLocalStorage(META_DATA_KEY, JSON.stringify(metaDataForSaving));
};

const getUsi = function(meta, ortb2) {
const getUsi = function (meta, ortb2) {
let usi = (meta && meta.usi) ? meta.usi : false;
if (ortb2 && ortb2.user && ortb2.user.id) {
usi = ortb2.user.id
Expand All @@ -128,9 +128,9 @@ const storageTool = (function() {
}

return {
refreshStorage: function(bidderRequest) {
refreshStorage: function (bidderRequest) {
const ortb2 = bidderRequest.ortb2 || {};
metaInternal = getMetaInternal().reduce((a, entry) => ({...a, [entry.key]: entry.value}), {});
metaInternal = getMetaInternal().reduce((a, entry) => ({ ...a, [entry.key]: entry.value }), {});
metaInternal.usi = getUsi(metaInternal, ortb2);
if (!metaInternal.usi) {
delete metaInternal.usi;
Expand All @@ -142,21 +142,21 @@ const storageTool = (function() {
}
metaInternal.segments = getSegmentsFromOrtb(ortb2);
},
saveToStorage: function(serverData) {
saveToStorage: function (serverData) {
setMetaInternal(serverData);
},
getUrlRelatedData: function() {
const {segments, usi, voidAuIdsArray} = metaInternal;
return {segments, usi, voidAuIdsArray};
getUrlRelatedData: function () {
const { segments, usi, voidAuIdsArray } = metaInternal;
return { segments, usi, voidAuIdsArray };
},
getPayloadRelatedData: function() {
const {segments, usi, userId, voidAuIdsArray, voidAuIds, ...payloadRelatedData} = metaInternal;
getPayloadRelatedData: function () {
const { segments, usi, userId, voidAuIdsArray, voidAuIds, ...payloadRelatedData } = metaInternal;
return payloadRelatedData;
}
};
})();

const validateBidType = function(bidTypeOption) {
const validateBidType = function (bidTypeOption) {
return VALID_BID_TYPES.indexOf(bidTypeOption || '') > -1 ? bidTypeOption : 'bid';
}

Expand All @@ -177,10 +177,13 @@ export const spec = {
const queryParamsAndValues = [];
queryParamsAndValues.push('tzo=' + new Date().getTimezoneOffset())
queryParamsAndValues.push('format=json')

const gdprApplies = deepAccess(bidderRequest, 'gdprConsent.gdprApplies');
const consentString = deepAccess(bidderRequest, 'gdprConsent.consentString');
if (gdprApplies !== undefined) queryParamsAndValues.push('consentString=' + consentString);
if (gdprApplies !== undefined) {
const flag = gdprApplies ? '1' : '0'
queryParamsAndValues.push('consentString=' + consentString);
queryParamsAndValues.push('gdpr=' + flag);
}

storageTool.refreshStorage(bidderRequest);

Expand All @@ -194,6 +197,7 @@ export const spec = {

const bidRequests = {};
const networks = {};

for (let i = 0; i < validBidRequests.length; i++) {
const bid = validBidRequests[i];
if ((urlRelatedMetaData.voidAuIdsArray && (urlRelatedMetaData.voidAuIdsArray.indexOf(bid.params.auId) > -1 || urlRelatedMetaData.voidAuIdsArray.indexOf(bid.params.auId.padStart(16, '0')) > -1))) {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('adnuntiusBidAdapter', function() {
const ENDPOINT_URL_VIDEO = `${ENDPOINT_URL_BASE}&userId=${usi}&tt=vast4`;
const ENDPOINT_URL_NOCOOKIE = `${ENDPOINT_URL_BASE}&userId=${usi}&noCookies=true`;
const ENDPOINT_URL_SEGMENTS = `${ENDPOINT_URL_BASE}&segments=segment1,segment2,segment3&userId=${usi}`;
const ENDPOINT_URL_CONSENT = `${EURO_URL}${tzo}&format=json&consentString=consentString&userId=${usi}`;
const ENDPOINT_URL_CONSENT = `${EURO_URL}${tzo}&format=json&consentString=consentString&gdpr=1&userId=${usi}`;
const adapter = newBidder(spec);

const bidderRequests = [
Expand Down

0 comments on commit 4fe6292

Please sign in to comment.