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: emitting BEFORE_BIDDER_HTTP event per bidder network request #7296

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 0 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export function newBidder(spec) {
// Server requests have returned and been processed. Since `ajax` accepts a single callback,
// we need to rig up a function which only executes after all the requests have been responded.
const onResponse = delayExecution(configEnabledCallback(afterAllResponses), requests.length)
requests.forEach(_ => events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP, bidderRequest));
requests.forEach(processRequest);

function formatGetParameters(data) {
Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"BIDDER_DONE": "bidderDone",
"SET_TARGETING": "setTargeting",
"BEFORE_REQUEST_BIDS": "beforeRequestBids",
"BEFORE_BIDDER_HTTP": "beforeBidderHttp",
"REQUEST_BIDS": "requestBids",
"ADD_AD_UNITS": "addAdUnits",
"AD_RENDER_FAILED": "adRenderFailed",
Expand Down
24 changes: 24 additions & 0 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { userSync } from 'src/userSync.js'
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
import { server } from 'test/mocks/xhr.js';
import CONSTANTS from 'src/constants.json';
import events from 'src/events.js';

const CODE = 'sampleBidder';
const MOCK_BIDS_REQUEST = {
Expand Down Expand Up @@ -314,6 +316,28 @@ describe('bidders created by newBidder', function () {

expect(addBidResponseStub.callCount).to.equal(0);
});

it('should emit BEFORE_BIDDER_HTTP events before network requests', function () {
const bidder = newBidder(spec);
const req = {
method: 'POST',
url: 'test.url.com',
data: { arg: 2 }
};

spec.isBidRequestValid.returns(true);
spec.buildRequests.returns([req, req]);

const eventEmitterSpy = sinon.spy(events, 'emit');
bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);

expect(ajaxStub.calledTwice).to.equal(true);
expect(eventEmitterSpy.getCalls()
.filter(call => call.args[0] === CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP)
).to.length(2);

eventEmitterSpy.restore();
});
});

describe('when the ajax call succeeds', function () {
Expand Down