diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index 867cc3d68bc..5e1276ab422 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -1,6 +1,5 @@ import {ajax} from 'src/ajax'; import adapter from 'src/AnalyticsAdapter'; -import CONSTANTS from 'src/constants.json'; import adaptermanager from 'src/adaptermanager'; import * as utils from 'src/utils'; @@ -8,24 +7,9 @@ const analyticsType = 'endpoint'; let rivrAnalytics = Object.assign(adapter({analyticsType}), { track({ eventType, args }) { - if (!window.rivraddon || !window.rivraddon.analytics || !window.rivraddon.analytics.getContext()) { - return; - } - utils.logInfo(`ARGUMENTS FOR TYPE: ============= ${eventType}`, args); - let handler = null; - switch (eventType) { - case CONSTANTS.EVENTS.AUCTION_INIT: - handler = window.rivraddon.analytics.trackAuctionInit; - break; - case CONSTANTS.EVENTS.AUCTION_END: - handler = window.rivraddon.analytics.trackAuctionEnd; - break; - case CONSTANTS.EVENTS.BID_WON: - handler = window.rivraddon.analytics.trackBidWon; - break; - } - if (handler) { - handler(args) + if (window.rivraddon && window.rivraddon.analytics && window.rivraddon.analytics.getContext() && window.rivraddon.analytics.trackPbjsEvent) { + utils.logInfo(`ARGUMENTS FOR TYPE: ============= ${eventType}`, args); + window.rivraddon.analytics.trackPbjsEvent({ eventType, args }); } } }); diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index 5bd526579ac..1b94a4c9d61 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -35,9 +35,7 @@ describe('RIVR Analytics adapter', () => { let sandbox; let ajaxStub; let rivraddonsEnableAnalyticsStub; - let rivraddonsTrackAuctionInitStub; - let rivraddonsTrackAuctionEndStub; - let rivraddonsTrackBidWonStub; + let rivraddonsTrackPbjsEventStub; let timer; before(() => { @@ -46,9 +44,7 @@ describe('RIVR Analytics adapter', () => { analytics: { enableAnalytics: () => {}, getContext: () => { return MOCK_RIVRADDON_CONTEXT; }, - trackAuctionInit: () => {}, - trackAuctionEnd: () => {}, - trackBidWon: () => {}, + trackPbjsEvent: () => {}, } }; rivraddonsEnableAnalyticsStub = sandbox.stub(window.rivraddon.analytics, 'enableAnalytics'); @@ -98,61 +94,32 @@ describe('RIVR Analytics adapter', () => { it('Firing an event when rivraddon context is not defined it should do nothing', () => { let rivraddonsGetContextStub = sandbox.stub(window.rivraddon.analytics, 'getContext'); - rivraddonsTrackAuctionInitStub = sandbox.stub(window.rivraddon.analytics, 'trackAuctionInit'); + rivraddonsTrackPbjsEventStub = sandbox.stub(window.rivraddon.analytics, 'trackPbjsEvent'); - expect(rivraddonsTrackAuctionInitStub.callCount).to.be.equal(0); + expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); events.emit(CONSTANTS.EVENTS.AUCTION_INIT, {auctionId: EMITTED_AUCTION_ID, config: {}, timeout: 3000}); - expect(rivraddonsTrackAuctionInitStub.callCount).to.be.equal(0); + expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); window.rivraddon.analytics.getContext.restore(); - window.rivraddon.analytics.trackAuctionInit.restore(); + window.rivraddon.analytics.trackPbjsEvent.restore(); }); - it('Firing AUCTION_INIT should call rivraddon trackAuctionInit passing the parameters', () => { - rivraddonsTrackAuctionInitStub = sandbox.stub(window.rivraddon.analytics, 'trackAuctionInit'); + it('Firing AUCTION_INIT should call rivraddon trackPbjsEvent passing the parameters', () => { + rivraddonsTrackPbjsEventStub = sandbox.stub(window.rivraddon.analytics, 'trackPbjsEvent'); - expect(rivraddonsTrackAuctionInitStub.callCount).to.be.equal(0); + expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); events.emit(CONSTANTS.EVENTS.AUCTION_INIT, {auctionId: EMITTED_AUCTION_ID, config: {}, timeout: 3000}); - expect(rivraddonsTrackAuctionInitStub.callCount).to.be.equal(1); + expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(1); - const firstArgument = rivraddonsTrackAuctionInitStub.getCall(0).args[0]; - expect(firstArgument.auctionId).to.be.equal(EMITTED_AUCTION_ID); + const firstArgument = rivraddonsTrackPbjsEventStub.getCall(0).args[0]; + expect(firstArgument.eventType).to.be.equal(CONSTANTS.EVENTS.AUCTION_INIT); + expect(firstArgument.args.auctionId).to.be.equal(EMITTED_AUCTION_ID); - window.rivraddon.analytics.trackAuctionInit.restore(); - }); - - it('Firing AUCTION_END should call rivraddon trackAuctionEnd passing the parameters', () => { - rivraddonsTrackAuctionEndStub = sandbox.stub(window.rivraddon.analytics, 'trackAuctionEnd'); - - expect(rivraddonsTrackAuctionEndStub.callCount).to.be.equal(0); - - events.emit(CONSTANTS.EVENTS.AUCTION_END, {auctionId: EMITTED_AUCTION_ID}); - - expect(rivraddonsTrackAuctionEndStub.callCount).to.be.equal(1); - - const firstArgument = rivraddonsTrackAuctionEndStub.getCall(0).args[0]; - expect(firstArgument.auctionId).to.be.equal(EMITTED_AUCTION_ID); - - window.rivraddon.analytics.trackAuctionEnd.restore(); - }); - - it('Firing BID_WON should call rivraddon trackBidWon passing the parameters', () => { - rivraddonsTrackBidWonStub = sandbox.stub(window.rivraddon.analytics, 'trackBidWon'); - - expect(rivraddonsTrackBidWonStub.callCount).to.be.equal(0); - - events.emit(CONSTANTS.EVENTS.BID_WON, {auctionId: EMITTED_AUCTION_ID}); - - expect(rivraddonsTrackBidWonStub.callCount).to.be.equal(1); - - const firstArgument = rivraddonsTrackBidWonStub.getCall(0).args[0]; - expect(firstArgument.auctionId).to.be.equal(EMITTED_AUCTION_ID); - - window.rivraddon.analytics.trackBidWon.restore(); + window.rivraddon.analytics.trackPbjsEvent.restore(); }); const BANNER_AD_UNITS_MOCK = [