From bfdda1fcf08511efbe195379e734a192faa90c49 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Thu, 22 Jun 2023 09:22:57 -0400 Subject: [PATCH 1/6] CSR-1439 email provided ga event --- src/global-methods.js | 19 ++++++++++++++++--- src/mixins/analytics-mixin.js | 4 ++++ src/router/index.js | 8 ++++++++ src/store/index.js | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/global-methods.js b/src/global-methods.js index cba64e908..49f9e15df 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -1,13 +1,20 @@ import axios from "axios"; import analyticsMixIn from "@/mixins/analytics-mixin.js"; import store from "@/store"; +import router from "@/router"; import { applicationConfig } from "@/constants/application-config.js"; import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; import { headerKeys } from "@/constants/header-keys"; export default { - callHttpClient({ method, endpoint, payload, logApiCall = true }) { + callHttpClient({ + method, + endpoint, + payload, + logApiCall = true, + additionalSuccessEventDataHandler, + }) { return new Promise((resolve, reject) => { const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; let payloadAndAnalyticsData = {}; @@ -26,10 +33,16 @@ export default { }).then( (response) => { if (logApiCall) { + let additionalEventData = ""; + if (additionalSuccessEventDataHandler) { + additionalEventData = "_" + additionalSuccessEventDataHandler(response); + } + const pageName = analyticsMixIn.methods.getPageName(); + const nextPageName = router.getNextPage() || pageName; analyticsMixIn.methods.pushEventToGA( GaCategories.API_RESPONSE, - GaActions.RESULT, - `${GaLabels.SUCCESS}_${endpoint}`, + `${nextPageName}_${endpoint}`, + `${GaLabels.SUCCESS}${additionalEventData}`, true ); } diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index 29eb76c3d..75f22edcb 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -23,6 +23,10 @@ import { applicationConfig } from "../constants/application-config"; export default { methods: { + getPageName() { + return getPageNameByQueryString(); + }, + logPageView(pageEvent) { const currentPageName = getPageNameByQueryString(); var payload = { diff --git a/src/router/index.js b/src/router/index.js index eb8e3947c..0d7918453 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -226,6 +226,12 @@ router.overrideNavigation = ( next(); }; +router.getNextPage = () => nextPageName; + +// PRIVATE VARIABLES + +var nextPageName; + // PRIVATE FUNCTIONS // Navigate to the next route, depending on the scenario. @@ -249,6 +255,8 @@ async function navigate( if (destinationFmgPageValue !== undefined) { // We're always pushing the same path, just changing query strings. Make sure our optional query strings get combined with our fmgPage one. + nextPageName = destinationFmgPageValue; + // Update page data to the store for next page if provided. Otherwise, keep existing page data or set to empty object const existingPageDataForPage = store.getters.pageData(destinationFmgPageValue); baseMixin.methods.savePageDataToStore( diff --git a/src/store/index.js b/src/store/index.js index ea1122f0c..510877a53 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1093,6 +1093,8 @@ export const actions = { eon: order.eon, }, }, + additionalSuccessEventDataHandler: (response) => + "Email provided: " + (order.customer.emailAddress ? "true" : "false"), }); }, loadSession( From c7f76b1348d7f7fa27b628f717712c3e91f0c4a3 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Fri, 23 Jun 2023 13:09:30 -0400 Subject: [PATCH 2/6] CSR-1439 refactor navigated page storage --- src/global-methods.js | 2 +- src/router/index.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/global-methods.js b/src/global-methods.js index 49f9e15df..1ae2dbf80 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -38,7 +38,7 @@ export default { additionalEventData = "_" + additionalSuccessEventDataHandler(response); } const pageName = analyticsMixIn.methods.getPageName(); - const nextPageName = router.getNextPage() || pageName; + const nextPageName = router.lastNavigationPage || pageName; analyticsMixIn.methods.pushEventToGA( GaCategories.API_RESPONSE, `${nextPageName}_${endpoint}`, diff --git a/src/router/index.js b/src/router/index.js index 0d7918453..231db1e3c 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -159,11 +159,17 @@ const router = createRouter({ }); //---------------------------------------------------------- Router Functions ---------------------------------------------------------- +router.beforeEach(async (to, from, next) => { + router.lastNavigationPage = to.name; + next(); +}); router.afterEach(async (to, from) => { // Update lastPageVisited in the store store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name); + // router.lastNavigationPage = to.name; + // If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate if (eval(to.params.isSavingNavigation)) { if ( @@ -226,12 +232,6 @@ router.overrideNavigation = ( next(); }; -router.getNextPage = () => nextPageName; - -// PRIVATE VARIABLES - -var nextPageName; - // PRIVATE FUNCTIONS // Navigate to the next route, depending on the scenario. @@ -255,7 +255,7 @@ async function navigate( if (destinationFmgPageValue !== undefined) { // We're always pushing the same path, just changing query strings. Make sure our optional query strings get combined with our fmgPage one. - nextPageName = destinationFmgPageValue; + // router.lastNavigationPage = destinationFmgPageValue; // Update page data to the store for next page if provided. Otherwise, keep existing page data or set to empty object const existingPageDataForPage = store.getters.pageData(destinationFmgPageValue); From cbfd6e49d23136001025547e16c00917c75f9936 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Mon, 26 Jun 2023 12:25:22 -0400 Subject: [PATCH 3/6] CSR-1439 handle browser navigation --- src/router/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 231db1e3c..d82c13ac9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -159,8 +159,9 @@ const router = createRouter({ }); //---------------------------------------------------------- Router Functions ---------------------------------------------------------- + router.beforeEach(async (to, from, next) => { - router.lastNavigationPage = to.name; + router.lastNavigationPage = to.name == "root" ? analyticsMixin.methods.getPageName() : to.name; next(); }); @@ -168,8 +169,6 @@ router.afterEach(async (to, from) => { // Update lastPageVisited in the store store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name); - // router.lastNavigationPage = to.name; - // If saving on navigation is requested, check for saved SessionId or EmailAddress to determine if saving is appropriate if (eval(to.params.isSavingNavigation)) { if ( From 6a53856fbf36e3461ffece4143972c1396e8e90a Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Mon, 26 Jun 2023 12:30:54 -0400 Subject: [PATCH 4/6] CSR-1439 removed comment --- src/router/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index d82c13ac9..3b09d7260 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -254,8 +254,6 @@ async function navigate( if (destinationFmgPageValue !== undefined) { // We're always pushing the same path, just changing query strings. Make sure our optional query strings get combined with our fmgPage one. - // router.lastNavigationPage = destinationFmgPageValue; - // Update page data to the store for next page if provided. Otherwise, keep existing page data or set to empty object const existingPageDataForPage = store.getters.pageData(destinationFmgPageValue); baseMixin.methods.savePageDataToStore( From c7adf2d9a7d7410df57c94de9fca4b3209604eed Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Mon, 26 Jun 2023 13:24:44 -0400 Subject: [PATCH 5/6] CSR-1439 comment to describe lastNavPage setting --- src/router/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/router/index.js b/src/router/index.js index 3b09d7260..2663846ce 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -161,7 +161,11 @@ const router = createRouter({ //---------------------------------------------------------- Router Functions ---------------------------------------------------------- router.beforeEach(async (to, from, next) => { + // Set the lastNavigationPage to the current page name for accurate tracking of page navigations. + // Since beforeEach() can be triggered before navigation resolution, to.name may sometimes be "root". + // In such cases, getPageName() from the analyticsMixin is used to accurately get the current page name. router.lastNavigationPage = to.name == "root" ? analyticsMixin.methods.getPageName() : to.name; + next(); }); From 1729748690ae19733a7407b5a63ec3bfd073b925 Mon Sep 17 00:00:00 2001 From: Matt Caimi Date: Mon, 26 Jun 2023 13:35:23 -0400 Subject: [PATCH 6/6] CSR-1439 comments --- src/router/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 2663846ce..04d26c9d6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -161,9 +161,8 @@ const router = createRouter({ //---------------------------------------------------------- Router Functions ---------------------------------------------------------- router.beforeEach(async (to, from, next) => { - // Set the lastNavigationPage to the current page name for accurate tracking of page navigations. - // Since beforeEach() can be triggered before navigation resolution, to.name may sometimes be "root". - // In such cases, getPageName() from the analyticsMixin is used to accurately get the current page name. + // set lastNavigationPage here to capture state before API calls for analytics. + // use current page url query string name when to.name is "root" (due to unresolved navigation in beforeEach) router.lastNavigationPage = to.name == "root" ? analyticsMixin.methods.getPageName() : to.name; next();