Skip to content

Commit

Permalink
Jixie Bid Adapter : pass bid floor to backend and change 1st party co…
Browse files Browse the repository at this point in the history
…okie (#10496)

* 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
  • Loading branch information
jxdeveloper1 committed Sep 18, 2023
1 parent ecc0f48 commit e18ab51
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
30 changes: 27 additions & 3 deletions modules/jixieBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepAccess, getDNT, isArray, logWarn} from '../src/utils.js';
import {deepAccess, getDNT, isArray, logWarn, isFn, isPlainObject} 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 @@ -14,6 +14,27 @@ const JX_OUTSTREAM_RENDERER_URL = 'https://scripts.jixie.media/jxhbrenderer.1.1.
const REQUESTS_URL = 'https://hb.jixie.io/v2/hbpost';
const sidTTLMins_ = 30;

/**
* Get bid floor from Price Floors Module
*
* @param {Object} bid
* @returns {float||null}
*/
function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return null;
}
let floor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
});
if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
return floor.floor;
}
return null;
}

/**
* Own miscellaneous support functions:
*/
Expand Down Expand Up @@ -56,7 +77,7 @@ function fetchIds_() {
if (tmp) ret.client_id_ls = tmp;
tmp = storage.getDataFromLocalStorage('_jxxs');
if (tmp) ret.session_id_ls = tmp;
['_jxtoko', '_jxifo', '_jxtdid', '__uid2_advertising_token'].forEach(function(n) {
['_jxtoko', '_jxifo', '_jxtdid', '_jxcomp'].forEach(function(n) {
tmp = storage.getCookie(n);
if (tmp) ret.jxeids[n] = tmp;
});
Expand Down Expand Up @@ -171,9 +192,12 @@ export const spec = {
params: one.params,
gpid: gpid
};
let bidFloor = getBidFloor(one);
if (bidFloor) {
tmp.bidFloor = bidFloor;
}
bids.push(tmp);
});

let jixieCfgBlob = config.getConfig('jixie');
if (!jixieCfgBlob) {
jixieCfgBlob = {};
Expand Down
25 changes: 21 additions & 4 deletions test/spec/modules/jixieBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import { spec, internal as jixieaux, storage } from 'modules/jixieBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { config } from 'src/config.js';
import { deepClone } from 'src/utils.js';

describe('jixie Adapter', function () {
const pageurl_ = 'https://testdomain.com/testpage.html';
Expand Down Expand Up @@ -74,13 +75,13 @@ describe('jixie Adapter', function () {
const jxtokoTest1_ = 'eyJJRCI6ImFiYyJ9';
const jxifoTest1_ = 'fffffbbbbbcccccaaaaae890606aaaaa';
const jxtdidTest1_ = '222223d1-1111-2222-3333-b9f129299999';
const __uid2_advertising_token_Test1 = 'AAAAABBBBBCCCCCDDDDDEEEEEUkkZPQfifpkPnnlJhtsa4o+gf4nfqgN5qHiTVX73ymTSbLT9jz1nf+Q7QdxNh9nTad9UaN5pzfHMt/rs1woQw72c1ip+8heZXPfKGZtZP7ldJesYhlo3/0FVcL/wl9ZlAo1jYOEfHo7Y9zFzNXABbbbbb==';
const jxcompTest1_ = 'AAAAABBBBBCCCCCDDDDDEEEEEUkkZPQfifpkPnnlJhtsa4o+gf4nfqgN5qHiTVX73ymTSbLT9jz1nf+Q7QdxNh9nTad9UaN5pzfHMt/rs1woQw72c1ip+8heZXPfKGZtZP7ldJesYhlo3/0FVcL/wl9ZlAo1jYOEfHo7Y9zFzNXABbbbbb==';

const refJxEids_ = {
'_jxtoko': jxtokoTest1_,
'_jxifo': jxifoTest1_,
'_jxtdid': jxtdidTest1_,
'__uid2_advertising_token': __uid2_advertising_token_Test1
'_jxcomp': jxcompTest1_
};

// to serve as the object that prebid will call jixie buildRequest with: (param2)
Expand Down Expand Up @@ -237,8 +238,8 @@ describe('jixie Adapter', function () {
.withArgs('_jxtdid')
.returns(jxtdidTest1_);
getCookieStub
.withArgs('__uid2_advertising_token')
.returns(__uid2_advertising_token_Test1);
.withArgs('_jxcomp')
.returns(jxcompTest1_);
getCookieStub
.withArgs('_jxx')
.returns(clientIdTest1_);
Expand Down Expand Up @@ -345,6 +346,22 @@ describe('jixie Adapter', function () {
expect(payload.schain).to.deep.include(schain);
});

it('it should populate the floor info when available', function () {
let oneSpecialBidReq = deepClone(bidRequests_[0]);
let request, payload = null;
// 1 floor is not set
request = spec.buildRequests([oneSpecialBidReq], bidderRequest_);
payload = JSON.parse(request.data);
expect(payload.bids[0].bidFloor).to.not.exist;

// 2 floor is set
let getFloorResponse = { currency: 'USD', floor: 2.1 };
oneSpecialBidReq.getFloor = () => getFloorResponse;
request = spec.buildRequests([oneSpecialBidReq], bidderRequest_);
payload = JSON.parse(request.data);
expect(payload.bids[0].bidFloor).to.exist.and.to.equal(2.1);
});

it('should populate eids when supported userIds are available', function () {
const oneSpecialBidReq = Object.assign({}, bidRequests_[0], {
userIdAsEids: [
Expand Down

0 comments on commit e18ab51

Please sign in to comment.