Skip to content
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: 6 additions & 9 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const ADRENDERFAILEDSENT = 16;
let initOptions;
const prebidGlobal = getGlobal();
export const BID_WON_TIMEOUT = 500;
const CACHE_CLEANUP_DELAY = BID_WON_TIMEOUT * 3;

const cache = {
auctions: {}
Expand Down Expand Up @@ -160,6 +159,7 @@ const livewrappedAnalyticsAdapter = Object.assign(adapter({ EMPTYURL, ANALYTICST
// save the base class function
livewrappedAnalyticsAdapter.originEnableAnalytics = livewrappedAnalyticsAdapter.enableAnalytics;
livewrappedAnalyticsAdapter.allRequestEvents = [];
const baseClearAllAuctions = prebidGlobal.clearAllAuctions;

// override enableAnalytics so we can get access to the config passed in from the page
livewrappedAnalyticsAdapter.enableAnalytics = function (config) {
Expand Down Expand Up @@ -191,12 +191,6 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
}

ajax(initOptions.endpoint || URL, undefined, JSON.stringify(events), { method: 'POST' });

setTimeout(() => {
sentRequests.auctionIds.forEach(id => {
delete cache.auctions[id];
});
}, CACHE_CLEANUP_DELAY);
};

function getMediaTypeEnum(mediaType) {
Expand Down Expand Up @@ -430,6 +424,11 @@ function getbidAdUnits() {
return bidAdUnits;
}

prebidGlobal.clearAllAuctions = function() {
cache.auctions = {};
baseClearAllAuctions();
}
Comment thread
bjorn-lw marked this conversation as resolved.

adapterManager.registerAnalyticsAdapter({
adapter: livewrappedAnalyticsAdapter,
code: 'livewrapped'
Expand All @@ -439,6 +438,4 @@ export function getAuctionCache() {
return cache.auctions;
}

export { CACHE_CLEANUP_DELAY };

export default livewrappedAnalyticsAdapter;
27 changes: 25 additions & 2 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config } from 'src/config.js';
import { server } from 'test/mocks/xhr.js';
import { setConfig } from 'modules/currency.js';
import * as adUnits from 'src/utils/adUnits';
import { getGlobal } from '../../../src/prebidGlobal.js';

const events = require('src/events');
const utils = require('src/utils');
Expand Down Expand Up @@ -378,12 +379,34 @@ describe('Livewrapped analytics adapter', function () {
expect(message).to.deep.equal(ANALYTICS_MESSAGE);
});

it('should clear auction cache after sending events', function () {
it('should clear auction cache when pbjs.clearAllAuctions is called', function () {
performStandardAuction();
performSecondAuction();

clock.tick(BID_WON_TIMEOUT + CACHE_CLEANUP_DELAY + 100);
expect(Object.keys(getAuctionCache()).length).to.equal(2);

getGlobal().clearAllAuctions();

expect(Object.keys(getAuctionCache()).length).to.equal(0);

function performSecondAuction() {
events.emit(AUCTION_INIT, {
'auctionId': '35c6d7f5-699a-4bfc-87c9-996f915341fa',
});
events.emit(BID_REQUESTED, {
'bidder': 'livewrapped',
'auctionId': '35c6d7f5-699a-4bfc-87c9-996f915341fa',
'bidderRequestId': '2be65d7958826a',
'bids': [
{
'bidder': 'livewrapped',
'adUnitCode': 'panorama_d_1',
'bidId': '3ecff0db240757',
}
],
'start': 1519149562216
});
}
});

it('should send batched message without BID_WON AND AD_RENDER_FAILED if necessary and further BID_WON and AD_RENDER_FAILED events individually', function () {
Expand Down
Loading