diff --git a/modules/connatixBidAdapter.js b/modules/connatixBidAdapter.js index 0b840db6c26..728d96da067 100644 --- a/modules/connatixBidAdapter.js +++ b/modules/connatixBidAdapter.js @@ -9,7 +9,7 @@ import { isArray, formatQS } from '../src/utils.js'; - +import {getStorageManager} from '../src/storageManager.js'; import { BANNER, } from '../src/mediaTypes.js'; @@ -18,6 +18,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 }); /* * Get the bid floor value from the bid object, either using the getFloor function or by accessing the 'params.bidfloor' property. @@ -41,6 +44,21 @@ export function getBidFloor(bid) { } } +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); +} + +function readFromAllStorages(name) { + const fromCookie = storage.getCookie(name); + const fromLocalStorage = storage.getDataFromLocalStorage(name); + + return fromCookie || fromLocalStorage || undefined; +} + export const spec = { code: BIDDER_CODE, gvlid: 143, @@ -94,12 +112,14 @@ export const spec = { }; }); + const cnxIds = readFromAllStorages(CNX_IDS); const requestPayload = { ortb2: bidderRequest.ortb2, gdprConsent: bidderRequest.gdprConsent, uspConsent: bidderRequest.uspConsent, gppConsent: bidderRequest.gppConsent, refererInfo: bidderRequest.refererInfo, + userIds: cnxIds, bidRequests, }; @@ -171,6 +191,20 @@ export const spec = { params['us_privacy'] = encodeURIComponent(uspConsent); } + window.addEventListener('message', function handler(event) { + if (!event.data || !event.origin.includes('connatix')) { + return; + } + this.removeEventListener('message', handler); + + event.stopImmediatePropagation(); + + const response = event.data; + if (!response.optout && response.eids) { + saveOnAllStorages(CNX_IDS, response.eids, CNX_ID_RETENTION_TIME_HOUR); + } + }, true) + const syncUrl = serverResponses[0].body.UserSyncEndpoint; const queryParams = Object.keys(params).length > 0 ? formatQS(params) : '';