diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index fd42be334c0..867cc3d68bc 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -1,6 +1,5 @@ import {ajax} from 'src/ajax'; import adapter from 'src/AnalyticsAdapter'; -import find from 'core-js/library/fn/array/find'; import CONSTANTS from 'src/constants.json'; import adaptermanager from 'src/adaptermanager'; import * as utils from 'src/utils'; @@ -31,61 +30,13 @@ let rivrAnalytics = Object.assign(adapter({analyticsType}), { } }); -/** - * Expiring queue implementation. Fires callback on elapsed timeout since last last update or creation. - * @param callback - * @param ttl - * @constructor - */ -export function ExpiringQueue(sendImpressions, sendAuction, ttl, log) { - let queue = []; - let timeoutId; - - this.push = (event) => { - if (event instanceof Array) { - queue.push.apply(queue, event); - } else { - queue.push(event); - } - reset(); - }; - - this.popAll = () => { - let result = queue; - queue = []; - reset(); - return result; - }; - /** - * For test/debug purposes only - * @return {Array} - */ - this.peekAll = () => { - return queue; - }; - - this.init = reset; - - function reset() { - if (timeoutId) { - clearTimeout(timeoutId); - } - timeoutId = setTimeout(() => { - sendAuction(); - if (queue.length) { - sendImpressions(); - } - }, ttl); - } -}; - // save the base class function rivrAnalytics.originEnableAnalytics = rivrAnalytics.enableAnalytics; // override enableAnalytics so we can get access to the config passed in from the page rivrAnalytics.enableAnalytics = (config) => { if (window.rivraddon && window.rivraddon.analytics) { - window.rivraddon.analytics.enableAnalytics(config, ExpiringQueue, {utils, ajax, find}); + window.rivraddon.analytics.enableAnalytics(config, {utils, ajax}); rivrAnalytics.originEnableAnalytics(config); } }; diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index e822becef15..5bd526579ac 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -1,8 +1,6 @@ import * as utils from 'src/utils'; import analyticsAdapter from 'modules/rivrAnalyticsAdapter'; import { - ExpiringQueue, - sendAuction, sendImpressions, handleClickEventWithClosureScope, createUnOptimisedParamsField, @@ -87,49 +85,15 @@ describe('RIVR Analytics adapter', () => { delete window.rivraddon; }); - it('ExpiringQueue should call sendImpression callback after expiring queue timeout is elapsed', (done) => { - const sendImpressionMock = () => { - let elements = queue.popAll(); - expect(elements).to.be.eql([1, 2, 3, 4]); - elements = queue.popAll(); - expect(elements).to.have.lengthOf(0); - expect(Date.now()).to.be.equal(200); - done(); - }; - const sendAuctionMock = () => {}; - - let queue = new ExpiringQueue( - sendImpressionMock, - sendAuctionMock, - EXPIRING_QUEUE_TIMEOUT_MOCK); - - queue.push(1); - - setTimeout(() => { - queue.push([2, 3]); - timer.tick(50); - }, 50); - setTimeout(() => { - queue.push([4]); - timer.tick(100); - }, 100); - timer.tick(50); - }); - it('enableAnalytics - should call rivraddon enableAnalytics with the correct arguments', () => { // adaptermanager.enableAnalytics() is called in beforeEach. If just called here it doesn't seem to work. const firstArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[0]; const secondArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[1]; - const thirdArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[2]; expect(firstArgument.provider).to.be.equal('rivr'); - expect(typeof secondArgument).to.be.equal('function'); - expect(secondArgument.name).to.be.equal('ExpiringQueue'); - - expect(thirdArgument).to.have.property('utils'); - expect(thirdArgument).to.have.property('ajax'); - expect(thirdArgument).to.have.property('find'); + expect(secondArgument).to.have.property('utils'); + expect(secondArgument).to.have.property('ajax'); }); it('Firing an event when rivraddon context is not defined it should do nothing', () => {