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

cookie-look-up-logic-fix-gpp-fix #32

Merged
merged 1 commit into from
Feb 18, 2024
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
15 changes: 13 additions & 2 deletions modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const USER_ID = 'user-id';
const STORAGE_KEY = `taboola global:${USER_ID}`;
const COOKIE_KEY = 'trc_cookie_storage';
const TGID_COOKIE_KEY = 't_gid';
const TGID_PT_COOKIE_KEY = 't_pt_gid';
const TBLA_ID_COOKIE_KEY = 'tbla_id';
export const EVENT_ENDPOINT = 'https://beacon.bidder.taboola.com';

Expand All @@ -43,21 +44,31 @@ export const userData = {
const {cookiesAreEnabled, getCookie} = userData.storageManager;
if (cookiesAreEnabled()) {
const cookieData = getCookie(COOKIE_KEY);
let userId = userData.getCookieDataByKey(cookieData, USER_ID);
let userId;
if (cookieData) {
userId = userData.getCookieDataByKey(cookieData, USER_ID);
}
if (userId) {
return userId;
}
userId = getCookie(TGID_COOKIE_KEY);
if (userId) {
return userId;
}
userId = getCookie(TGID_PT_COOKIE_KEY);
if (userId) {
return userId;
}
const tblaId = getCookie(TBLA_ID_COOKIE_KEY);
if (tblaId) {
return tblaId;
}
}
},
getCookieDataByKey(cookieData, key) {
if (!cookieData) {
return undefined;
}
const [, value = ''] = cookieData.split(`${key}=`)
return value;
},
Expand Down Expand Up @@ -166,7 +177,7 @@ export const spec = {
}

if (gppConsent) {
queryParams.push('gpp=' + encodeURIComponent(gppConsent));
queryParams.push('gpp=' + encodeURIComponent(gppConsent.gppString || '') + '&gpp_sid=' + encodeURIComponent((gppConsent.applicableSections || []).join(',')));
}

if (syncOptions.iframeEnabled) {
Expand Down
95 changes: 93 additions & 2 deletions test/spec/modules/taboolaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {server} from '../../mocks/xhr'

describe('Taboola Adapter', function () {
let sandbox, hasLocalStorage, cookiesAreEnabled, getDataFromLocalStorage, localStorageIsEnabled, getCookie, commonBidRequest;
const COOKIE_KEY = 'trc_cookie_storage';
const TGID_COOKIE_KEY = 't_gid';
const TGID_PT_COOKIE_KEY = 't_pt_gid';
const TBLA_ID_COOKIE_KEY = 'tbla_id';

beforeEach(() => {
sandbox = sinon.sandbox.create();
Expand Down Expand Up @@ -471,6 +475,90 @@ describe('Taboola Adapter', function () {
expect(res.data.user.buyeruid).to.equal('12121212');
});

it('should get user id from cookie if local storage isn`t defined, only TGID_COOKIE_KEY exists', function () {
getDataFromLocalStorage.returns(51525152);
hasLocalStorage.returns(false);
localStorageIsEnabled.returns(false);
cookiesAreEnabled.returns(true);
getCookie.callsFake(function (cookieKey) {
if (cookieKey === COOKIE_KEY) {
return 'should:not:return:this';
}
if (cookieKey === TGID_COOKIE_KEY) {
return 'user:12121212';
}
return undefined;
});
const bidderRequest = {
...commonBidderRequest
};
const res = spec.buildRequests([defaultBidRequest], bidderRequest);
expect(res.data.user.buyeruid).to.equal('user:12121212');
});

it('should get user id from cookie if local storage isn`t defined, only TGID_PT_COOKIE_KEY exists', function () {
getDataFromLocalStorage.returns(51525152);
hasLocalStorage.returns(false);
localStorageIsEnabled.returns(false);
cookiesAreEnabled.returns(true);
getCookie.callsFake(function (cookieKey) {
if (cookieKey === TGID_PT_COOKIE_KEY) {
return 'user:12121212';
}
return undefined;
});
const bidderRequest = {
...commonBidderRequest
};
const res = spec.buildRequests([defaultBidRequest], bidderRequest);
expect(res.data.user.buyeruid).to.equal('user:12121212');
});

it('should get user id from cookie if local storage isn`t defined, only TBLA_ID_COOKIE_KEY exists', function () {
getDataFromLocalStorage.returns(51525152);
hasLocalStorage.returns(false);
localStorageIsEnabled.returns(false);
cookiesAreEnabled.returns(true);
getCookie.callsFake(function (cookieKey) {
if (cookieKey === TBLA_ID_COOKIE_KEY) {
return 'user:tbla:12121212';
}
return undefined;
});
const bidderRequest = {
...commonBidderRequest
};
const res = spec.buildRequests([defaultBidRequest], bidderRequest);
expect(res.data.user.buyeruid).to.equal('user:tbla:12121212');
});

it('should get user id from cookie if local storage isn`t defined, all cookie keys exist', function () {
getDataFromLocalStorage.returns(51525152);
hasLocalStorage.returns(false);
localStorageIsEnabled.returns(false);
cookiesAreEnabled.returns(true);
getCookie.callsFake(function (cookieKey) {
if (cookieKey === COOKIE_KEY) {
return 'taboola%20global%3Auser-id=cookie:1';
}
if (cookieKey === TGID_COOKIE_KEY) {
return 'cookie:2';
}
if (cookieKey === TGID_PT_COOKIE_KEY) {
return 'cookie:3';
}
if (cookieKey === TBLA_ID_COOKIE_KEY) {
return 'cookie:4';
}
return undefined;
});
const bidderRequest = {
...commonBidderRequest
};
const res = spec.buildRequests([defaultBidRequest], bidderRequest);
expect(res.data.user.buyeruid).to.equal('cookie:1');
});

it('should get user id from tgid cookie if local storage isn`t defined', function () {
getDataFromLocalStorage.returns(51525152);
hasLocalStorage.returns(false);
Expand Down Expand Up @@ -892,8 +980,11 @@ describe('Taboola Adapter', function () {
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, 'USP_CONSENT')).to.deep.equal([{
type: 'image', url: `${usersyncUrl}?us_privacy=USP_CONSENT`
}]);
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, 'USP_CONSENT', 'GPP_STRING')).to.deep.equal([{
type: 'image', url: `${usersyncUrl}?us_privacy=USP_CONSENT&gpp=GPP_STRING`
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, 'USP_CONSENT', {gppString: 'GPP_STRING', applicableSections: []})).to.deep.equal([{
type: 'image', url: `${usersyncUrl}?us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=`
}]);
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, 'USP_CONSENT', {gppString: 'GPP_STRING', applicableSections: [32, 51]})).to.deep.equal([{
type: 'image', url: `${usersyncUrl}?us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=32%2C51`
}]);
});
})
Expand Down