Skip to content

Commit

Permalink
Jixie Bid Adapter : support ids extraction based on config object and…
Browse files Browse the repository at this point in the history
… misc. changes (#10551)

* Adapter does not seem capable of supporting advertiserDomains #6650
added response comment and some trivial code.

* removed a blank line at the end of file
added a space behind the // in comments

* in response to comment from reviewer. add the aspect of advertiserdomain in unit tests

* added the code to get the keywords from the meta tags if available.

* WIP

* cleaned up

* correcting formatting errors from circleci

* sending floor to our backend for each bid, when available, changed one of the 1st party cookies that we want to send to backend

* fixed spacing issues in code

* 1/ provide the possibility of using the jixie section of the config object to determine what ids to read from cookie and to send
2/ removed ontimeout handling
3/ bidwon just ping the trackingUrl, if any
4/ misc: sending aid (from jixie config if any), prebid version etc

* corrected formatting mistakes
  • Loading branch information
jxdeveloper1 authored Oct 23, 2023
1 parent d0e981b commit 6f51f68
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 187 deletions.
103 changes: 38 additions & 65 deletions modules/jixieBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepAccess, getDNT, isArray, logWarn, isFn, isPlainObject} from '../src/utils.js';
import {deepAccess, getDNT, isArray, logWarn, isFn, isPlainObject, logError, logInfo} from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getStorageManager} from '../src/storageManager.js';
Expand All @@ -7,9 +7,11 @@ import {ajax} from '../src/ajax.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {Renderer} from '../src/Renderer.js';

const ADAPTER_VERSION = '2.1.0';
const PREBID_VERSION = '$prebid.version$';

const BIDDER_CODE = 'jixie';
export const storage = getStorageManager({bidderCode: BIDDER_CODE});
const EVENTS_URL = 'https://hbtra.jixie.io/sync/hb?';
const JX_OUTSTREAM_RENDERER_URL = 'https://scripts.jixie.media/jxhbrenderer.1.1.min.js';
const REQUESTS_URL = 'https://hb.jixie.io/v2/hbpost';
const sidTTLMins_ = 30;
Expand Down Expand Up @@ -59,7 +61,18 @@ function setIds_(clientId, sessionId) {
} catch (error) {}
}

