From af9213efb5597262081729000efd5ae738d274af Mon Sep 17 00:00:00 2001 From: Ahmad Lobany Date: Sun, 18 Feb 2024 16:43:00 +0200 Subject: [PATCH 1/3] cookie-look-up-logic-fix-gpp-fix --- modules/taboolaBidAdapter.js | 15 +++- test/spec/modules/taboolaBidAdapter_spec.js | 95 ++++++++++++++++++++- 2 files changed, 106 insertions(+), 4 deletions(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index 3b83514b6fd..748cde7a9c9 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -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'; @@ -43,7 +44,10 @@ 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; } @@ -51,6 +55,10 @@ export const userData = { 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; @@ -58,6 +66,9 @@ export const userData = { } }, getCookieDataByKey(cookieData, key) { + if (!cookieData) { + return undefined; + } const [, value = ''] = cookieData.split(`${key}=`) return value; }, @@ -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) { diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index dd91c410d08..a1b754097c3 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -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(); @@ -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); @@ -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` }]); }); }) From 5a3e3ac952c5818b8af6f52c50f9017de9ee049e Mon Sep 17 00:00:00 2001 From: "aleksander.l" Date: Thu, 22 Feb 2024 18:00:33 +0200 Subject: [PATCH 2/3] Append support for topics in taboolaPrebidAdapter --- modules/taboolaBidAdapter.js | 3 +++ modules/topicsFpdModule.js | 3 +++ modules/topicsFpdModule.md | 6 +++++- test/spec/modules/taboolaBidAdapter_spec.js | 22 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index 748cde7a9c9..e4af7c6ce8a 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -229,6 +229,9 @@ function fillTaboolaReqData(bidderRequest, bidRequest, data) { buyeruid: userData.getUserId(gdprConsent, uspConsent), ext: {} }; + if (bidderRequest && bidderRequest.ortb2 && bidderRequest.ortb2.user) { + user.data = bidderRequest.ortb2.user.data; + } const regs = { coppa: 0, ext: {} diff --git a/modules/topicsFpdModule.js b/modules/topicsFpdModule.js index b5a90dacfb4..748242142c4 100644 --- a/modules/topicsFpdModule.js +++ b/modules/topicsFpdModule.js @@ -38,6 +38,9 @@ const bidderIframeList = { }, { bidder: 'onetag', iframeURL: 'https://onetag-sys.com/static/topicsapi.html' + }, { + bidder: 'taboola', + iframeURL: 'https://cdn.taboola.com/libtrc/static/topics/taboola-prebid-browsing-topics.html' }] } diff --git a/modules/topicsFpdModule.md b/modules/topicsFpdModule.md index 89eb03fb6df..e8daded4439 100644 --- a/modules/topicsFpdModule.md +++ b/modules/topicsFpdModule.md @@ -56,6 +56,10 @@ pbjs.setConfig({ bidder: 'onetag', iframeURL: 'https://onetag-sys.com/static/topicsapi.html', expiry: 7 // Configurable expiry days + }, { + bidder: 'taboola', + iframeURL: 'https://cdn.taboola.com/libtrc/static/topics/taboola-prebid-browsing-topics.html', + expiry: 7 // Configurable expiry days }] } .... @@ -71,4 +75,4 @@ pbjs.setConfig({ | topics.bidders | no | Array of objects | Array of topics callers with the iframe locations and other necessary informations like bidder(Bidder code) and expiry. Default Array of topics in the module itself.| | topics.bidders[].bidder | yes | string | Bidder Code of the bidder(SSP). | | topics.bidders[].iframeURL | yes | string | URL which is hosted on bidder/SSP/third-party domains which will call Topics API. | -| topics.bidders[].expiry | no | integer | Max number of days where Topics data will be persist. If Data is stored for more than mentioned expiry day, it will be deleted from storage. Default is 21 days which is hardcoded in Module. | \ No newline at end of file +| topics.bidders[].expiry | no | integer | Max number of days where Topics data will be persist. If Data is stored for more than mentioned expiry day, it will be deleted from storage. Default is 21 days which is hardcoded in Module. | diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index a1b754097c3..b2a4a66a975 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -394,6 +394,28 @@ describe('Taboola Adapter', function () { const res = spec.buildRequests([defaultBidRequest], bidderRequest); expect(res.data.ext.example).to.deep.equal(bidderRequest.ortb2.ext.example); }); + + it('should pass additional parameter in request for topics', function () { + const ortb2 = { + user: { + data: { + segment: [ + { + id: '243' + } + ], + name: 'pa.taboola.com', + ext: { + segclass: '4', + segtax: 601 + } + } + } + } + + const res = spec.buildRequests([defaultBidRequest], {...commonBidderRequest, ortb2}) + expect(res.user.data).to.deep.equal(ortb2.user.data); + }); }); describe('handle privacy segments when building request', function () { From 0aef6db8a5c5c448e5b8b8280edc0d58bb1df804 Mon Sep 17 00:00:00 2001 From: "aleksander.l" Date: Sun, 25 Feb 2024 09:54:33 +0200 Subject: [PATCH 3/3] test fix --- modules/taboolaBidAdapter.js | 2 +- test/spec/modules/taboolaBidAdapter_spec.js | 28 +++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index e4af7c6ce8a..df7fd0734b3 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -225,7 +225,7 @@ function fillTaboolaReqData(bidderRequest, bidRequest, data) { const {refererInfo, gdprConsent = {}, uspConsent} = bidderRequest; const site = getSiteProperties(bidRequest.params, refererInfo, bidderRequest.ortb2); const device = {ua: navigator.userAgent}; - const user = { + let user = { buyeruid: userData.getUserId(gdprConsent, uspConsent), ext: {} }; diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index b2a4a66a975..971b9530752 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -397,24 +397,26 @@ describe('Taboola Adapter', function () { it('should pass additional parameter in request for topics', function () { const ortb2 = { - user: { - data: { - segment: [ - { - id: '243' + ...commonBidderRequest, + ortb2: { + user: { + data: { + segment: [ + { + id: '243' + } + ], + name: 'pa.taboola.com', + ext: { + segclass: '4', + segtax: 601 } - ], - name: 'pa.taboola.com', - ext: { - segclass: '4', - segtax: 601 } } } } - - const res = spec.buildRequests([defaultBidRequest], {...commonBidderRequest, ortb2}) - expect(res.user.data).to.deep.equal(ortb2.user.data); + const res = spec.buildRequests([defaultBidRequest], {...ortb2}) + expect(res.data.user.data).to.deep.equal(ortb2.ortb2.user.data); }); });