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

Connatix events #11

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
90 changes: 72 additions & 18 deletions modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import {
registerBidder
} from '../src/adapters/bidderFactory.js';

import { config } from '../src/config.js';

import {
deepAccess,
isFn,
logError,
isArray,
formatQS,
deepSetValue
deepSetValue,
isNumber
} from '../src/utils.js';
import { ajax } from '../src/ajax.js';

import {
ADPOD,
Expand All @@ -18,10 +22,15 @@ import {
} from '../src/mediaTypes.js';

const BIDDER_CODE = 'connatix';

const AD_URL = 'https://capi.connatix.com/rtb/hba';
const DEFAULT_MAX_TTL = '3600';
const DEFAULT_CURRENCY = 'USD';

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

let context = {};

/*
* Get the bid floor value from the bid object, either using the getFloor function or by accessing the 'params.bidfloor' property.
* If the bid floor cannot be determined, return 0 as a fallback value.
Expand Down Expand Up @@ -62,6 +71,26 @@ export function validateVideo(mediaTypes) {
return video.context !== ADPOD;
}

export function _getBidRequests(validBidRequests) {
return validBidRequests.map(bid => {
const {
bidId,
mediaTypes,
params,
sizes,
} = bid;
const { placementId, viewabilityContainerIdentifier } = params;
return {
bidId,
mediaTypes,
sizes,
placementId,
hasViewabilityContainerId: Boolean(viewabilityContainerIdentifier),
floor: getBidFloor(bid),
};
});
}

/**
* Get ids from Prebid User ID Modules and add them to the payload
*/
Expand Down Expand Up @@ -113,21 +142,7 @@ export const spec = {
* Return an object containing the request method, url, and the constructed payload.
*/
buildRequests: (validBidRequests = [], bidderRequest = {}) => {
const bidRequests = validBidRequests.map(bid => {
const {
bidId,
mediaTypes,
params,
sizes,
} = bid;
return {
bidId,
mediaTypes,
sizes,
placementId: params.placementId,
floor: getBidFloor(bid),
};
});
const bidRequests = _getBidRequests(validBidRequests);

const requestPayload = {
ortb2: bidderRequest.ortb2,
Expand All @@ -140,10 +155,12 @@ export const spec = {

_handleEids(requestPayload, validBidRequests);

context = requestPayload;

return {
method: 'POST',
url: AD_URL,
data: requestPayload
data: context
};
},

Expand Down Expand Up @@ -217,7 +234,44 @@ export const spec = {
type: 'iframe',
url
}];
}
},

/**
* Register bidder specific code, which will execute if the server response time is greater than auction timeout
* @param {TimedOutBid} timeoutData
*/
onTimeout: (timeoutData) => {
const connatixBidRequestTimeout = timeoutData.find(bidderRequest => bidderRequest.bidder === BIDDER_CODE);

// Log only it is a timeout for Connatix
// Otherwise it is not relevant for us
if (!connatixBidRequestTimeout) {
return;
}
const requestTimeout = connatixBidRequestTimeout.timeout;
const timeout = isNumber(requestTimeout) ? requestTimeout : config.getConfig('bidderTimeout');
ajax(`${EVENTS_URL}`, null, JSON.stringify({type: 'timeout', timeout, context}), {
method: 'POST',
withCredentials: false
});
},

/**
* Register bidder specific code, which will execute if a bid from this bidder won the auction
* @param {Bid} bid The bid that won the auction
*/
onBidWon(bidWinData) {
if (bidWinData == null) {
return;
}

const {bidder, cpm} = bidWinData;

ajax(`${EVENTS_URL}`, null, JSON.stringify({type: 'bid_won', bestBidBidder: bidder, bestBidPrice: cpm, context}), {
method: 'POST',
withCredentials: false
});
},
};

registerBidder(spec);