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 Bid Adapter: sends refererInfo #11725

Merged
merged 1 commit into from
Jun 6, 2024
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
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