Skip to content

Commit

Permalink
Merge branch 'adding-data-onto-datalayer-tracking' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Sep 29, 2023
2 parents 65540f6 + 1d5d179 commit 8dc04f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/app/analytics/analytics.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.forEach((item) => {
$window.sessionStorage.removeItem(testingTransactionName(item))
})
}),
search: suppressErrors(function (params, results) {
if (params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,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

Expand Down

0 comments on commit 8dc04f4

Please sign in to comment.