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

[CriteoId] Add local storage check and migrate cookie check to use StorageManager API #5953

Merged
merged 2 commits into from
Nov 16, 2020
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
17 changes: 6 additions & 11 deletions modules/criteoIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@ export const storage = getStorageManager(gvlid, bidderCode);

const bididStorageKey = 'cto_bidid';
const bundleStorageKey = 'cto_bundle';
const cookieWriteableKey = 'cto_test_cookie';
const cookiesMaxAge = 13 * 30 * 24 * 60 * 60 * 1000;

const pastDateString = new Date(0).toString();
const expirationString = new Date(utils.timestamp() + cookiesMaxAge).toString();

function areCookiesWriteable() {
storage.setCookie(cookieWriteableKey, '1');
const canWrite = storage.getCookie(cookieWriteableKey) === '1';
storage.setCookie(cookieWriteableKey, '', pastDateString);
return canWrite;
}

function extractProtocolHost (url, returnOnlyHost = false) {
const parsedUrl = utils.parseUrl(url, {noDecodeWholeURL: true})
return returnOnlyHost
Expand Down Expand Up @@ -60,20 +52,22 @@ function getCriteoDataFromAllStorages() {
}
}

function buildCriteoUsersyncUrl(topUrl, domain, bundle, areCookiesWriteable, isPublishertagPresent, gdprString) {
function buildCriteoUsersyncUrl(topUrl, domain, bundle, areCookiesWriteable, isLocalStorageWritable, isPublishertagPresent, gdprString) {
const url = 'https://gum.criteo.com/sid/json?origin=prebid' +
`${topUrl ? '&topUrl=' + encodeURIComponent(topUrl) : ''}` +
`${domain ? '&domain=' + encodeURIComponent(domain) : ''}` +
`${bundle ? '&bundle=' + encodeURIComponent(bundle) : ''}` +
`${gdprString ? '&gdprString=' + encodeURIComponent(gdprString) : ''}` +
`${areCookiesWriteable ? '&cw=1' : ''}` +
`${isPublishertagPresent ? '&pbt=1' : ''}`
`${isPublishertagPresent ? '&pbt=1' : ''}` +
`${isLocalStorageWritable ? '&lsw=1' : ''}`;

return url;
}

function callCriteoUserSync(parsedCriteoData, gdprString) {
const cw = areCookiesWriteable();
const cw = storage.cookiesAreEnabled();
const lsw = storage.localStorageIsEnabled();
const topUrl = extractProtocolHost(getRefererInfo().referer);
const domain = extractProtocolHost(document.location.href, true);
const isPublishertagPresent = typeof criteo_pubtag !== 'undefined'; // eslint-disable-line camelcase
Expand All @@ -83,6 +77,7 @@ function callCriteoUserSync(parsedCriteoData, gdprString) {
domain,
parsedCriteoData.bundle,
cw,
lsw,
isPublishertagPresent,
gdprString
);
Expand Down
3 changes: 1 addition & 2 deletions test/spec/modules/criteoIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ describe('CriteoId module', function () {
});

it('should call user sync url with the right params', function () {
getCookieStub.withArgs('cto_test_cookie').returns('1');
getCookieStub.withArgs('cto_bundle').returns('bundle');
window.criteo_pubtag = {}

Expand All @@ -80,7 +79,7 @@ describe('CriteoId module', function () {
ajaxBuilderStub.callsFake(mockResponse(undefined, ajaxStub))

criteoIdSubmodule.getId();
const expectedUrl = `https://gum.criteo.com/sid/json?origin=prebid&topUrl=https%3A%2F%2Ftestdev.com%2F&domain=testdev.com&bundle=bundle&cw=1&pbt=1`;
const expectedUrl = `https://gum.criteo.com/sid/json?origin=prebid&topUrl=https%3A%2F%2Ftestdev.com%2F&domain=testdev.com&bundle=bundle&cw=1&pbt=1&lsw=1`;

expect(ajaxStub.calledWith(expectedUrl)).to.be.true;

Expand Down