Skip to content
Open
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
3 changes: 1 addition & 2 deletions modules/imAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,14 @@ const imAnalyticsAdapter = Object.assign(
auction.wonBidsTimer = null;

if (auction.wonBids.length === 0) {
delete cache.auctions[auctionId];
return;
}

const consent = auction.consentData;
const ts = auction.auctionInitTimestamp || Date.now();
const bids = auction.wonBids;
const uid = auction.imUid;
delete cache.auctions[auctionId];
auction.wonBids = [];
sendToApi(buildApiUrlWithOptions(this.options, 'won', auctionId), {
bids,
ts,
Expand Down
16 changes: 8 additions & 8 deletions test/spec/modules/imAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('imAnalyticsAdapter', function() {
expect(requests[0].url).to.include('/won');
});

it('should drop BID_WON for an auction whose cache entry has been cleaned up', function() {
it('should send subsequent BID_WON immediately after initial batch', function() {
const clock = sandbox.useFakeTimers();

imAnalyticsAdapter.track({
Expand All @@ -222,17 +222,16 @@ describe('imAnalyticsAdapter', function() {
args: { auctionId: 'auc-1' }
});

// initial batch sends and deletes cache entry
clock.tick(BID_WON_TIMEOUT + 10);
expect(requests.length).to.equal(1);

// BID_WON after cache cleanup is dropped
// subsequent BID_WON sent immediately via lightweight cache state
imAnalyticsAdapter.track({
eventType: EVENTS.BID_WON,
args: { ...bidWonArgs, requestId: 'req-2' }
});

expect(requests.length).to.equal(1);
expect(requests.length).to.equal(2);
});

it('should deduplicate won bids with same requestId', function() {
Expand Down Expand Up @@ -347,7 +346,7 @@ describe('imAnalyticsAdapter', function() {
expect(requests.length).to.equal(0);
});

it('should drop BID_WON that arrives after timer fired with no bids', function() {
it('should send BID_WON immediately when it arrives after timer fired with no bids', function() {
const clock = sandbox.useFakeTimers();

imAnalyticsAdapter.track({
Expand All @@ -361,17 +360,18 @@ describe('imAnalyticsAdapter', function() {
args: { auctionId: 'auc-1' }
});

// timer fires with no bids, cache entry is deleted
// timer fires with no bids, lightweight cache state is kept
clock.tick(BID_WON_TIMEOUT + 10);
expect(requests.length).to.equal(0);

// late BID_WON is dropped after cache cleanup
// late BID_WON sent immediately via lightweight cache state
imAnalyticsAdapter.track({
eventType: EVENTS.BID_WON,
args: { ...bidWonArgs, requestId: 'req-1' }
});

expect(requests.length).to.equal(0);
expect(requests.length).to.equal(1);
expect(requests[0].url).to.include('/won');
});
});
});
Expand Down
Loading