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

Prebid Core: Added TTL validation for suppressing expired ads #12532

Merged
merged 2 commits into from
Dec 4, 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
11 changes: 10 additions & 1 deletion src/adRendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import {fireNativeTrackers} from './native.js';
import {GreedyPromise} from './utils/promise.js';
import adapterManager from './adapterManager.js';
import {useMetrics} from './utils/perfMetrics.js';
import {filters} from './targeting.js';

const { AD_RENDER_FAILED, AD_RENDER_SUCCEEDED, STALE_RENDER, BID_WON } = EVENTS;
const { AD_RENDER_FAILED, AD_RENDER_SUCCEEDED, STALE_RENDER, BID_WON, EXPIRED_RENDER } = EVENTS;
const { EXCEPTION } = AD_RENDER_FAILED_REASON;

export const getBidToRender = hook('sync', function (adId, forRender = true, override = GreedyPromise.resolve()) {
Expand Down Expand Up @@ -185,6 +186,14 @@ export function handleRender({renderFn, resizeFn, adId, options, bidResponse, do
return;
}
}
if (!filters.isBidNotExpired(bidResponse)) {
logWarn(`Ad id ${adId} has been expired`);
events.emit(EXPIRED_RENDER, bidResponse);
if (deepAccess(config.getConfig('auctionOptions'), 'suppressExpiredRender')) {
return;
}
}

try {
doRender({renderFn, resizeFn, bidResponse, options, doc});
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function attachProperties(config, useDefaultValues = true) {
}

for (let k of Object.keys(val)) {
if (k !== 'secondaryBidders' && k !== 'suppressStaleRender') {
if (k !== 'secondaryBidders' && k !== 'suppressStaleRender' && k !== 'suppressExpiredRender') {
logWarn(`Auction Options given an incorrect param: ${k}`)
return false
}
Expand All @@ -191,7 +191,7 @@ function attachProperties(config, useDefaultValues = true) {
logWarn(`Auction Options ${k} must be only string`);
return false
}
} else if (k === 'suppressStaleRender') {
} else if (k === 'suppressStaleRender' || k === 'suppressExpiredRender') {
if (!isBoolean(val[k])) {
logWarn(`Auction Options ${k} must be of type boolean`);
return false;
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const EVENTS = {
AUCTION_DEBUG: 'auctionDebug',
BID_VIEWABLE: 'bidViewable',
STALE_RENDER: 'staleRender',
EXPIRED_RENDER: 'expiredRender',
BILLABLE_EVENT: 'billableEvent',
BID_ACCEPTED: 'bidAccepted',
RUN_PAAPI_AUCTION: 'paapiRunAuction',
Expand Down
17 changes: 17 additions & 0 deletions test/spec/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ describe('config API', function () {
expect(getConfig('auctionOptions')).to.eql(auctionOptionsConfig);
});

it('sets auctionOptions suppressExpiredRender', function () {
const auctionOptionsConfig = {
'suppressExpiredRender': true
}
setConfig({ auctionOptions: auctionOptionsConfig });
expect(getConfig('auctionOptions')).to.eql(auctionOptionsConfig);
});

it('should log warning for the wrong value passed to auctionOptions', function () {
setConfig({ auctionOptions: '' });
expect(logWarnSpy.calledOnce).to.equal(true);
Expand All @@ -370,6 +378,15 @@ describe('config API', function () {
assert.ok(logWarnSpy.calledWith(warning), 'expected warning was logged');
});

it('should log warning for invalid auctionOptions suppress expired render', function () {
setConfig({ auctionOptions: {
'suppressExpiredRender': 'test',
}});
expect(logWarnSpy.calledOnce).to.equal(true);
const warning = 'Auction Options suppressExpiredRender must be of type boolean';
assert.ok(logWarnSpy.calledWith(warning), 'expected warning was logged');
});

it('should log warning for invalid properties to auctionOptions', function () {
setConfig({ auctionOptions: {
'testing': true
Expand Down
21 changes: 21 additions & 0 deletions test/spec/unit/adRendering_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {config} from 'src/config.js';
import {VIDEO} from '../../../src/mediaTypes.js';
import {auctionManager} from '../../../src/auctionManager.js';
import adapterManager from '../../../src/adapterManager.js';
import {filters} from 'src/targeting.js';

describe('adRendering', () => {
let sandbox;
Expand Down Expand Up @@ -309,6 +310,26 @@ describe('adRendering', () => {
sinon.assert.notCalled(doRenderStub);
})
});

describe('when bid has already expired', () => {
let isBidNotExpiredStub = sinon.stub(filters, 'isBidNotExpired');
beforeEach(() => {
isBidNotExpiredStub.returns(false);
});
afterEach(() => {
isBidNotExpiredStub.restore();
})
it('should emit EXPIRED_RENDER', () => {
handleRender({adId, bidResponse});
sinon.assert.calledWith(events.emit, EVENTS.EXPIRED_RENDER, bidResponse);
sinon.assert.called(doRenderStub);
});
it('should skip rendering if suppressExpiredRender', () => {
config.setConfig({auctionOptions: {suppressExpiredRender: true}});
handleRender({adId, bidResponse});
sinon.assert.notCalled(doRenderStub);
})
});
})
})

Expand Down
Loading