Skip to content

Commit

Permalink
InvibesBidAdapter - gdpr updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rcheptanariu committed Aug 14, 2020
1 parent f0cdb88 commit 704b9e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
29 changes: 12 additions & 17 deletions modules/invibesBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -117,7 +117,8 @@ function buildRequest(bidRequests, bidderRequest) {
oi: invibes.optIn,

kw: keywords,
purposes: invibes.purposes.toString()
purposes: invibes.purposes.toString(),

};

if (lid) {
Expand Down Expand Up @@ -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)) || {};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/spec/modules/invibesBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 704b9e8

Please sign in to comment.