Skip to content

Commit

Permalink
Prevent duplicate purchase analytics events in branded checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Feb 1, 2024
1 parent ce3fd16 commit c39a474
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/app/thankYou/summary/thankYouSummary.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/app/thankYou/summary/thankYouSummary.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=')
Expand All @@ -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(() => {})
Expand Down

0 comments on commit c39a474

Please sign in to comment.