From cde525fed010f3f066d00c4f3f3bcf81208a8ef9 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 15:07:47 -0400 Subject: [PATCH 01/13] User sync fixes. --- modules/insticatorBidAdapter.js | 81 ++++++++++++++----- .../spec/modules/insticatorBidAdapter_spec.js | 2 - 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index 3853414c1a2..c3ed17f8644 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -8,7 +8,7 @@ import {find} from '../src/polyfill.js'; const BIDDER_CODE = 'insticator'; const ENDPOINT = 'https://ex.ingage.tech/v1/openrtb'; // production endpoint const USER_ID_KEY = 'hb_insticator_uid'; -const USER_ID_COOKIE_EXP = 2592000000; // 30 days +const USER_ID_COOKIE_EXP = 7776000000; // 90 days const BID_TTL = 300; // 5 minutes const GVLID = 910; @@ -22,30 +22,74 @@ config.setDefaults({ }); function getUserId() { - let uid; + let uid = storage.getCookie(USER_ID_KEY); + if (uid && isUserIdValid(uid)) { + const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); + storage.setCookie(USER_ID_KEY, uid, expireIn); + return uid; + } + + uid = localStorage.getItem(USER_ID_KEY); + if (uid && isUserIdValid(uid)) { + return uid; + } + + return generateUserId() +} + +function isUserIdValid(uid) { + return uid && uid.length === 36; +} + +function generateUserId() { + const uid = generateUUID(); - if (storage.localStorageIsEnabled()) { - uid = localStorage.getItem(USER_ID_KEY); - } else { - uid = storage.getCookie(USER_ID_KEY); + if (isCookieEnabled()) { + const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); + storage.setCookie(USER_ID_KEY, uid, expireIn); + return uid; } - if (uid && uid.length !== 36) { - uid = undefined; + if (isLocalStoreEnabled()) { + localStorage.setItem(USER_ID_KEY, uid); } return uid; } -function setUserId(userId) { - if (storage.localStorageIsEnabled()) { - localStorage.setItem(USER_ID_KEY, userId); +function isLocalStoreEnabled() { + let enabled = false; + + try { + localStorage.setItem('prebid.localStoreTest', 'true'); + enabled = Boolean(localStorage.getItem('prebid.localStoreTest')); + } catch (err) { + return false + } finally { + if (enabled) { + localStorage.removeItem('insticator.prebid.localStoreTest'); + } } - if (storage.cookiesAreEnabled()) { - const expires = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); - storage.setCookie(USER_ID_KEY, userId, expires); + return enabled; +} + +function isCookieEnabled() { + let enabled = false; + + try { + const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); + storage.setCookie('insticator.prebid.cookieTest', 'true', expireIn); + enabled = Boolean(storage.getCookie('insticator.prebid.cookieTest')); + } catch (err) { + return false; + } finally { + if (enabled) { + storage.setCookie('insticator.prebid.cookieTest', 'true', new Date(Date.now()).toUTCString()); + } } + + return enabled; } function buildImpression(bidRequest) { @@ -95,10 +139,7 @@ function buildDevice() { w: window.innerWidth, h: window.innerHeight, js: true, - ext: { - localStorage: storage.localStorageIsEnabled(), - cookies: storage.cookiesAreEnabled(), - }, + ext: {}, }; if (typeof deviceConfig === 'object') { @@ -122,12 +163,10 @@ function buildRegs(bidderRequest) { } function buildUser(bid) { - const userId = getUserId() || generateUUID(); + const userId = getUserId(); const yob = deepAccess(bid, 'params.user.yob') const gender = deepAccess(bid, 'params.user.gender') - setUserId(userId); - return { id: userId, yob, diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index fc7ed1833ac..bebf25dbcd1 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -270,8 +270,6 @@ describe('InsticatorBidAdapter', function () { expect(data.device.h).to.equal(window.innerHeight); expect(data.device.js).to.equal(true); expect(data.device.ext).to.be.an('object'); - expect(data.device.ext.localStorage).to.equal(true); - expect(data.device.ext.cookies).to.equal(false); expect(data.regs).to.be.an('object'); expect(data.regs.ext.gdpr).to.equal(1); expect(data.regs.ext.gdprConsentString).to.equal(bidderRequest.gdprConsent.consentString); From 24a920379483d23a1db95d97b9d5701728ada3ce Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 15:52:07 -0400 Subject: [PATCH 02/13] Update insticatorBidAdapter.js --- modules/insticatorBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index c3ed17f8644..8423c126a02 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -168,7 +168,7 @@ function buildUser(bid) { const gender = deepAccess(bid, 'params.user.gender') return { - id: userId, + buyeruid: userId, yob, gender, }; From ae1397aa19409889547d2fa778bc62fbe9f75a34 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 16:00:02 -0400 Subject: [PATCH 03/13] Update insticatorBidAdapter_spec.js --- test/spec/modules/insticatorBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index bebf25dbcd1..09952f833f8 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); const data = JSON.parse(requests[0].data); - expect(data.user.id).to.equal(USER_ID_STUBBED); + expect(data.user.buyeruid).to.equal(USER_ID_STUBBED); }); it('should return empty regs object if no gdprConsent is passed', function () { const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); From 314b522cc850c04d743ac1136580b05f0c6f2db5 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 16:11:27 -0400 Subject: [PATCH 04/13] Revert "Update insticatorBidAdapter_spec.js" This reverts commit ae1397aa19409889547d2fa778bc62fbe9f75a34. --- test/spec/modules/insticatorBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index 09952f833f8..bebf25dbcd1 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); const data = JSON.parse(requests[0].data); - expect(data.user.buyeruid).to.equal(USER_ID_STUBBED); + expect(data.user.id).to.equal(USER_ID_STUBBED); }); it('should return empty regs object if no gdprConsent is passed', function () { const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); From 0ae7bbf722e5440ce31d94b3be48d3bd9afbc45c Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 16:11:30 -0400 Subject: [PATCH 05/13] Revert "User sync fixes for 7 25 0 (#59)" This reverts commit 2ea50ac35e9b0a6600bb9023bc43cf6e879e772e. --- modules/insticatorBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index 8423c126a02..c3ed17f8644 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -168,7 +168,7 @@ function buildUser(bid) { const gender = deepAccess(bid, 'params.user.gender') return { - buyeruid: userId, + id: userId, yob, gender, }; From 4d13615eff7cfd245271e0656a410de3eb7f242c Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 16:14:33 -0400 Subject: [PATCH 06/13] Update insticatorBidAdapter_spec.js --- test/spec/modules/insticatorBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index bebf25dbcd1..93301aed56f 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); const data = JSON.parse(requests[0].data); - expect(data.user.id).to.equal(USER_ID_STUBBED); + expect(data.user.id).to.equal(USER_ID_STUBBED); }); it('should return empty regs object if no gdprConsent is passed', function () { const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); From abc10a9a2db8da436f3ce6b5466c15e9a2a02947 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 16:14:50 -0400 Subject: [PATCH 07/13] Update insticatorBidAdapter_spec.js --- test/spec/modules/insticatorBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index 93301aed56f..bebf25dbcd1 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); const data = JSON.parse(requests[0].data); - expect(data.user.id).to.equal(USER_ID_STUBBED); + expect(data.user.id).to.equal(USER_ID_STUBBED); }); it('should return empty regs object if no gdprConsent is passed', function () { const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); From f77693d5fcaf153ac62c12919c0d4d16c8bc0130 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Mon, 24 Apr 2023 14:31:03 -0400 Subject: [PATCH 08/13] User sync fixes. prioritize local store over cookie to store the user ID, so that the same value can be shared among tabs. --- modules/insticatorBidAdapter.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index c3ed17f8644..0857fefac68 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -22,15 +22,15 @@ config.setDefaults({ }); function getUserId() { - let uid = storage.getCookie(USER_ID_KEY); + uid = localStorage.getItem(USER_ID_KEY); if (uid && isUserIdValid(uid)) { - const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); - storage.setCookie(USER_ID_KEY, uid, expireIn); return uid; } - uid = localStorage.getItem(USER_ID_KEY); + let uid = storage.getCookie(USER_ID_KEY); if (uid && isUserIdValid(uid)) { + const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); + storage.setCookie(USER_ID_KEY, uid, expireIn); return uid; } @@ -44,14 +44,14 @@ function isUserIdValid(uid) { function generateUserId() { const uid = generateUUID(); - if (isCookieEnabled()) { - const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); - storage.setCookie(USER_ID_KEY, uid, expireIn); + if (isLocalStoreEnabled()) { + localStorage.setItem(USER_ID_KEY, uid); return uid; } - if (isLocalStoreEnabled()) { - localStorage.setItem(USER_ID_KEY, uid); + if (isCookieEnabled()) { + const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); + storage.setCookie(USER_ID_KEY, uid, expireIn); } return uid; From 9e0e12ff3374a581f82c1ede71cab005f25bcf37 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Mon, 24 Apr 2023 14:32:22 -0400 Subject: [PATCH 09/13] Update insticatorBidAdapter.js --- modules/insticatorBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index 0857fefac68..8688a85be10 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -22,12 +22,12 @@ config.setDefaults({ }); function getUserId() { - uid = localStorage.getItem(USER_ID_KEY); + let uid = localStorage.getItem(USER_ID_KEY); if (uid && isUserIdValid(uid)) { return uid; } - let uid = storage.getCookie(USER_ID_KEY); + uid = storage.getCookie(USER_ID_KEY); if (uid && isUserIdValid(uid)) { const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); storage.setCookie(USER_ID_KEY, uid, expireIn); From 45a565c78e3a95dba232e6ed7c0d006327503b43 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Mon, 1 May 2023 23:20:17 -0400 Subject: [PATCH 10/13] Update insticatorBidAdapter.js --- modules/insticatorBidAdapter.js | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index 8688a85be10..969598eda40 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -7,7 +7,7 @@ import {find} from '../src/polyfill.js'; const BIDDER_CODE = 'insticator'; const ENDPOINT = 'https://ex.ingage.tech/v1/openrtb'; // production endpoint -const USER_ID_KEY = 'hb_insticator_uid'; +const USER_ID_KEY = 'instUid'; const USER_ID_COOKIE_EXP = 7776000000; // 90 days const BID_TTL = 300; // 5 minutes const GVLID = 910; @@ -22,12 +22,7 @@ config.setDefaults({ }); function getUserId() { - let uid = localStorage.getItem(USER_ID_KEY); - if (uid && isUserIdValid(uid)) { - return uid; - } - - uid = storage.getCookie(USER_ID_KEY); + let uid = storage.getCookie(USER_ID_KEY); if (uid && isUserIdValid(uid)) { const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); storage.setCookie(USER_ID_KEY, uid, expireIn); @@ -44,11 +39,6 @@ function isUserIdValid(uid) { function generateUserId() { const uid = generateUUID(); - if (isLocalStoreEnabled()) { - localStorage.setItem(USER_ID_KEY, uid); - return uid; - } - if (isCookieEnabled()) { const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); storage.setCookie(USER_ID_KEY, uid, expireIn); @@ -57,23 +47,6 @@ function generateUserId() { return uid; } -function isLocalStoreEnabled() { - let enabled = false; - - try { - localStorage.setItem('prebid.localStoreTest', 'true'); - enabled = Boolean(localStorage.getItem('prebid.localStoreTest')); - } catch (err) { - return false - } finally { - if (enabled) { - localStorage.removeItem('insticator.prebid.localStoreTest'); - } - } - - return enabled; -} - function isCookieEnabled() { let enabled = false; From 3d9fa09867cbe0ece2ebc992ac07e1701f379508 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Tue, 2 May 2023 13:34:53 -0400 Subject: [PATCH 11/13] Adding domain in the cookie. --- modules/insticatorBidAdapter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index 969598eda40..c3aab52de56 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -25,7 +25,8 @@ function getUserId() { let uid = storage.getCookie(USER_ID_KEY); if (uid && isUserIdValid(uid)) { const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); - storage.setCookie(USER_ID_KEY, uid, expireIn); + const domain = window.location.hostname.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/mg); + storage.setCookie(USER_ID_KEY, uid, expireIn, 'none', `.${domain}`); return uid; } @@ -41,7 +42,8 @@ function generateUserId() { if (isCookieEnabled()) { const expireIn = new Date(Date.now() + USER_ID_COOKIE_EXP).toUTCString(); - storage.setCookie(USER_ID_KEY, uid, expireIn); + const domain = window.location.hostname.match(/[^.]*\.[^.]{2,3}(?:\.[^.]{2,3})?$/mg); + storage.setCookie(USER_ID_KEY, uid, expireIn, 'none', `.${domain}`); } return uid; From c874721616a14d6203fcf5be9eb92e1ad4b67c4a Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Tue, 2 May 2023 14:41:17 -0400 Subject: [PATCH 12/13] Fixing unit test. --- test/spec/modules/insticatorBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js index 09952f833f8..bebf25dbcd1 100644 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ b/test/spec/modules/insticatorBidAdapter_spec.js @@ -335,7 +335,7 @@ describe('InsticatorBidAdapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); const data = JSON.parse(requests[0].data); - expect(data.user.buyeruid).to.equal(USER_ID_STUBBED); + expect(data.user.id).to.equal(USER_ID_STUBBED); }); it('should return empty regs object if no gdprConsent is passed', function () { const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); From 10d59164013d828066fbfffa939a4d68a7b24db2 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Tue, 2 May 2023 14:47:17 -0400 Subject: [PATCH 13/13] Adding logic for localhost. --- modules/insticatorBidAdapter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/insticatorBidAdapter.js b/modules/insticatorBidAdapter.js index ac1b493722a..f953af7365d 100644 --- a/modules/insticatorBidAdapter.js +++ b/modules/insticatorBidAdapter.js @@ -296,7 +296,10 @@ export const spec = { buildRequests: function (validBidRequests, bidderRequest) { const requests = []; let endpointUrl = config.getConfig('insticator.endpointUrl') || ENDPOINT; - endpointUrl = endpointUrl.replace(/^http:/, 'https:'); + + if (endpointUrl.indexOf('localhost') === -1) { + endpointUrl = endpointUrl.replace(/^http:/, 'https:'); + } if (validBidRequests.length > 0) { requests.push({