From 5d3917b27ccb9db1137ec6a887214806cd26056f Mon Sep 17 00:00:00 2001 From: Daniel Bisgrove Date: Fri, 29 Sep 2023 10:50:24 -0400 Subject: [PATCH 1/2] TestingTransaction for different frequecies as well as items. Also added sessionStorage to remove items after checkout has completed. Also made function to create sessionStorage name to simplify code --- src/app/analytics/analytics.factory.js | 18 ++++++++++++++---- .../productConfigForm.component.js | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/analytics/analytics.factory.js b/src/app/analytics/analytics.factory.js index f380b689c..9d33a13db 100644 --- a/src/app/analytics/analytics.factory.js +++ b/src/app/analytics/analytics.factory.js @@ -16,10 +16,16 @@ function suppressErrors (func) { } } -const testingTransactionSessionName = 'isItemTestingTransaction_' +function testingTransactionName (item) { + const designationNumber = item.designationNumber + const frequencyObj = find(item.frequencies, { name: item.frequency }) + const frequency = frequencyObj?.display || item.frequency + return `isItemTestingTransaction_${designationNumber}_${frequency.toLowerCase()}` +} + // Generate a datalayer product object const generateProduct = suppressErrors(function (item, additionalData = {}) { - const testingTransaction = window.sessionStorage.getItem(`${testingTransactionSessionName + item.designationNumber}`) || undefined + const testingTransaction = window.sessionStorage.getItem(testingTransactionName(item)) || undefined const price = additionalData?.price || item.amount const category = additionalData?.category || item.designationType const name = additionalData?.name || item.displayName || undefined @@ -134,9 +140,9 @@ const analyticsFactory = /* @ngInject */ function ($window, $timeout, envService }) } }), - saveTestingTransaction: suppressErrors(function (itemId, testingTransaction) { + saveTestingTransaction: suppressErrors(function (item, testingTransaction) { if (testingTransaction) { - $window.sessionStorage.setItem(`${testingTransactionSessionName + itemId}`, testingTransaction) + $window.sessionStorage.setItem(testingTransactionName(item), testingTransaction) } }), cartAdd: suppressErrors(function (itemConfig, productData) { @@ -588,6 +594,10 @@ const analyticsFactory = /* @ngInject */ function ($window, $timeout, envService localStorage.removeItem('transactionCart') // Remove the coverFeeDecision from sessionStorage since it is no longer needed sessionStorage.removeItem('coverFeeDecision') + // Remove testingTransaction from sessionStorage for each item if any since it is no longer needed + transactionCart.items.map((item) => { + $window.sessionStorage.removeItem(testingTransactionName(item)) + }) }), search: suppressErrors(function (params, results) { if (params) { diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index 6f5dfa9ed..869f0b486 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -311,7 +311,7 @@ class ProductConfigFormController { const comment = this.itemConfig['donation-services-comments'] const isTestingTransaction = comment ? comment.toLowerCase().includes('test') : false this.brandedAnalyticsFactory.saveTestingTransaction(isTestingTransaction) - this.analyticsFactory.saveTestingTransaction(this.productData.designationNumber, isTestingTransaction) + this.analyticsFactory.saveTestingTransaction(this.productData, isTestingTransaction) const data = this.productData.frequency === 'NA' ? omit(this.itemConfig, ['recurring-start-month', 'recurring-day-of-month']) : this.itemConfig From 1d5d1798567f069c37d25cc87f8dddb2f64e8a52 Mon Sep 17 00:00:00 2001 From: Daniel Bisgrove Date: Fri, 29 Sep 2023 10:51:55 -0400 Subject: [PATCH 2/2] fixing lint issues --- src/app/analytics/analytics.factory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/analytics/analytics.factory.js b/src/app/analytics/analytics.factory.js index 9d33a13db..0e6f7c506 100644 --- a/src/app/analytics/analytics.factory.js +++ b/src/app/analytics/analytics.factory.js @@ -140,7 +140,7 @@ const analyticsFactory = /* @ngInject */ function ($window, $timeout, envService }) } }), - saveTestingTransaction: suppressErrors(function (item, testingTransaction) { + saveTestingTransaction: suppressErrors(function (item, testingTransaction) { if (testingTransaction) { $window.sessionStorage.setItem(testingTransactionName(item), testingTransaction) } @@ -595,7 +595,7 @@ const analyticsFactory = /* @ngInject */ function ($window, $timeout, envService // Remove the coverFeeDecision from sessionStorage since it is no longer needed sessionStorage.removeItem('coverFeeDecision') // Remove testingTransaction from sessionStorage for each item if any since it is no longer needed - transactionCart.items.map((item) => { + transactionCart.items.forEach((item) => { $window.sessionStorage.removeItem(testingTransactionName(item)) }) }),