From cde525fed010f3f066d00c4f3f3bcf81208a8ef9 Mon Sep 17 00:00:00 2001 From: Robson Viana Date: Fri, 21 Apr 2023 15:07:47 -0400 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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 } });