Merge pull request #1181 from Safelite/feature/CSR-1439.1
Feature/csr 1439.1
This commit is contained in:
commit
37170a49f0
4 changed files with 30 additions and 3 deletions
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ import { applicationConfig } from "../constants/application-config";
|
|||
|
||||
export default {
|
||||
methods: {
|
||||
getPageName() {
|
||||
return getPageNameByQueryString();
|
||||
},
|
||||
|
||||
logPageView(pageEvent) {
|
||||
const currentPageName = getPageNameByQueryString();
|
||||
var payload = {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1093,6 +1093,8 @@ export const actions = {
|
|||
eon: order.eon,
|
||||
},
|
||||
},
|
||||
additionalSuccessEventDataHandler: (response) =>
|
||||
"Email provided: " + (order.customer.emailAddress ? "true" : "false"),
|
||||
});
|
||||
},
|
||||
loadSession(
|
||||
|
|
|
|||
Loading…
Reference in a new issue