diff --git a/src/global-methods.js b/src/global-methods.js index 45bbc467c..756b58dc8 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -1,13 +1,21 @@ 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, isFormData = false }) { + callHttpClient({ + method, + endpoint, + payload, + logApiCall = true, + isFormData = false, + additionalSuccessEventDataHandler, + }) { return new Promise((resolve, reject) => { const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; let payloadAndAnalyticsData = {}; @@ -31,10 +39,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 15ba52647..1d410c3cb 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -222,6 +222,12 @@ router.overrideNavigation = ( next(); }; +router.getNextPage = () => nextPageName; + +// PRIVATE VARIABLES + +var nextPageName; + // PRIVATE FUNCTIONS // Navigate to the next route, depending on the scenario. @@ -245,6 +251,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 7ad5c4457..c81346f16 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1391,6 +1391,8 @@ export const actions = { eon: order.eon, }, }, + additionalSuccessEventDataHandler: (response) => + "Email provided: " + (order.customer.emailAddress ? "true" : "false"), }); },