From c39a47494849c957af8660176fa5db210ef36c83 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Thu, 1 Feb 2024 15:34:32 -0600 Subject: [PATCH] Prevent duplicate purchase analytics events in branded checkout --- src/app/thankYou/summary/thankYouSummary.component.js | 7 +++++-- .../thankYou/summary/thankYouSummary.component.spec.js | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/thankYou/summary/thankYouSummary.component.js b/src/app/thankYou/summary/thankYouSummary.component.js index dfe9f7959..a85a230aa 100644 --- a/src/app/thankYou/summary/thankYouSummary.component.js +++ b/src/app/thankYou/summary/thankYouSummary.component.js @@ -21,9 +21,10 @@ const componentName = 'thankYouSummary' class ThankYouSummaryController { /* @ngInject */ - constructor ($rootScope, $window, analyticsFactory, orderService, profileService, sessionModalService, designationsService, $log) { + constructor ($rootScope, $window, analyticsFactory, envService, orderService, profileService, sessionModalService, designationsService, $log) { this.$rootScope = $rootScope this.$window = $window + this.envService = envService this.orderService = orderService this.profileService = profileService this.sessionModalService = sessionModalService @@ -73,7 +74,9 @@ class ThankYouSummaryController { this.analyticsFactory.pageLoaded() this.analyticsFactory.setPurchaseNumber(data.rawData['purchase-number']) - this.analyticsFactory.transactionEvent(this.purchase) + if (!this.envService.read('isBrandedCheckout')) { + this.analyticsFactory.transactionEvent(this.purchase) + } }, (error) => { this.$log.error('Error loading purchase data for thank you component', error) diff --git a/src/app/thankYou/summary/thankYouSummary.component.spec.js b/src/app/thankYou/summary/thankYouSummary.component.spec.js index 376d7ffcc..0cd1683c1 100644 --- a/src/app/thankYou/summary/thankYouSummary.component.spec.js +++ b/src/app/thankYou/summary/thankYouSummary.component.spec.js @@ -114,6 +114,7 @@ describe('thank you summary', () => { it('should load all data from the last completed purchase', () => { jest.spyOn(self.controller.profileService, 'getPurchase') jest.spyOn(self.controller.analyticsFactory, 'transactionEvent') + jest.spyOn(self.controller.envService, 'read').mockReturnValue(false) self.controller.loadLastPurchase() expect(self.controller.profileService.getPurchase).toHaveBeenCalledWith('/purchases/crugive/iiydanbt=') @@ -139,6 +140,14 @@ describe('thank you summary', () => { expect(self.controller.analyticsFactory.transactionEvent).toHaveBeenCalledWith(self.mockPurchase) }) + it('does not trigger analytics event in branded checkout', () => { + jest.spyOn(self.controller.analyticsFactory, 'transactionEvent') + jest.spyOn(self.controller.envService, 'read').mockReturnValue(true) + self.controller.loadLastPurchase() + + expect(self.controller.analyticsFactory.transactionEvent).not.toHaveBeenCalled() + }) + it('should not request purchase data if lastPurchaseLink is not defined', () => { jest.spyOn(self.controller.orderService, 'retrieveLastPurchaseLink').mockImplementation(() => undefined) jest.spyOn(self.controller.profileService, 'getPurchase').mockImplementation(() => {})