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

Kargo session id #3897

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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