Skip to content

Commit

Permalink
KRKPD-1247: sends refererInfo to Kraken (prebid#36) (prebid#11725)
Browse files Browse the repository at this point in the history
* sends refererInfo to kraken

* minor change

* removes comment
  • Loading branch information
nickllerandi authored and DecayConstant committed Jul 18, 2024
1 parent 53bc68f commit d5b5ee0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
24 changes: 16 additions & 8 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,13 @@ function buildRequests(validBidRequests, bidderRequest) {
]
},
imp: impressions,
user: getUserIds(tdidAdapter, bidderRequest.uspConsent, bidderRequest.gdprConsent, firstBidRequest.userIdAsEids, bidderRequest.gppConsent)
user: getUserIds(tdidAdapter, bidderRequest.uspConsent, bidderRequest.gdprConsent, firstBidRequest.userIdAsEids, bidderRequest.gppConsent),
ext: getExtensions(firstBidRequest.ortb2, bidderRequest?.refererInfo)
});

// Add full ortb2 object as backup
if (firstBidRequest.ortb2) {
const siteCat = firstBidRequest.ortb2.site?.cat;
if (siteCat != null) {
krakenParams.site = { cat: siteCat };
}
krakenParams.ext = { ortb2: firstBidRequest.ortb2 };
// Add site.cat if it exists
if (firstBidRequest.ortb2?.site?.cat != null) {
krakenParams.site = { cat: firstBidRequest.ortb2.site.cat };
}

// Add schain
Expand Down Expand Up @@ -186,6 +183,10 @@ function buildRequests(validBidRequests, bidderRequest) {
krakenParams.page = page;
}

if (krakenParams.ext && Object.keys(krakenParams.ext).length === 0) {
delete krakenParams.ext;
}

return Object.assign({}, bidderRequest, {
method: BIDDER.REQUEST_METHOD,
url: `https://${BIDDER.HOST}${BIDDER.REQUEST_ENDPOINT}`,
Expand Down Expand Up @@ -300,6 +301,13 @@ function onTimeout(timeoutData) {
});
}

function getExtensions(ortb2, refererInfo) {
const ext = {};
if (ortb2) ext.ortb2 = ortb2;
if (refererInfo) ext.refererInfo = refererInfo;
return ext;
}

function _generateRandomUUID() {
try {
// crypto.getRandomValues is supported everywhere but Opera Mini for years
Expand Down
36 changes: 30 additions & 6 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ describe('kargo adapter tests', function() {
domain,
isAmp: false,
location: topUrl,
numIframs: 0,
numIframes: 0,
page: topUrl,
reachedTop: true,
ref: referer,
Expand Down Expand Up @@ -428,12 +428,12 @@ describe('kargo adapter tests', function() {
}
}
}]);
expect(payload.ext).to.deep.equal({ ortb2: {
expect(payload.ext.ortb2).to.deep.equal({
user: { key: 'value' }
}});
});

payload = getPayloadFromTestBids(testBids);
expect(payload.ext).to.be.undefined;
expect(payload.ext.ortb2).to.be.undefined;

payload = getPayloadFromTestBids([{
...minimumBidParams,
Expand All @@ -450,9 +450,33 @@ describe('kargo adapter tests', function() {
}
}
}]);
expect(payload.ext).to.deep.equal({ortb2: {
expect(payload.ext.ortb2).to.deep.equal({
user: { key: 'value' }
}});
}
);
});

it('copies the refererInfo object from bidderRequest if present', function() {
let payload;
payload = getPayloadFromTestBids(testBids);
expect(payload.ext.refererInfo).to.deep.equal({
canonicalUrl: 'https://random.com/this/is/a/url',
domain: 'random.com',
isAmp: false,
location: 'https://random.com/this/is/a/url',
numIframes: 0,
page: 'https://random.com/this/is/a/url',
reachedTop: true,
ref: 'https://random.com/',
stack: [
'https://random.com/this/is/a/url'
],
topmostLocation: 'https://random.com/this/is/a/url'
});

delete bidderRequest.refererInfo
payload = getPayloadFromTestBids(testBids);
expect(payload.ext).to.be.undefined;
});

it('pulls the site category from the first bids ortb2 object', function() {
Expand Down

0 comments on commit d5b5ee0

Please sign in to comment.