diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index 5c3d59bd241..63406bf3ce4 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -22,6 +22,10 @@ export const spec = { bidIds[bid.bidId] = bid.params.placementId; bidSizes[bid.bidId] = bid.sizes; }); + let tdid; + if (validBidRequests.length > 0 && validBidRequests[0].userId && validBidRequests[0].userId.tdid) { + tdid = validBidRequests[0].userId.tdid; + } const transformedParams = Object.assign({}, { sessionId: spec._getSessionId(), timeout: bidderRequest.timeout, @@ -35,7 +39,7 @@ export const spec = { bidIDs: bidIds, bidSizes: bidSizes, prebidRawBidRequests: validBidRequests - }, spec._getAllMetadata()); + }, spec._getAllMetadata(tdid)); const encodedParams = encodeURIComponent(JSON.stringify(transformedParams)); return Object.assign({}, bidderRequest, { method: 'GET', @@ -159,14 +163,18 @@ export const spec = { } }, - _getUserIds() { + _getUserIds(tdid) { const crb = spec._getCrb(); - return { + const userIds = { kargoID: crb.userId, clientID: crb.clientId, crbIDs: crb.syncIds || {}, optOut: crb.optOut }; + if (tdid) { + userIds.tdID = tdid; + } + return userIds; }, _getClientId() { @@ -174,9 +182,9 @@ export const spec = { return crb.clientId; }, - _getAllMetadata() { + _getAllMetadata(tdid) { return { - userIDs: spec._getUserIds(), + userIDs: spec._getUserIds(tdid), krux: spec._getKrux(), pageURL: window.location.href, rawCRB: spec._readCookie('krg_crb'), diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index a6779f518a0..92f68fd9b91 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -58,6 +58,9 @@ describe('kargo adapter tests', function () { placementId: 'foo' }, bidId: 1, + userId: { + tdid: 'fake-tdid' + }, sizes: [[320, 50], [300, 250], [300, 600]] }, { @@ -239,6 +242,7 @@ describe('kargo adapter tests', function () { userIDs: { kargoID: '5f108831-302d-11e7-bf6b-4595acd3bf6c', clientID: '2410d8f2-c111-4811-88a5-7b5e190e475f', + tdID: 'fake-tdid', crbIDs: { 2: '82fa2555-5969-4614-b4ce-4dcf1080e9f9', 16: 'VoxIk8AoJz0AAEdCeyAAAAC2&502', @@ -267,6 +271,9 @@ describe('kargo adapter tests', function () { params: { placementId: 'foo' }, + userId: { + tdid: 'fake-tdid' + }, sizes: [[320, 50], [300, 250], [300, 600]] }, { @@ -292,6 +299,7 @@ describe('kargo adapter tests', function () { base.userIDs = { crbIDs: {} }; + delete base.prebidRawBidRequests[0].userId.tdid; } if (excludeKrux) { @@ -304,8 +312,12 @@ describe('kargo adapter tests', function () { return base; } - function testBuildRequests(expected) { - var request = spec.buildRequests(bids, {timeout: 200, foo: 'bar'}); + function testBuildRequests(excludeTdid, expected) { + var clonedBids = JSON.parse(JSON.stringify(bids)); + if (excludeTdid) { + delete clonedBids[0].userId.tdid; + } + var request = spec.buildRequests(clonedBids, {timeout: 200, foo: 'bar'}); expected.sessionId = getSessionId(); sessionIds.push(expected.sessionId); var krakenParams = JSON.parse(decodeURIComponent(request.data.slice(5))); @@ -330,23 +342,23 @@ describe('kargo adapter tests', function () { initializeKruxUser(); initializeKruxSegments(); initializeKrgCrb(); - testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); + testBuildRequests(false, getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); }); it('works when all params and cookies are correctly set but no localstorage', function() { initializeKruxUser(); initializeKruxSegments(); initializeKrgCrb(true); - testBuildRequests(getExpectedKrakenParams(undefined, undefined, null, getKrgCrbOldStyle())); + testBuildRequests(false, getExpectedKrakenParams(undefined, undefined, null, getKrgCrbOldStyle())); }); it('gracefully handles nothing being set', function() { - testBuildRequests(getExpectedKrakenParams(true, true, null, null)); + testBuildRequests(true, getExpectedKrakenParams(true, true, null, null)); }); it('gracefully handles browsers without localStorage', function() { simulateNoLocalStorage(); - testBuildRequests(getExpectedKrakenParams(true, true, null, null)); + testBuildRequests(true, getExpectedKrakenParams(true, true, null, null)); }); it('handles empty yet valid Kargo CRB', function() { @@ -354,49 +366,49 @@ describe('kargo adapter tests', function () { initializeKruxSegments(); initializeEmptyKrgCrb(); initializeEmptyKrgCrbCookie(); - testBuildRequests(getExpectedKrakenParams(true, undefined, getEmptyKrgCrb(), getEmptyKrgCrbOldStyle())); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, getEmptyKrgCrb(), getEmptyKrgCrbOldStyle())); }); it('handles broken Kargo CRBs where base64 encoding is invalid', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType1(); - testBuildRequests(getExpectedKrakenParams(true, undefined, getInvalidKrgCrbType1(), null)); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, getInvalidKrgCrbType1(), null)); }); it('handles broken Kargo CRBs where top level JSON is invalid on cookie', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType1Cookie(); - testBuildRequests(getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType1())); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType1())); }); it('handles broken Kargo CRBs where decoded JSON is invalid', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType2(); - testBuildRequests(getExpectedKrakenParams(true, undefined, getInvalidKrgCrbType2(), null)); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, getInvalidKrgCrbType2(), null)); }); it('handles broken Kargo CRBs where inner base 64 is invalid on cookie', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType2Cookie(); - testBuildRequests(getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType2OldStyle())); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType2OldStyle())); }); it('handles broken Kargo CRBs where inner JSON is invalid on cookie', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType3Cookie(); - testBuildRequests(getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType3OldStyle())); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType3OldStyle())); }); it('handles broken Kargo CRBs where inner JSON is falsey', function() { initializeKruxUser(); initializeKruxSegments(); initializeInvalidKrgCrbType4Cookie(); - testBuildRequests(getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType4OldStyle())); + testBuildRequests(true, getExpectedKrakenParams(true, undefined, null, getInvalidKrgCrbType4OldStyle())); }); it('handles a non-existant currency object on the config', function() { @@ -404,7 +416,7 @@ describe('kargo adapter tests', function () { initializeKruxUser(); initializeKruxSegments(); initializeKrgCrb(); - testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); + testBuildRequests(false, getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); }); it('handles no ad server currency being set on the currency object in the config', function() { @@ -412,7 +424,7 @@ describe('kargo adapter tests', function () { initializeKruxUser(); initializeKruxSegments(); initializeKrgCrb(); - testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); + testBuildRequests(false, getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle())); }); });