Skip to content

Commit

Permalink
adding tdid support (prebid#3981)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhorwitz authored and leonardlabat committed Jul 30, 2019
1 parent 97f497c commit bc5998a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
18 changes: 13 additions & 5 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -159,24 +163,28 @@ 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() {
const crb = spec._getCrb();
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'),
Expand Down
42 changes: 27 additions & 15 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ describe('kargo adapter tests', function () {
placementId: 'foo'
},
bidId: 1,
userId: {
tdid: 'fake-tdid'
},
sizes: [[320, 50], [300, 250], [300, 600]]
},
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -267,6 +271,9 @@ describe('kargo adapter tests', function () {
params: {
placementId: 'foo'
},
userId: {
tdid: 'fake-tdid'
},
sizes: [[320, 50], [300, 250], [300, 600]]
},
{
Expand All @@ -292,6 +299,7 @@ describe('kargo adapter tests', function () {
base.userIDs = {
crbIDs: {}
};
delete base.prebidRawBidRequests[0].userId.tdid;
}

if (excludeKrux) {
Expand All @@ -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)));
Expand All @@ -330,89 +342,89 @@ 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() {
initializeKruxUser();
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() {
simulateNoCurrencyObject();
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() {
simulateNoAdServerCurrency();
initializeKruxUser();
initializeKruxSegments();
initializeKrgCrb();
testBuildRequests(getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle()));
testBuildRequests(false, getExpectedKrakenParams(undefined, undefined, getKrgCrb(), getKrgCrbOldStyle()));
});
});

Expand Down

0 comments on commit bc5998a

Please sign in to comment.