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

purposes in call for invibes #5533

Merged
merged 10 commits into from
Aug 20, 2020
153 changes: 29 additions & 124 deletions modules/invibesBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const spec = {
},
getUserSyncs: function (syncOptions) {
if (syncOptions.iframeEnabled) {
handlePostMessage();
const syncUrl = buildSyncUrl();

return {
type: 'iframe',
url: syncUrl
Expand Down Expand Up @@ -91,11 +89,10 @@ function buildRequest(bidRequests, bidderRequest) {

invibes.visitId = invibes.visitId || generateRandomId();

cookieDomain = detectTopmostCookieDomain();
invibes.noCookies = invibes.noCookies || invibes.getCookie('ivNoCookie');
invibes.optIn = invibes.optIn || invibes.getCookie('ivOptIn') || readGdprConsent(bidderRequest.gdprConsent);

initDomainId(invibes.domainOptions);
let lid = initDomainId(invibes.domainOptions);

const currentQueryStringParams = parseQueryStringParams();

Expand All @@ -117,14 +114,17 @@ function buildRequest(bidRequests, bidderRequest) {
width: topWin.innerWidth,
height: topWin.innerHeight,

noc: !cookieDomain,
oi: invibes.optIn,

kw: keywords
kw: keywords,
p1: invibes.purposes[0],
p2and7: invibes.purposes[1] && invibes.purposes[6],
p9: invibes.purposes[8],
onePMissing: invibes.purposes.every(Boolean)
};

if (invibes.dom.id) {
data.lId = invibes.dom.id;
if (lid) {
data.lId = lid;
}

const parametersToPassForward = 'videoaddebug,advs,bvci,bvid,istop,trybvid,trybvci'.split(',');
Expand Down Expand Up @@ -348,26 +348,15 @@ function buildSyncUrl() {
return syncUrl;
}

function handlePostMessage() {
try {
if (window.addEventListener) {
window.addEventListener('message', acceptPostMessage);
}
} catch (e) { }
}

function acceptPostMessage(e) {
let msg = e.data || {};
if (msg.ivbscd === 1) {
invibes.setCookie(msg.name, msg.value, msg.exdays, msg.domain);
} else if (msg.ivbscd === 2) {
invibes.dom.graduate();
}
}

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;
for (index = 0; index < invibes.purposes; ++index) {
invibes.purposes[index] = true;
}
return 2;
}

Expand All @@ -377,12 +366,21 @@ function readGdprConsent(gdprConsent) {
let properties = Object.keys(purposeConsents);
let purposeConsentsCounter = getPurposeConsentsCounter(gdprConsent.vendorData);

var oneMissing = false;

for (let i = 0; i < purposeConsentsCounter; i++) {
invibes.purposes[i] = !(!purposeConsents[properties[i]] || purposeConsents[properties[i]] === 'false');
if (!purposeConsents[properties[i]] || purposeConsents[properties[i]] === 'false') {
oneMissing = true;
}
}

if (properties.length < purposeConsentsCounter) {
return 0;
}

for (let i = 0; i < purposeConsentsCounter; i++) {
if (!purposeConsents[properties[i]] || purposeConsents[properties[i]] === 'false') { return 0; }
if (oneMissing) {
return 0;
}

let vendorConsents = getVendorConsents(gdprConsent.vendorData);
Expand Down Expand Up @@ -443,7 +441,6 @@ invibes.Uid = {
}
};

let cookieDomain;
invibes.getCookie = function (name) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reading cookies please use the storage manager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change request was implemented please review for merge asap :)

if (!storage.cookiesAreEnabled()) { return; }
let i, x, y;
Expand All @@ -458,116 +455,24 @@ invibes.getCookie = function (name) {
}
};

invibes.setCookie = function (name, value, exdays, domain) {
if (!storage.cookiesAreEnabled()) { return; }
let whiteListed = name == 'ivNoCookie' || name == 'IvbsCampIdsLocal';
if (invibes.noCookies && !whiteListed && (exdays || 0) >= 0) { return; }
if (exdays > 365) { exdays = 365; }
domain = domain || cookieDomain;
let exdate = new Date();
let exms = exdays * 24 * 60 * 60 * 1000;
exdate.setTime(exdate.getTime() + exms);
storage.setCookie(name, value, exdate.toUTCString(), undefined, domain);
};

let detectTopmostCookieDomain = function () {
let testCookie = invibes.Uid.generate();
let hostParts = location.hostname.split('.');
if (hostParts.length === 1) {
return location.hostname;
}
for (let i = hostParts.length - 1; i >= 0; i--) {
let domain = '.' + hostParts.slice(i).join('.');
invibes.setCookie(testCookie, testCookie, 1, domain);
let val = invibes.getCookie(testCookie);
if (val === testCookie) {
invibes.setCookie(testCookie, testCookie, -1, domain);
return domain;
}
}
};

let initDomainId = function (options) {
if (invibes.dom) { return; }

options = options || {};

let cookiePersistence = {
cname: 'ivbsdid',
load: function () {
let str = invibes.getCookie(this.cname) || '';
try {
return JSON.parse(str);
} catch (e) { }
},
save: function (obj) {
invibes.setCookie(this.cname, JSON.stringify(obj), 365);
}
};

let persistence = options.persistence || cookiePersistence;
let state;
let minHC = 2;

let validGradTime = function (state) {
if (!state.cr) { return false; }
let min = 151 * 10e9;
if (state.cr < min) {
return false;
}
let now = new Date().getTime();
let age = now - state.cr;
let minAge = 24 * 60 * 60 * 1000;
return age > minAge;
};

state = persistence.load() || {
id: invibes.Uid.generate(),
cr: new Date().getTime(),
hc: 1,
};

if (state.id.match(/\./)) {
state.id = invibes.Uid.generate();
}
options = options || {};

let graduate = function () {
if (!state.cr) { return; }
delete state.cr;
delete state.hc;
persistence.save(state);
setId();
};
var persistence = options.persistence || cookiePersistence;

let regenerateId = function () {
state.id = invibes.Uid.generate();
persistence.save(state);
};
let state = persistence.load();

let setId = function () {
invibes.dom = {
get id() {
return (!state.cr && invibes.optIn > 0) ? state.id : undefined;
},
get tempId() {
return (invibes.optIn > 0) ? state.id : undefined;
},
graduate: graduate,
regen: regenerateId
};
};

if (state.cr && !options.noVisit) {
if (state.hc < minHC) {
state.hc++;
}
if ((state.hc >= minHC && validGradTime(state)) || options.skipGraduation) {
graduate();
}
}
persistence.save(state);
setId();
ivLogger.info('Did=' + invibes.dom.id);
return state ? (state.id || state.tempId) : undefined;
};

let keywords = (function () {
Expand Down
Loading