Skip to content

priceFloors: fix bug where floors are not set when TIDs are disabled #10257

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

Merged
merged 1 commit into from
Jul 20, 2023
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
1 change: 0 additions & 1 deletion integrationExamples/gpt/adUnitFloors.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,3 @@ <h5>Div-1</h5>
</body>

</html>

14 changes: 11 additions & 3 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function registerBidder(spec) {
}
}

function guardTids(bidderCode) {
export function guardTids(bidderCode) {
if (isActivityAllowed(ACTIVITY_TRANSMIT_TID, activityParams(MODULE_TYPE_BIDDER, bidderCode))) {
return {
bidRequest: (br) => br,
Expand All @@ -197,7 +197,15 @@ function guardTids(bidderCode) {
}
return Reflect.get(target, prop, receiver);
}
const bidRequest = memoize((br) => new Proxy(br, {get}), (arg) => arg.bidId)
function privateAccessProxy(target, handler) {
const proxy = new Proxy(target, handler);
// always allow methods (such as getFloor) private access to TIDs
Object.entries(target)
.filter(([_, v]) => typeof v === 'function')
.forEach(([prop, fn]) => proxy[prop] = fn.bind(target));
return proxy;
}
const bidRequest = memoize((br) => privateAccessProxy(br, {get}), (arg) => arg.bidId);
/**
* Return a view on bidd(er) requests where auctionId/transactionId are nulled if the bidder is not allowed `transmitTid`.
*
Expand All @@ -207,7 +215,7 @@ function guardTids(bidderCode) {
*/
return {
bidRequest,
bidderRequest: (br) => new Proxy(br, {
bidderRequest: (br) => privateAccessProxy(br, {
get(target, prop, receiver) {
if (prop === 'bids') return br.bids.map(bidRequest);
return get(target, prop, receiver);
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'src/prebid.js';
import {createBid} from '../../../src/bidfactory.js';
import {auctionManager} from '../../../src/auctionManager.js';
import {stubAuctionIndex} from '../../helpers/indexStub.js';
import {guardTids} from '../../../src/adapters/bidderFactory.js';
import * as activities from '../../../src/activities/rules.js';

describe('the price floors module', function () {
let logErrorSpy;
Expand Down Expand Up @@ -1369,6 +1371,18 @@ describe('the price floors module', function () {
floor: 2.5
});
});

it('works when TIDs are disabled', () => {
sandbox.stub(activities, 'isActivityAllowed').returns(false);
const req = utils.deepClone(bidRequest);
_floorDataForAuction[req.auctionId] = utils.deepClone(basicFloorConfig);

expect(guardTids('mock-bidder').bidRequest(req).getFloor({})).to.deep.equal({
currency: 'USD',
floor: 1.0
});
});

it('picks the right rule with more complex rules', function () {
_floorDataForAuction[bidRequest.auctionId] = {
...basicFloorConfig,
Expand Down
56 changes: 42 additions & 14 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {stubAuctionIndex} from '../../../helpers/indexStub.js';
import {bidderSettings} from '../../../../src/bidderSettings.js';
import {decorateAdUnitsWithNativeParams} from '../../../../src/native.js';
import * as activityRules from 'src/activities/rules.js';
import {sandbox} from 'sinon';
import {MODULE_TYPE_BIDDER} from '../../../../src/activities/modules.js';
import {ACTIVITY_TRANSMIT_TID} from '../../../../src/activities/activities.js';

Expand Down Expand Up @@ -141,6 +140,21 @@ describe('bidders created by newBidder', function () {
});

describe('transaction IDs', () => {
beforeEach(() => {
activityRules.isActivityAllowed.reset();
ajaxStub.callsFake((_, callback) => callback.success(null, {getResponseHeader: sinon.stub()}));
spec.interpretResponse.callsFake(() => [
{
requestId: 'bid',
cpm: 123,
ttl: 300,
creativeId: 'crid',
netRevenue: true,
currency: 'USD'
}
])
});

Object.entries({
'be hidden': false,
'not be hidden': true,
Expand All @@ -166,21 +180,8 @@ describe('bidders created by newBidder', function () {
bidReqs.forEach(checkBidRequest);
return {method: 'POST'};
});
spec.interpretResponse.callsFake(() => [
{
requestId: 'bid',
cpm: 123,
ttl: 300,
creativeId: 'crid',
netRevenue: true,
currency: 'USD'
}
])
activityRules.isActivityAllowed.reset();
activityRules.isActivityAllowed.callsFake(() => allowed);

ajaxStub.callsFake((_, callback) => callback.success(null, {getResponseHeader: sinon.stub()}));

const bidder = newBidder(spec);

bidder.callBids({
Expand All @@ -206,6 +207,33 @@ describe('bidders created by newBidder', function () {
})
});
});

it('should not be hidden from request methods', (done) => {
const bidderRequest = {
bidderCode: 'mockBidder',
auctionId: 'aid',
getAID() { return this.auctionId },
bids: [
{
adUnitCode: 'mockAU',
bidId: 'bid',
transactionId: 'tid',
auctionId: 'aid',
getTIDs() {
return [this.auctionId, this.transactionId]
}
}
]
};
activityRules.isActivityAllowed.callsFake(() => false);
spec.isBidRequestValid.returns(true);
spec.buildRequests.callsFake((reqs, bidderReq) => {
expect(bidderReq.getAID()).to.eql('aid');
expect(reqs[0].getTIDs()).to.eql(['aid', 'tid']);
done();
});
newBidder(spec).callBids(bidderRequest, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
})
});

it('should handle bad bid requests gracefully', function () {
Expand Down