From 704b9e8964d06a6c6c9d0b6526d76ad638a6c3c4 Mon Sep 17 00:00:00 2001 From: raduchept Date: Fri, 14 Aug 2020 18:06:23 +0300 Subject: [PATCH] InvibesBidAdapter - gdpr updates --- modules/invibesBidAdapter.js | 29 +++++++++------------ test/spec/modules/invibesBidAdapter_spec.js | 10 +++++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/modules/invibesBidAdapter.js b/modules/invibesBidAdapter.js index 603e653351d..f507dccc5f5 100644 --- a/modules/invibesBidAdapter.js +++ b/modules/invibesBidAdapter.js @@ -8,7 +8,7 @@ const CONSTANTS = { SYNC_ENDPOINT: 'https://k.r66net.com/GetUserSync', TIME_TO_LIVE: 300, DEFAULT_CURRENCY: 'EUR', - PREBID_VERSION: 2, + PREBID_VERSION: 4, METHOD: 'GET', INVIBES_VENDOR_ID: 436 }; @@ -53,6 +53,7 @@ registerBidder(spec); // some state info is required: cookie info, unique user visit id const topWin = getTopMostWindow(); let invibes = topWin.invibes = topWin.invibes || {}; +invibes.purposes = invibes.purposes || [false, false, false, false, false, false, false, false, false, false]; let _customUserSync; function isBidRequestValid(bid) { @@ -87,11 +88,10 @@ function buildRequest(bidRequests, bidderRequest) { _customUserSync = _customUserSync || bidRequest.params.customUserSync; }); - invibes.visitId = invibes.visitId || generateRandomId(); + invibes.optIn = invibes.optIn || readGdprConsent(bidderRequest.gdprConsent); + invibes.visitId = invibes.visitId || generateRandomId(); invibes.noCookies = invibes.noCookies || invibes.getCookie('ivNoCookie'); - invibes.optIn = invibes.optIn || invibes.getCookie('ivOptIn') || readGdprConsent(bidderRequest.gdprConsent); - let lid = initDomainId(invibes.domainOptions); const currentQueryStringParams = parseQueryStringParams(); @@ -117,7 +117,8 @@ function buildRequest(bidRequests, bidderRequest) { oi: invibes.optIn, kw: keywords, - purposes: invibes.purposes.toString() + purposes: invibes.purposes.toString(), + }; if (lid) { @@ -275,6 +276,8 @@ function renderCreative(bidModel) { function getCappedCampaignsAsString() { const key = 'ivvcap'; + if (!invibes.optIn || !invibes.purposes[0]) { return ''; } + let loadData = function () { try { return JSON.parse(storage.getDataFromLocalStorage(key)) || {}; @@ -346,8 +349,6 @@ function buildSyncUrl() { } function readGdprConsent(gdprConsent) { - invibes.purposes = [false, false, false, false, false, false, false, false, false, false]; - if (gdprConsent && gdprConsent.vendorData) { if (!gdprConsent.vendorData.gdprApplies || gdprConsent.vendorData.hasGlobalConsent) { var index; @@ -440,16 +441,10 @@ invibes.Uid = { invibes.getCookie = function (name) { if (!storage.cookiesAreEnabled()) { return; } - let i, x, y; - let cookies = document.cookie.split(';'); - for (i = 0; i < cookies.length; i++) { - x = cookies[i].substr(0, cookies[i].indexOf('=')); - y = cookies[i].substr(cookies[i].indexOf('=') + 1); - x = x.replace(/^\s+|\s+$/g, ''); - if (x === name) { - return unescape(y); - } - } + + if (!invibes.optIn || !invibes.purposes[0]) { return; } + + return storage.getCookie(name); }; let initDomainId = function (options) { diff --git a/test/spec/modules/invibesBidAdapter_spec.js b/test/spec/modules/invibesBidAdapter_spec.js index 13a9b6ec29c..69eebaf9291 100644 --- a/test/spec/modules/invibesBidAdapter_spec.js +++ b/test/spec/modules/invibesBidAdapter_spec.js @@ -137,11 +137,19 @@ describe('invibesBidAdapter:', function () { }); it('has capped ids if local storage variable is correctly formatted', function () { + top.window.invibes.optIn = 1; + top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; localStorage.ivvcap = '{"9731":[1,1768600800000]}'; const request = spec.buildRequests(bidRequests, {auctionStart: Date.now()}); expect(request.data.capCounts).to.equal('9731=1'); }); + it('does not have capped ids if local storage variable is correctly formatted but no opt in', function () { + localStorage.ivvcap = '{"9731":[1,1768600800000]}'; + const request = spec.buildRequests(bidRequests, {auctionStart: Date.now()}); + expect(request.data.capCounts).to.equal(''); + }); + it('does not have capped ids if local storage variable is incorrectly formatted', function () { localStorage.ivvcap = ':[1,1574334216992]}'; const request = spec.buildRequests(bidRequests, {auctionStart: Date.now()}); @@ -184,6 +192,8 @@ describe('invibesBidAdapter:', function () { }); it('sends lid when comes on cookie', function () { + top.window.invibes.optIn = 1; + top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":' + Date.now() + ',"hc":0}'; let bidderRequest = {gdprConsent: {vendorData: {vendorConsents: {436: true}}}}; let request = spec.buildRequests(bidRequests, bidderRequest);