Skip to content

Commit

Permalink
ReadPeak Bid Adapter: fix api issues, add gdpr consent, & getfloor mo…
Browse files Browse the repository at this point in the history
…dule support (#6548)
  • Loading branch information
readpeaktuomo authored and idettman committed May 21, 2021
1 parent 163238a commit 3bf1be4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
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

0 comments on commit 3bf1be4

Please sign in to comment.