function fetchIds_() {
/**
* fetch some ids from cookie, LS.
* @returns
*/
const defaultGenIds_ = [
{ id: '_jxtoko' },
{ id: '_jxifo' },
{ id: '_jxtdid' },
{ id: '_jxcomp' }
];

function fetchIds_(cfg) {
let ret = {
client_id_c: '',
client_id_ls: '',
Expand All @@ -77,9 +90,11 @@ function fetchIds_() {
if (tmp) ret.client_id_ls = tmp;
tmp = storage.getDataFromLocalStorage('_jxxs');
if (tmp) ret.session_id_ls = tmp;
['_jxtoko', '_jxifo', '_jxtdid', '_jxcomp'].forEach(function(n) {
tmp = storage.getCookie(n);
if (tmp) ret.jxeids[n] = tmp;

let arr = cfg.genids ? cfg.genids : defaultGenIds_;
arr.forEach(function(o) {
tmp = storage.getCookie(o.ck ? o.ck : o.id);
if (tmp) ret.jxeids[o.id] = tmp;
});
} catch (error) {}
return ret;
Expand All @@ -97,14 +112,6 @@ function getDevice_() {
return device;
}

function pingTracking_(endpointOverride, qpobj) {
internal.ajax((endpointOverride || EVENTS_URL), null, qpobj, {
withCredentials: true,
method: 'GET',
crossOrigin: true
});
}

function jxOutstreamRender_(bidAd) {
bidAd.renderer.push(() => {
window.JixieOutstreamVideo.init({
Expand Down Expand Up @@ -166,7 +173,6 @@ export const internal = {

export const spec = {
code: BIDDER_CODE,
EVENTS_URL: EVENTS_URL,
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
if (bid.bidder !== BIDDER_CODE || typeof bid.params === 'undefined') {
Expand Down Expand Up @@ -198,29 +204,23 @@ export const spec = {
}
bids.push(tmp);
});
let jixieCfgBlob = config.getConfig('jixie');
if (!jixieCfgBlob) {
jixieCfgBlob = {};
}
let jxCfg = config.getConfig('jixie') || {};

let ids = fetchIds_();
let ids = fetchIds_(jxCfg);
let eids = [];
let miscDims = internal.getMiscDims();
let schain = deepAccess(validBidRequests[0], 'schain');

let eids1 = validBidRequests[0].userIdAsEids
let eids1 = validBidRequests[0].userIdAsEids;
// all available user ids are sent to our backend in the standard array layout:
if (eids1 && eids1.length) {
eids = eids1;
}
// we want to send this blob of info to our backend:
let pg = config.getConfig('priceGranularity');
if (!pg) {
pg = {};
}
let transformedParams = Object.assign({}, {
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
auctionid: bidderRequest.auctionId,
auctionid: bidderRequest.auctionId || '',
aid: jxCfg.aid || '',
timeout: bidderRequest.timeout,
currency: currency,
timestamp: (new Date()).getTime(),
Expand All @@ -231,8 +231,10 @@ export const spec = {
bids: bids,
eids: eids,
schain: schain,
pricegranularity: pg,
cfg: jixieCfgBlob
pricegranularity: (config.getConfig('priceGranularity') || {}),
ver: ADAPTER_VERSION,
pbjsver: PREBID_VERSION,
cfg: jxCfg
}, ids);
return Object.assign({}, {
method: 'POST',
Expand All @@ -243,56 +245,27 @@ export const spec = {
},

onTimeout: function(timeoutData) {
let jxCfgBlob = config.getConfig('jixie');
if (jxCfgBlob && jxCfgBlob.onTimeout == 'off') {
return;
}
let url = null;// default
if (jxCfgBlob && jxCfgBlob.onTimeoutUrl && typeof jxCfgBlob.onTimeoutUrl == 'string') {
url = jxCfgBlob.onTimeoutUrl;
}
let miscDims = internal.getMiscDims();
pingTracking_(url, // no overriding ping URL . just use default
{
action: 'hbtimeout',
device: miscDims.device,
pageurl: encodeURIComponent(miscDims.pageurl),
domain: encodeURIComponent(miscDims.domain),
auctionid: deepAccess(timeoutData, '0.auctionId'),
timeout: deepAccess(timeoutData, '0.timeout'),
count: timeoutData.length
});
logError('jixie adapter timed out for the auction.', timeoutData);
},

onBidWon: function(bid) {
if (bid.notrack) {
return;
}
if (bid.trackingUrl) {
pingTracking_(bid.trackingUrl, {});
} else {
let miscDims = internal.getMiscDims();
pingTracking_((bid.trackingUrlBase ? bid.trackingUrlBase : null), {
action: 'hbbidwon',
device: miscDims.device,
pageurl: encodeURIComponent(miscDims.pageurl),
domain: encodeURIComponent(miscDims.domain),
cid: bid.cid,
cpid: bid.cpid,
jxbidid: bid.jxBidId,
auctionid: bid.auctionId,
cpm: bid.cpm,
requestid: bid.requestId
internal.ajax(bid.trackingUrl, null, {}, {
withCredentials: true,
method: 'GET',
crossOrigin: true
});
}
logInfo(
`jixie adapter won the auction. Bid id: ${bid.bidId}, Ad Unit Id: ${bid.adUnitId}`
);
},

interpretResponse: function(response, bidRequest) {
if (response && response.body && isArray(response.body.bids)) {
const bidResponses = [];
response.body.bids.forEach(function(oneBid) {
let bnd = {};

Object.assign(bnd, oneBid);
if (oneBid.osplayer) {
bnd.adResponse = {
Expand Down
Loading

0 comments on commit 6f51f68

Please sign in to comment.