Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mny 3670 3 #14

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,6 +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';
Dan-Lucian marked this conversation as resolved.
Show resolved Hide resolved
const CNX_ID_RETENTION_TIME_HOUR = 24 * 30; // 30 days
Dan-Lucian marked this conversation as resolved.
Show resolved Hide resolved
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
const CNX_IDS_VALUES = [];

const EVENTS_URL = 'https://capi.connatix.com/tr/am';

Expand Down Expand Up @@ -182,6 +186,22 @@ function _handleEids(payload, validBidRequests) {
}
}

function saveOnAllStorages(name, value, expirationTimeHours) {
const date = new Date();
date.setTime(date.getTime() + (expirationTimeHours * 60 * 60 * 1000));
Dan-Lucian marked this conversation as resolved.
Show resolved Hide resolved
const expires = `expires=${date.toUTCString()}`;
storage.setCookie(name, value, expires);
storage.setDataInLocalStorage(name, value);
CNX_IDS_VALUES.push(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 @@ -225,13 +245,15 @@ export const spec = {
*/
buildRequests: (validBidRequests = [], bidderRequest = {}) => {
const bidRequests = _getBidRequests(validBidRequests);
const cnxIds = [readFromAllStorages(CNX_IDS)] || CNX_IDS_VALUES;

const requestPayload = {
ortb2: bidderRequest.ortb2,
gdprConsent: bidderRequest.gdprConsent,
uspConsent: bidderRequest.uspConsent,
gppConsent: bidderRequest.gppConsent,
refererInfo: bidderRequest.refererInfo,
userIds: cnxIds,
bidRequests,
};

Expand Down Expand Up @@ -308,6 +330,21 @@ export const spec = {
params['us_privacy'] = encodeURIComponent(uspConsent);
}

window.addEventListener('message', function handler(event) {
if (!event.data || !event.origin.includes('connatix')) {
OctaviaS20 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

this.removeEventListener('message', handler);

event.stopImmediatePropagation();
OctaviaS20 marked this conversation as resolved.
Show resolved Hide resolved

const response = event.data;
if (!response.optout && response.ids) {
saveOnAllStorages(CNX_IDS, response.ids, CNX_ID_RETENTION_TIME_HOUR);
}
}, true)

const syncUrl = serverResponses[0].body.UserSyncEndpoint;
const queryParams = Object.keys(params).length > 0 ? formatQS(params) : '';

Expand Down