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 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.lastNavigationPage || pageName;
analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE,
GaActions.RESULT,
`${GaLabels.SUCCESS}_${endpoint}`,
`${nextPageName}_${endpoint}`,
`${GaLabels.SUCCESS}${additionalEventData}`,
true
);
}

View file

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

View file

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

View file

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