Merge pull request #1181 from Safelite/feature/CSR-1439.1

Feature/csr 1439.1
This commit is contained in:
Matt Caimi 2023-06-26 13:40:53 -04:00 committed by GitHub
commit 37170a49f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -1,13 +1,20 @@
import axios from "axios"; import axios from "axios";
import analyticsMixIn from "@/mixins/analytics-mixin.js"; import analyticsMixIn from "@/mixins/analytics-mixin.js";
import store from "@/store"; import store from "@/store";
import router from "@/router";
import { applicationConfig } from "@/constants/application-config.js"; import { applicationConfig } from "@/constants/application-config.js";
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
import { headerKeys } from "@/constants/header-keys"; import { headerKeys } from "@/constants/header-keys";
export default { export default {
callHttpClient({ method, endpoint, payload, logApiCall = true }) { callHttpClient({
method,
endpoint,
payload,
logApiCall = true,
additionalSuccessEventDataHandler,
}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
let payloadAndAnalyticsData = {}; let payloadAndAnalyticsData = {};
@ -26,10 +33,16 @@ export default {
}).then( }).then(
(response) => { (response) => {
if (logApiCall) { if (logApiCall) {
let additionalEventData = "";
if (additionalSuccessEventDataHandler) {
additionalEventData = "_" + additionalSuccessEventDataHandler(response);
}
const pageName = analyticsMixIn.methods.getPageName();
const nextPageName = router.lastNavigationPage || pageName;
analyticsMixIn.methods.pushEventToGA( analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE, GaCategories.API_RESPONSE,
GaActions.RESULT, `${nextPageName}_${endpoint}`,
`${GaLabels.SUCCESS}_${endpoint}`, `${GaLabels.SUCCESS}${additionalEventData}`,
true true
); );
} }

View file

@ -23,6 +23,10 @@ import { applicationConfig } from "../constants/application-config";
export default { export default {
methods: { methods: {
getPageName() {
return getPageNameByQueryString();
},
logPageView(pageEvent) { logPageView(pageEvent) {
const currentPageName = getPageNameByQueryString(); const currentPageName = getPageNameByQueryString();
var payload = { var payload = {

View file

@ -160,6 +160,14 @@ const router = createRouter({
//---------------------------------------------------------- Router Functions ---------------------------------------------------------- //---------------------------------------------------------- Router Functions ----------------------------------------------------------
router.beforeEach(async (to, from, next) => {
// 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();
});
router.afterEach(async (to, from) => { router.afterEach(async (to, from) => {
// Update lastPageVisited in the store // Update lastPageVisited in the store
store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name); store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name);

View file

@ -1093,6 +1093,8 @@ export const actions = {
eon: order.eon, eon: order.eon,
}, },
}, },
additionalSuccessEventDataHandler: (response) =>
"Email provided: " + (order.customer.emailAddress ? "true" : "false"),
}); });
}, },
loadSession( loadSession(