Skip to content

Commit

Permalink
Taboola Bid Adapter: fix cookie look up logic and gpp extracting (pre…
Browse files Browse the repository at this point in the history
…bid#11109)

* cookie-look-up-logic-fix-gpp-fix

* pass-version
  • Loading branch information
ahmadlob authored Feb 19, 2024
1 parent aaf2951 commit 67210fa
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 5 deletions.
16 changes: 14 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 Expand Up @@ -258,6 +269,7 @@ function fillTaboolaReqData(bidderRequest, bidRequest, data) {
data.user = user;
data.regs = regs;
deepSetValue(data, 'ext.pageType', ortb2?.ext?.data?.pageType || ortb2?.ext?.data?.section || bidRequest.params.pageType);
deepSetValue(data, 'ext.prebid.version', '$prebid.version$');
}

function fillTaboolaImpData(bid, imp) {
Expand Down
101 changes: 98 additions & 3 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 @@ -214,7 +218,11 @@ describe('Taboola Adapter', function () {
'ext': {},
},
'regs': {'coppa': 0, 'ext': {}},
'ext': {}
'ext': {
'prebid': {
'version': '$prebid.version$'
}
}
};

expect(res.url).to.equal(`${END_POINT_URL}?publisher=${commonBidRequest.params.publisherId}`);
Expand Down Expand Up @@ -471,6 +479,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 +984,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

0 comments on commit 67210fa

Please sign in to comment.