Skip to content

Commit

Permalink
kargo session id (prebid#3897)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhorwitz authored and sa1omon committed Nov 28, 2019
1 parent 2deb3be commit f23056d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const spec = {
bidSizes[bid.bidId] = bid.sizes;
});
const transformedParams = Object.assign({}, {
sessionId: spec._getSessionId(),
timeout: bidderRequest.timeout,
currency: currency,
cpmGranularity: 1,
Expand Down Expand Up @@ -183,6 +184,13 @@ export const spec = {
};
},

_getSessionId() {
if (!spec._sessionId) {
spec._sessionId = spec._generateRandomUuid();
}
return spec._sessionId;
},

_generateRandomUuid() {
try {
// crypto.getRandomValues is supported everywhere but Opera Mini for years
Expand Down
16 changes: 15 additions & 1 deletion test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('kargo adapter tests', function () {
});

describe('build request', function() {
var bids, undefinedCurrency, noAdServerCurrency, cookies = [], localStorageItems = [];
var bids, undefinedCurrency, noAdServerCurrency, cookies = [], localStorageItems = [], sessionIds = [];

beforeEach(function () {
undefinedCurrency = false;
Expand Down Expand Up @@ -212,6 +212,10 @@ describe('kargo adapter tests', function () {
setCookie('krg_crb', getEmptyKrgCrbOldStyle());
}

function getSessionId() {
return spec._sessionId;
}

function getExpectedKrakenParams(excludeUserIds, excludeKrux, expectedRawCRB, expectedRawCRBCookie) {
var base = {
timeout: 200,
Expand Down Expand Up @@ -302,6 +306,8 @@ describe('kargo adapter tests', function () {

function testBuildRequests(expected) {
var request = spec.buildRequests(bids, {timeout: 200, foo: 'bar'});
expected.sessionId = getSessionId();
sessionIds.push(expected.sessionId);
var krakenParams = JSON.parse(decodeURIComponent(request.data.slice(5)));
expect(request.data.slice(0, 5)).to.equal('json=');
expect(request.url).to.equal('https://krk.kargo.com/api/v2/bid');
Expand All @@ -310,6 +316,14 @@ describe('kargo adapter tests', function () {
expect(request.timeout).to.equal(200);
expect(request.foo).to.equal('bar');
expect(krakenParams).to.deep.equal(expected);
// Make sure session ID stays the same across requests simulating multiple auctions on one page load
for (let i in sessionIds) {
if (i == 0) {
continue;
}
let sessionId = sessionIds[i];
expect(sessionIds[0]).to.equal(sessionId);
}
}

it('works when all params and localstorage and cookies are correctly set', function() {
Expand Down

0 comments on commit f23056d

Please sign in to comment.