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

ReadPeak Bid Adapter: fix api issues, add gdpr consent, & getfloor module support #6548

Merged
merged 6 commits into from
Apr 9, 2021
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
31 changes: 29 additions & 2 deletions modules/readpeakBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export const spec = {
}
};

if (bidderRequest.gdprConsent) {
request.user = {
ext: {
consent: bidderRequest.gdprConsent.consentString || ''
},
};
request.regs = {
ext: {
gdpr: bidderRequest.gdprConsent.gdprApplies !== undefined ? bidderRequest.gdprConsent.gdprApplies : true
}
};
}

return {
method: 'POST',
url: ENDPOINT,
Expand Down Expand Up @@ -87,18 +100,32 @@ function bidResponseAvailable(bidRequest, bidResponse) {
currency: bidResponse.cur,
native: nativeResponse(idToImpMap[id], idToBidMap[id])
};
if (idToBidMap[id].adomain) {
bid.meta = {
advertiserDomains: idToBidMap[id].adomain
}
}
bids.push(bid);
}
});
return bids;
}

function impression(slot) {
let bidFloorFromModule
if (typeof slot.getFloor === 'function') {
const floorInfo = slot.getFloor({
currency: 'USD',
mediaType: 'native',
size: '\*'
});
bidFloorFromModule = floorInfo.currency === 'USD' ? floorInfo.floor : undefined;
}
return {
id: slot.bidId,
native: nativeImpression(slot),
bidfloor: slot.params.bidfloor || 0,
bidfloorcur: slot.params.bidfloorcur || 'USD',
bidfloor: bidFloorFromModule || slot.params.bidfloor || 0,
bidfloorcur: (bidFloorFromModule && 'USD') || slot.params.bidfloorcur || 'USD',
tagId: slot.params.tagId || '0'
};
}
Expand Down
70 changes: 70 additions & 0 deletions test/spec/modules/readpeakBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,73 @@ describe('ReadPeakAdapter', function() {
language: navigator.language
});
expect(data.cur).to.deep.equal(['EUR']);
expect(data.user).to.be.undefined;
expect(data.regs).to.be.undefined;
});

it('should get bid floor from module', function() {
const floorModuleData = {
currency: 'USD',
floor: 3.2,
}
bidRequest.getFloor = function () {
return floorModuleData
}
const request = spec.buildRequests([bidRequest], bidderRequest);

const data = JSON.parse(request.data);

expect(data.source.ext.prebid).to.equal('$prebid.version$');
expect(data.id).to.equal(bidRequest.bidderRequestId);
expect(data.imp[0].bidfloor).to.equal(floorModuleData.floor);
expect(data.imp[0].bidfloorcur).to.equal(floorModuleData.currency);
});

it('should send gdpr data when gdpr does not apply', function() {
const gdprData = {
gdprConsent: {
gdprApplies: false,
consentString: undefined,
}
}
const request = spec.buildRequests([bidRequest], {...bidderRequest, ...gdprData});

const data = JSON.parse(request.data);

expect(data.user).to.deep.equal({
ext: {
consent: ''
}
});
expect(data.regs).to.deep.equal({
ext: {
gdpr: false
}
});
});

it('should send gdpr data when gdpr applies', function() {
const tcString = 'sometcstring';
const gdprData = {
gdprConsent: {
gdprApplies: true,
consentString: tcString
}
}
const request = spec.buildRequests([bidRequest], {...bidderRequest, ...gdprData});

const data = JSON.parse(request.data);

expect(data.user).to.deep.equal({
ext: {
consent: tcString
}
});
expect(data.regs).to.deep.equal({
ext: {
gdpr: true
}
});
});
});

Expand All @@ -213,6 +280,9 @@ describe('ReadPeakAdapter', function() {
currency: serverResponse.cur
});

expect(bidResponse.meta).to.deep.equal({
advertiserDomains: ['readpeak.com'],
})
expect(bidResponse.native.title).to.equal('Title');
expect(bidResponse.native.body).to.equal('Description');
expect(bidResponse.native.image).to.deep.equal({
Expand Down