Skip to content

Commit

Permalink
listen to ids from user sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Octavia Suceava authored and Octavia Suceava committed Sep 26, 2024
1 parent daf607a commit b173792
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isArray,
formatQS
} from '../src/utils.js';

import {getStorageManager} from '../src/storageManager.js';
import {
BANNER,
} from '../src/mediaTypes.js';
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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,
};

Expand Down Expand Up @@ -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) : '';

Expand Down

0 comments on commit b173792

Please sign in to comment.