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

Rubicon Analytics: Add option to delay sending of event message #6344

Merged
merged 1 commit into from
Feb 23, 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
15 changes: 10 additions & 5 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const cache = {
const BID_REJECTED_IPF = 'rejected-ipf';

export let rubiConf = {
pvid: utils.generateUUID().slice(0, 8)
pvid: utils.generateUUID().slice(0, 8),
analyticsEventDelay: 0
};
// we are saving these as global to this module so that if a pub accidentally overwrites the entire
// rubicon object, then we do not lose other data
Expand Down Expand Up @@ -487,7 +488,11 @@ function subscribeToGamSlots() {
if (rubiConf.waitForGamSlots && !cache.auctions[auctionId].sent && Object.keys(cache.auctions[auctionId].gamHasRendered).every(adUnitCode => cache.auctions[auctionId].gamHasRendered[adUnitCode])) {
clearTimeout(cache.timeouts[auctionId]);
delete cache.timeouts[auctionId];
sendMessage.call(rubiconAdapter, auctionId);
if (rubiConf.analyticsEventDelay > 0) {
setTimeout(() => sendMessage.call(rubiconAdapter, auctionId), rubiConf.analyticsEventDelay)
} else {
sendMessage.call(rubiconAdapter, auctionId)
}
}
});
});
Expand Down Expand Up @@ -568,9 +573,9 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
cache.gpt.registered = true;
} else if (!cache.gpt.registered) {
cache.gpt.registered = true;
let googletag = window.googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
window.googletag = window.googletag || {};
window.googletag.cmd = window.googletag.cmd || [];
window.googletag.cmd.push(function() {
subscribeToGamSlots();
});
}
Expand Down
52 changes: 50 additions & 2 deletions test/spec/modules/rubiconAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ describe('rubicon analytics adapter', function () {
}
});
expect(rubiConf).to.deep.equal({
analyticsEventDelay: 0,
pvid: '12345678',
wrapperName: '1001_general',
int_type: 'dmpbjs',
Expand All @@ -654,6 +655,7 @@ describe('rubicon analytics adapter', function () {
}
});
expect(rubiConf).to.deep.equal({
analyticsEventDelay: 0,
pvid: '12345678',
wrapperName: '1001_general',
int_type: 'dmpbjs',
Expand All @@ -674,6 +676,7 @@ describe('rubicon analytics adapter', function () {
}
});
expect(rubiConf).to.deep.equal({
analyticsEventDelay: 0,
pvid: '12345678',
wrapperName: '1001_general',
int_type: 'dmpbjs',
Expand Down Expand Up @@ -1500,7 +1503,7 @@ describe('rubicon analytics adapter', function () {
it('should send request when waitForGamSlots is present but no bidWons are sent', function () {
config.setConfig({
rubicon: {
waitForGamSlots: true
waitForGamSlots: true,
}
});
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
Expand All @@ -1511,7 +1514,7 @@ describe('rubicon analytics adapter', function () {
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);

// should not send if just slotRenderEnded is emmitted for both
// should send if just slotRenderEnded is emmitted for both
mockGpt.emitEvent(gptSlotRenderEnded0.eventName, gptSlotRenderEnded0.params);
mockGpt.emitEvent(gptSlotRenderEnded1.eventName, gptSlotRenderEnded1.params);

Expand All @@ -1536,6 +1539,51 @@ describe('rubicon analytics adapter', function () {
};
expect(message).to.deep.equal(expectedMessage);
});

it('should delay the event call depending on analyticsEventDelay config', function () {
config.setConfig({
rubicon: {
waitForGamSlots: true,
analyticsEventDelay: 2000
}
});
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]);
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
events.emit(SET_TARGETING, MOCK.SET_TARGETING);

// should send if just slotRenderEnded is emmitted for both
mockGpt.emitEvent(gptSlotRenderEnded0.eventName, gptSlotRenderEnded0.params);
mockGpt.emitEvent(gptSlotRenderEnded1.eventName, gptSlotRenderEnded1.params);

// Should not be sent until delay
expect(server.requests.length).to.equal(0);

// tick the clock and it should fire
clock.tick(2000);

expect(server.requests.length).to.equal(1);
let request = server.requests[0];
let message = JSON.parse(request.requestBody);
validate(message);
let expectedGam0 = {
advertiserId: 1111,
creativeId: 2222,
lineItemId: 3333,
adSlot: '/19968336/header-bid-tag-0'
};
let expectedGam1 = {
advertiserId: 4444,
creativeId: 5555,
lineItemId: 6666,
adSlot: '/19968336/header-bid-tag1'
};
expect(expectedGam0).to.deep.equal(message.auctions[0].adUnits[0].gam);
expect(expectedGam1).to.deep.equal(message.auctions[0].adUnits[1].gam);
});
});

it('should correctly overwrite bidId if seatBidId is on the bidResponse', function () {
Expand Down