From 4cff78649f9d206ff0fd6ec260683bc5757f8c9b Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Thu, 3 Oct 2024 16:59:36 +0300 Subject: [PATCH 01/21] added event listener in cnx bid adapter --- integrationExamples/cnx/index.html | 239 ++++++++++++++++++ modules/connatixBidAdapter.js | 47 +++- .../modules/ads_interactiveBidAdapter_spec.js | 1 + 3 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 integrationExamples/cnx/index.html diff --git a/integrationExamples/cnx/index.html b/integrationExamples/cnx/index.html new file mode 100644 index 00000000000..bb44f186895 --- /dev/null +++ b/integrationExamples/cnx/index.html @@ -0,0 +1,239 @@ + + + + Prebid.js Integration Example + + + + + +

Prebid.js Integration Example

+ +
+
+
+ + diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 6e453e2caa7..ec1c7cc32db 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -6,7 +6,7 @@ import { import { percentInView } from '../libraries/percentInView/percentInView.js'; import { config } from '../src/config.js'; - +import { getStorageManager } from '../src/storageManager.js'; import { ajax } from '../src/ajax.js'; import { deepAccess, @@ -31,6 +31,9 @@ const BIDDER_CODE = 'connatix'; const AD_URL = 'https://capi.connatix.com/rtb/hba'; const DEFAULT_MAX_TTL = '3600'; const DEFAULT_CURRENCY = 'USD'; +const CNX_IDS = 'cnx_ids'; +const CNX_ID_RETENTION_TIME_HOUR = 24 * 30; // 30 days +export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -182,6 +185,29 @@ function _handleEids(payload, validBidRequests) { } } +function saveOnAllStorages(name, value, expirationTimeHours) { + const date = new Date(); + date.setTime(date.getTime() + (expirationTimeHours * 60 * 60 * 1000)); + const expires = `expires=${date.toUTCString()}`; + // eslint-disable-next-line no-console + console.log('TEST: save on all storages:', name, ' AND', value); + storage.setCookie(name, value, expires); + storage.setDataInLocalStorage(name, value); + const fromCookie = storage.getCookie(name); + const fromLocalStorage = storage.getDataFromLocalStorage(name); + // eslint-disable-next-line no-console + console.log('TEST: SAVE ABD READ on all storages:', fromCookie, ' AND', fromLocalStorage); +} + +function readFromAllStorages(name) { + const fromCookie = storage.getCookie(name); + const fromLocalStorage = storage.getDataFromLocalStorage(name); + // eslint-disable-next-line no-console + console.log('TEST read from all storages: ', fromCookie, fromLocalStorage) + + return fromCookie || fromLocalStorage || undefined; +} + export const spec = { code: BIDDER_CODE, gvlid: 143, @@ -225,6 +251,7 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); + const cnxIds = readFromAllStorages(CNX_IDS); const requestPayload = { ortb2: bidderRequest.ortb2, @@ -232,6 +259,7 @@ export const spec = { uspConsent: bidderRequest.uspConsent, gppConsent: bidderRequest.gppConsent, refererInfo: bidderRequest.refererInfo, + userIds: cnxIds, bidRequests, }; @@ -308,6 +336,23 @@ export const spec = { params['us_privacy'] = encodeURIComponent(uspConsent); } + window.addEventListener('message', function handler(event) { + // eslint-disable-next-line no-console + console.log('TEST: event:', event); + if (!event.data || !event.origin.includes('connatix')) { + return; + } + + this.removeEventListener('message', handler); + + event.stopImmediatePropagation(); + + const response = event.data; + if (!response.optout && response.type) { + saveOnAllStorages(CNX_IDS, response.type, CNX_ID_RETENTION_TIME_HOUR); + } + }, true) + const syncUrl = serverResponses[0].body.UserSyncEndpoint; const queryParams = Object.keys(params).length > 0 ? formatQS(params) : ''; diff --git a/test/spec/modules/ads_interactiveBidAdapter_spec.js b/test/spec/modules/ads_interactiveBidAdapter_spec.js index 93fd94a0f2d..f33e24fd25d 100644 --- a/test/spec/modules/ads_interactiveBidAdapter_spec.js +++ b/test/spec/modules/ads_interactiveBidAdapter_spec.js @@ -137,6 +137,7 @@ describe('AdsInteractiveBidAdapter', function () { expect(data).to.have.all.keys( 'deviceWidth', 'deviceHeight', + 'device', 'language', 'secure', 'host', From 26f652708e7a77b0e689d88fe78cb2c32400d219 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Fri, 4 Oct 2024 13:57:51 +0300 Subject: [PATCH 02/21] deleted console logs and added cache variable --- modules/connatixBidAdapter.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index ec1c7cc32db..80eb43dd258 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -34,6 +34,7 @@ const DEFAULT_CURRENCY = 'USD'; const CNX_IDS = 'cnx_ids'; const CNX_ID_RETENTION_TIME_HOUR = 24 * 30; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); +const CNX_IDS_VALUES = []; const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -189,21 +190,14 @@ function saveOnAllStorages(name, value, expirationTimeHours) { const date = new Date(); date.setTime(date.getTime() + (expirationTimeHours * 60 * 60 * 1000)); const expires = `expires=${date.toUTCString()}`; - // eslint-disable-next-line no-console - console.log('TEST: save on all storages:', name, ' AND', value); storage.setCookie(name, value, expires); storage.setDataInLocalStorage(name, value); - const fromCookie = storage.getCookie(name); - const fromLocalStorage = storage.getDataFromLocalStorage(name); - // eslint-disable-next-line no-console - console.log('TEST: SAVE ABD READ on all storages:', fromCookie, ' AND', fromLocalStorage); + CNX_IDS_VALUES.push(value); } function readFromAllStorages(name) { const fromCookie = storage.getCookie(name); const fromLocalStorage = storage.getDataFromLocalStorage(name); - // eslint-disable-next-line no-console - console.log('TEST read from all storages: ', fromCookie, fromLocalStorage) return fromCookie || fromLocalStorage || undefined; } @@ -251,7 +245,7 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); - const cnxIds = readFromAllStorages(CNX_IDS); + const cnxIds = [readFromAllStorages(CNX_IDS)] || CNX_IDS_VALUES; const requestPayload = { ortb2: bidderRequest.ortb2, @@ -337,8 +331,6 @@ export const spec = { } window.addEventListener('message', function handler(event) { - // eslint-disable-next-line no-console - console.log('TEST: event:', event); if (!event.data || !event.origin.includes('connatix')) { return; } From eb147d84174f8c1862182b654e7d769b9851c935 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Fri, 4 Oct 2024 15:08:07 +0300 Subject: [PATCH 03/21] deleted test file --- integrationExamples/cnx/index.html | 239 ----------------------------- 1 file changed, 239 deletions(-) delete mode 100644 integrationExamples/cnx/index.html diff --git a/integrationExamples/cnx/index.html b/integrationExamples/cnx/index.html deleted file mode 100644 index bb44f186895..00000000000 --- a/integrationExamples/cnx/index.html +++ /dev/null @@ -1,239 +0,0 @@ - - - - Prebid.js Integration Example - - - - - -

Prebid.js Integration Example

- -
-
-
- - From e3db1f52a6d1feeaf75ea71c628b2a5850794fd3 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Fri, 4 Oct 2024 15:14:07 +0300 Subject: [PATCH 04/21] deleted test change --- test/spec/modules/ads_interactiveBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/ads_interactiveBidAdapter_spec.js b/test/spec/modules/ads_interactiveBidAdapter_spec.js index f33e24fd25d..93fd94a0f2d 100644 --- a/test/spec/modules/ads_interactiveBidAdapter_spec.js +++ b/test/spec/modules/ads_interactiveBidAdapter_spec.js @@ -137,7 +137,6 @@ describe('AdsInteractiveBidAdapter', function () { expect(data).to.have.all.keys( 'deviceWidth', 'deviceHeight', - 'device', 'language', 'secure', 'host', From d442066d9960683cad139521d791046f36233152 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Fri, 4 Oct 2024 15:16:50 +0300 Subject: [PATCH 05/21] renamed response data --- modules/connatixBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 80eb43dd258..e0b2b4cd8fe 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -340,8 +340,8 @@ export const spec = { event.stopImmediatePropagation(); const response = event.data; - if (!response.optout && response.type) { - saveOnAllStorages(CNX_IDS, response.type, CNX_ID_RETENTION_TIME_HOUR); + if (!response.optout && response.ids) { + saveOnAllStorages(CNX_IDS, response.ids, CNX_ID_RETENTION_TIME_HOUR); } }, true) From 02ba79758eba61ac48eae454d8a970c1b6111760 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Fri, 4 Oct 2024 16:10:24 +0300 Subject: [PATCH 06/21] modified url in event listener --- modules/connatixBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index e0b2b4cd8fe..46261b1dee8 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -331,7 +331,7 @@ export const spec = { } window.addEventListener('message', function handler(event) { - if (!event.data || !event.origin.includes('connatix')) { + if (!event.data || event.origin != 'https://cds.connatix.com') { return; } From 52da7f22cfd7f1c02bfcfb9f647258d8869f5f65 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 7 Oct 2024 15:06:01 +0300 Subject: [PATCH 07/21] updated response naming --- modules/connatixBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 46261b1dee8..db8fc6f56ef 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -340,8 +340,8 @@ export const spec = { event.stopImmediatePropagation(); const response = event.data; - if (!response.optout && response.ids) { - saveOnAllStorages(CNX_IDS, response.ids, CNX_ID_RETENTION_TIME_HOUR); + if (response.data) { + saveOnAllStorages(CNX_IDS, response.data, CNX_ID_RETENTION_TIME_HOUR); } }, true) From a87d18923c1f30d21565a4e6ad7fe964630a18dc Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 7 Oct 2024 15:31:18 +0300 Subject: [PATCH 08/21] remove event listener when i get all providers --- modules/connatixBidAdapter.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index db8fc6f56ef..bb37389b7bd 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -335,9 +335,11 @@ export const spec = { return; } - this.removeEventListener('message', handler); - - event.stopImmediatePropagation(); + if(event.response.type === 'cnx_all_identity_providers_resolved') + { + this.removeEventListener('message', handler); + event.stopImmediatePropagation(); + } const response = event.data; if (response.data) { From f396380ba5578d2e6b1b847c509b4653f813f718 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 7 Oct 2024 15:42:22 +0300 Subject: [PATCH 09/21] formatting --- modules/connatixBidAdapter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index bb37389b7bd..77860739d75 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -335,8 +335,7 @@ export const spec = { return; } - if(event.response.type === 'cnx_all_identity_providers_resolved') - { + if (event.response.type === 'cnx_all_identity_providers_resolved') { this.removeEventListener('message', handler); event.stopImmediatePropagation(); } From 87bfec8ae3d92e5988319ae42220d412e0c16309 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 7 Oct 2024 15:57:58 +0300 Subject: [PATCH 10/21] wrote data instead of response --- modules/connatixBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 77860739d75..0ba2a832c8c 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -335,7 +335,7 @@ export const spec = { return; } - if (event.response.type === 'cnx_all_identity_providers_resolved') { + if (event.data.type === 'cnx_all_identity_providers_resolved') { this.removeEventListener('message', handler); event.stopImmediatePropagation(); } From 2449b807bfa23553750860e60594ef226098a148 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Tue, 8 Oct 2024 12:00:37 +0300 Subject: [PATCH 11/21] fixed receiving id values --- modules/connatixBidAdapter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 0ba2a832c8c..506d8369f3e 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -34,7 +34,7 @@ const DEFAULT_CURRENCY = 'USD'; const CNX_IDS = 'cnx_ids'; const CNX_ID_RETENTION_TIME_HOUR = 24 * 30; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); -const CNX_IDS_VALUES = []; +let CNX_IDS_VALUES; const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -190,16 +190,16 @@ function saveOnAllStorages(name, value, expirationTimeHours) { const date = new Date(); date.setTime(date.getTime() + (expirationTimeHours * 60 * 60 * 1000)); const expires = `expires=${date.toUTCString()}`; - storage.setCookie(name, value, expires); - storage.setDataInLocalStorage(name, value); - CNX_IDS_VALUES.push(value); + storage.setCookie(name, JSON.stringify(value), expires); + storage.setDataInLocalStorage(name, JSON.stringify(value)); + CNX_IDS_VALUES = value; } function readFromAllStorages(name) { const fromCookie = storage.getCookie(name); const fromLocalStorage = storage.getDataFromLocalStorage(name); - return fromCookie || fromLocalStorage || undefined; + return JSON.parse(fromCookie) || JSON.parse(fromLocalStorage) || undefined; } export const spec = { @@ -245,7 +245,7 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); - const cnxIds = [readFromAllStorages(CNX_IDS)] || CNX_IDS_VALUES; + let cnxIds = readFromAllStorages(CNX_IDS) || CNX_IDS_VALUES; const requestPayload = { ortb2: bidderRequest.ortb2, From 25ae0bd79a736edbf7860342e706fc8d883a7365 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Tue, 8 Oct 2024 14:50:19 +0300 Subject: [PATCH 12/21] check if undefined before parsing --- modules/connatixBidAdapter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 506d8369f3e..8badd4eefe6 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -199,7 +199,10 @@ function readFromAllStorages(name) { const fromCookie = storage.getCookie(name); const fromLocalStorage = storage.getDataFromLocalStorage(name); - return JSON.parse(fromCookie) || JSON.parse(fromLocalStorage) || undefined; + const parsedCookie = fromCookie ? JSON.parse(fromCookie) : undefined; + const parsedLocalStorage = fromLocalStorage ? JSON.parse(fromLocalStorage) : undefined; + + return parsedCookie || parsedLocalStorage || undefined; } export const spec = { From 6f6992476a541380cf13f1a907df32ae7e2a4abd Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Tue, 8 Oct 2024 15:27:08 +0300 Subject: [PATCH 13/21] PR comments --- modules/connatixBidAdapter.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 8badd4eefe6..e633a2a4752 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -31,9 +31,10 @@ const BIDDER_CODE = 'connatix'; const AD_URL = 'https://capi.connatix.com/rtb/hba'; const DEFAULT_MAX_TTL = '3600'; const DEFAULT_CURRENCY = 'USD'; -const CNX_IDS = 'cnx_ids'; -const CNX_ID_RETENTION_TIME_HOUR = 24 * 30; // 30 days +const USER_IDS = 'cnx_ids'; +const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); +const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; let CNX_IDS_VALUES; const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -186,9 +187,9 @@ function _handleEids(payload, validBidRequests) { } } -function saveOnAllStorages(name, value, expirationTimeHours) { +function saveOnAllStorages(name, value, expirationTimeMs) { const date = new Date(); - date.setTime(date.getTime() + (expirationTimeHours * 60 * 60 * 1000)); + date.setTime(date.getTime() + expirationTimeMs); const expires = `expires=${date.toUTCString()}`; storage.setCookie(name, JSON.stringify(value), expires); storage.setDataInLocalStorage(name, JSON.stringify(value)); @@ -248,7 +249,7 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); - let cnxIds = readFromAllStorages(CNX_IDS) || CNX_IDS_VALUES; + let cnxIds = readFromAllStorages(USER_IDS) || CNX_IDS_VALUES; const requestPayload = { ortb2: bidderRequest.ortb2, @@ -334,18 +335,18 @@ export const spec = { } window.addEventListener('message', function handler(event) { - if (!event.data || event.origin != 'https://cds.connatix.com') { + if (!event.data || event.origin !== 'https://cds.connatix.com') { return; } - if (event.data.type === 'cnx_all_identity_providers_resolved') { + if (event.data.type === ALL_PROVIDERS_RESOLVED_EVENT) { this.removeEventListener('message', handler); event.stopImmediatePropagation(); } const response = event.data; if (response.data) { - saveOnAllStorages(CNX_IDS, response.data, CNX_ID_RETENTION_TIME_HOUR); + saveOnAllStorages(USER_IDS, response.data, CNX_IDS_EXPIRY); } }, true) From d35bc57f3ebe0fdcaa181339701f180d888287a1 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Tue, 8 Oct 2024 15:34:14 +0300 Subject: [PATCH 14/21] changed naming to be the same as on BE side --- modules/connatixBidAdapter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index e633a2a4752..a6ffe475ad1 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -31,7 +31,7 @@ const BIDDER_CODE = 'connatix'; const AD_URL = 'https://capi.connatix.com/rtb/hba'; const DEFAULT_MAX_TTL = '3600'; const DEFAULT_CURRENCY = 'USD'; -const USER_IDS = 'cnx_ids'; +const USER_IDS = 'user_ids'; const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; @@ -249,7 +249,7 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); - let cnxIds = readFromAllStorages(USER_IDS) || CNX_IDS_VALUES; + let userIds = readFromAllStorages(USER_IDS) || CNX_IDS_VALUES; const requestPayload = { ortb2: bidderRequest.ortb2, @@ -257,7 +257,7 @@ export const spec = { uspConsent: bidderRequest.uspConsent, gppConsent: bidderRequest.gppConsent, refererInfo: bidderRequest.refererInfo, - userIds: cnxIds, + identityProviderData: userIds, bidRequests, }; From a9566bcafeec4e6cbc51dd6b0a351ce542f8d4cf Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Wed, 9 Oct 2024 12:52:12 +0300 Subject: [PATCH 15/21] PR comments --- modules/connatixBidAdapter.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index a6ffe475ad1..4f4ab7af860 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -31,7 +31,7 @@ const BIDDER_CODE = 'connatix'; const AD_URL = 'https://capi.connatix.com/rtb/hba'; const DEFAULT_MAX_TTL = '3600'; const DEFAULT_CURRENCY = 'USD'; -const USER_IDS = 'user_ids'; +const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'user_ids'; const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; @@ -249,7 +249,12 @@ export const spec = { */ buildRequests: (validBidRequests = [], bidderRequest = {}) => { const bidRequests = _getBidRequests(validBidRequests); - let userIds = readFromAllStorages(USER_IDS) || CNX_IDS_VALUES; + let userIds; + try { + userIds = readFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY) || CNX_IDS_VALUES; + } catch (error) { + userIds = CNX_IDS_VALUES; + } const requestPayload = { ortb2: bidderRequest.ortb2, @@ -346,7 +351,7 @@ export const spec = { const response = event.data; if (response.data) { - saveOnAllStorages(USER_IDS, response.data, CNX_IDS_EXPIRY); + saveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); } }, true) From d1eb2ba5ebb0586f4e244f9e7ecafc7e0ca71639 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Thu, 10 Oct 2024 12:47:03 +0300 Subject: [PATCH 16/21] changed naming --- modules/connatixBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 4f4ab7af860..3566303885c 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -31,7 +31,7 @@ const BIDDER_CODE = 'connatix'; const AD_URL = 'https://capi.connatix.com/rtb/hba'; const DEFAULT_MAX_TTL = '3600'; const DEFAULT_CURRENCY = 'USD'; -const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'user_ids'; +const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'cnx_user_ids'; const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; From 9f5ccf81a734acc7c9c052a5f331e40f892052a4 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Thu, 10 Oct 2024 13:16:32 +0300 Subject: [PATCH 17/21] changed to camelcase --- modules/connatixBidAdapter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 3566303885c..02c66ccda5c 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -35,7 +35,7 @@ const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'cnx_user_ids'; const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; -let CNX_IDS_VALUES; +let cnxIdsValues; const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -193,7 +193,7 @@ function saveOnAllStorages(name, value, expirationTimeMs) { const expires = `expires=${date.toUTCString()}`; storage.setCookie(name, JSON.stringify(value), expires); storage.setDataInLocalStorage(name, JSON.stringify(value)); - CNX_IDS_VALUES = value; + cnxIdsValues = value; } function readFromAllStorages(name) { @@ -251,9 +251,9 @@ export const spec = { const bidRequests = _getBidRequests(validBidRequests); let userIds; try { - userIds = readFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY) || CNX_IDS_VALUES; + userIds = readFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY) || cnxIdsValues; } catch (error) { - userIds = CNX_IDS_VALUES; + userIds = cnxIdsValues; } const requestPayload = { From 0692cd9adab83981545c40fd7dfc4eb8e5ec0704 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Thu, 10 Oct 2024 13:24:53 +0300 Subject: [PATCH 18/21] checked for all events --- modules/connatixBidAdapter.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 02c66ccda5c..461bc3d4217 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -35,6 +35,7 @@ const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'cnx_user_ids'; const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; // 30 days export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; +const IDENTITY_PROVIDER_RESOLVED_EVENT = 'cnx_identity_provider_resolved'; let cnxIdsValues; const EVENTS_URL = 'https://capi.connatix.com/tr/am'; @@ -349,9 +350,11 @@ export const spec = { event.stopImmediatePropagation(); } - const response = event.data; - if (response.data) { - saveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); + if (event.data.type === ALL_PROVIDERS_RESOLVED_EVENT || event.data.type === IDENTITY_PROVIDER_RESOLVED_EVENT) { + const response = event.data; + if (response.data) { + saveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); + } } }, true) From 092ba3b195908f960228975321eb12cdb6e19c0f Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 14 Oct 2024 16:11:51 +0300 Subject: [PATCH 19/21] unit tests --- test/spec/modules/connatixBidAdapter_spec.js | 102 +++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/test/spec/modules/connatixBidAdapter_spec.js b/test/spec/modules/connatixBidAdapter_spec.js index 5c01e23b027..4ac3d59e2f6 100644 --- a/test/spec/modules/connatixBidAdapter_spec.js +++ b/test/spec/modules/connatixBidAdapter_spec.js @@ -8,11 +8,15 @@ import { _getMinSize as connatixGetMinSize, _getViewability as connatixGetViewability, _isViewabilityMeasurable as connatixIsViewabilityMeasurable, + saveOnAllStorages, + readFromAllStorages, + storage, spec } from '../../../modules/connatixBidAdapter.js'; import adapterManager from '../../../src/adapterManager.js'; import * as ajax from '../../../src/ajax.js'; import { ADPOD, BANNER, VIDEO } from '../../../src/mediaTypes.js'; +import { getStorageManager } from '../../../src/storageManager.js'; const BIDDER_CODE = 'connatix'; @@ -935,4 +939,102 @@ describe('connatixBidAdapter', function () { expect(floor).to.equal(0); }); }); + describe('getUserSyncs with message event listener', function() { + const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; + const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'cnx_user_ids'; + const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; + + const mockData = { + providerName: 'nonId', + data: { + supplementalEids: [{ provider: 2, group: 1, eidsList: ['123', '456'] }] + } + }; + + function messageHandler(event) { + if (!event.data || event.origin !== 'https://cds.connatix.com') { + return; + } + + if (event.data.type === ALL_PROVIDERS_RESOLVED_EVENT) { + window.removeEventListener('message', messageHandler); + event.stopImmediatePropagation(); + } + + if (event.data.type === ALL_PROVIDERS_RESOLVED_EVENT || event.data.type === IDENTITY_PROVIDER_RESOLVED_EVENT) { + const response = event.data; + if (response.data) { + saveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); + } + } + } + + let sandbox; + + beforeEach(() => { + sandbox = sinon.createSandbox(); + sandbox.stub(storage, 'setCookie'); + sandbox.stub(storage, 'setDataInLocalStorage'); + sandbox.stub(window, 'removeEventListener'); + sandbox.stub(storage, 'cookiesAreEnabled').returns(true); + sandbox.stub(storage, 'localStorageIsEnabled').returns(true); + sandbox.stub(storage, 'getCookie'); + sandbox.stub(storage, 'getDataFromLocalStorage'); + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('Should set a cookie and save to local storage when a valid message is received', () => { + const fakeEvent = { + data: { type: 'cnx_all_identity_providers_resolved', data: mockData }, + origin: 'https://cds.connatix.com', + stopImmediatePropagation: sinon.spy() + }; + + messageHandler(fakeEvent); + + expect(fakeEvent.stopImmediatePropagation.calledOnce).to.be.true; + expect(window.removeEventListener.calledWith('message', messageHandler)).to.be.true; + expect(storage.setCookie.calledWith(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, JSON.stringify(mockData), sinon.match.string)).to.be.true; + expect(storage.setDataInLocalStorage.calledWith(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, JSON.stringify(mockData))).to.be.true; + + storage.getCookie.returns(JSON.stringify(mockData)); + storage.getDataFromLocalStorage.returns(JSON.stringify(mockData)); + + const retrievedData = readFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY); + expect(retrievedData).to.deep.equal(mockData); + }); + + it('Should should not do anything when there is no data in the payload', () => { + const fakeEvent = { + data: null, + origin: 'https://cds.connatix.com', + stopImmediatePropagation: sinon.spy() + }; + + messageHandler(fakeEvent); + + expect(fakeEvent.stopImmediatePropagation.notCalled).to.be.true; + expect(window.removeEventListener.notCalled).to.be.true; + expect(storage.setCookie.notCalled).to.be.true; + expect(storage.setDataInLocalStorage.notCalled).to.be.true; + }); + + it('Should should not do anything when the origin is invalid', () => { + const fakeEvent = { + data: { type: 'cnx_all_identity_providers_resolved', data: mockData }, + origin: 'https://notConnatix.com', + stopImmediatePropagation: sinon.spy() + }; + + messageHandler(fakeEvent); + + expect(fakeEvent.stopImmediatePropagation.notCalled).to.be.true; + expect(window.removeEventListener.notCalled).to.be.true; + expect(storage.setCookie.notCalled).to.be.true; + expect(storage.setDataInLocalStorage.notCalled).to.be.true; + }); + }); }); From 34453ff927e06c2b958a54306657b947982f5311 Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Mon, 14 Oct 2024 16:40:03 +0300 Subject: [PATCH 20/21] exported functions --- modules/connatixBidAdapter.js | 4 ++-- test/spec/modules/connatixBidAdapter_spec.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 461bc3d4217..aeadd2d1cd9 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -188,7 +188,7 @@ function _handleEids(payload, validBidRequests) { } } -function saveOnAllStorages(name, value, expirationTimeMs) { +export function saveOnAllStorages(name, value, expirationTimeMs) { const date = new Date(); date.setTime(date.getTime() + expirationTimeMs); const expires = `expires=${date.toUTCString()}`; @@ -197,7 +197,7 @@ function saveOnAllStorages(name, value, expirationTimeMs) { cnxIdsValues = value; } -function readFromAllStorages(name) { +export function readFromAllStorages(name) { const fromCookie = storage.getCookie(name); const fromLocalStorage = storage.getDataFromLocalStorage(name); diff --git a/test/spec/modules/connatixBidAdapter_spec.js b/test/spec/modules/connatixBidAdapter_spec.js index 4ac3d59e2f6..3a32a1d3ab1 100644 --- a/test/spec/modules/connatixBidAdapter_spec.js +++ b/test/spec/modules/connatixBidAdapter_spec.js @@ -8,8 +8,8 @@ import { _getMinSize as connatixGetMinSize, _getViewability as connatixGetViewability, _isViewabilityMeasurable as connatixIsViewabilityMeasurable, - saveOnAllStorages, - readFromAllStorages, + saveOnAllStorages as connatixSaveOnAllStorages, + readFromAllStorages as connatixReadFromAllStorages, storage, spec } from '../../../modules/connatixBidAdapter.js'; @@ -964,7 +964,7 @@ describe('connatixBidAdapter', function () { if (event.data.type === ALL_PROVIDERS_RESOLVED_EVENT || event.data.type === IDENTITY_PROVIDER_RESOLVED_EVENT) { const response = event.data; if (response.data) { - saveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); + connatixSaveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, response.data, CNX_IDS_EXPIRY); } } } @@ -1003,7 +1003,7 @@ describe('connatixBidAdapter', function () { storage.getCookie.returns(JSON.stringify(mockData)); storage.getDataFromLocalStorage.returns(JSON.stringify(mockData)); - const retrievedData = readFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY); + const retrievedData = connatixReadFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY); expect(retrievedData).to.deep.equal(mockData); }); From 6624dc11c7d0098d999e60afa4389bef550baa2f Mon Sep 17 00:00:00 2001 From: Octavia Suceava Date: Wed, 16 Oct 2024 16:40:53 +0300 Subject: [PATCH 21/21] added one more test for buildRequests --- test/spec/modules/connatixBidAdapter_spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/connatixBidAdapter_spec.js b/test/spec/modules/connatixBidAdapter_spec.js index 3a32a1d3ab1..af56b937f58 100644 --- a/test/spec/modules/connatixBidAdapter_spec.js +++ b/test/spec/modules/connatixBidAdapter_spec.js @@ -16,7 +16,6 @@ import { import adapterManager from '../../../src/adapterManager.js'; import * as ajax from '../../../src/ajax.js'; import { ADPOD, BANNER, VIDEO } from '../../../src/mediaTypes.js'; -import { getStorageManager } from '../../../src/storageManager.js'; const BIDDER_CODE = 'connatix'; @@ -568,6 +567,7 @@ describe('connatixBidAdapter', function () { describe('buildRequests', function () { let serverRequest; + let setCookieStub, setDataInLocalStorageStub; let bidderRequest = { refererInfo: { canonicalUrl: '', @@ -596,10 +596,21 @@ describe('connatixBidAdapter', function () { }; this.beforeEach(function () { + const mockIdentityProviderData = { mockKey: 'mockValue' }; + const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; + setCookieStub = sinon.stub(storage, 'setCookie'); + setDataInLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage'); + connatixSaveOnAllStorages('test_ids_cnx', mockIdentityProviderData, CNX_IDS_EXPIRY); + bid = mockBidRequest(); serverRequest = spec.buildRequests([bid], bidderRequest); }) + this.afterEach(function() { + setCookieStub.restore(); + setDataInLocalStorageStub.restore(); + }); + it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; expect(serverRequest.method).to.exist; @@ -626,6 +637,7 @@ describe('connatixBidAdapter', function () { expect(serverRequest.data.uspConsent).to.equal(bidderRequest.uspConsent); expect(serverRequest.data.gppConsent).to.equal(bidderRequest.gppConsent); expect(serverRequest.data.ortb2).to.equal(bidderRequest.ortb2); + expect(serverRequest.data.identityProviderData).to.deep.equal({ mockKey: 'mockValue' }); }); });