This commit is contained in:
Jeremy Zimmerman 2022-11-03 12:44:04 -04:00
parent 17ff7506cb
commit ba4191e891
7 changed files with 60 additions and 43 deletions

View file

@ -1,5 +1,5 @@
import axios from "axios";
import analyticsMixIn from "@/mixins/analytics-mixin.js";
//import analyticsMixIn from "@/mixins/analytics-mixin.js";
import { applicationConfig } from "@/constants/application-config.js";
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
@ -25,12 +25,14 @@ export default {
})
.then((response) => {
if (logApiCall) {
/*
analyticsMixIn.methods.pushEventToGA(
GaCategories.API_RESPONSE,
GaActions.RESULT,
`${GaLabels.SUCCESS}_${endpoint}`,
true
);
*/
}
return resolve(response);

View file

@ -5,7 +5,7 @@ import {
deleteFunnelCookie,
} from "@/helpers/heritage-integration/cookie-helper.js";
import baseMixin from "@/mixins/base-mixin";
import store from "@/store";
import { useMainStore } from "@/store";
import { storeMutations } from "@/constants/store-mutations";
/*
@ -51,9 +51,9 @@ export async function loadSessionIfPresent() {
*/
export async function saveSession() {
var saveSessionPromise;
if (store.getters.applicationUser.saveSessionPromise) {
if (useMainStore.getters.applicationUser.saveSessionPromise) {
// queue newest request after current saveSessionPromise resolves
saveSessionPromise = store.getters.applicationUser.saveSessionPromise.then(() => {
saveSessionPromise = useMainStore.getters.applicationUser.saveSessionPromise.then(() => {
// get a new saveSessionPromise
return saveSessionHelper();
});
@ -61,7 +61,7 @@ export async function saveSession() {
// create an initial saveSessionPromise
saveSessionPromise = saveSessionHelper();
}
store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise);
useMainStore.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise);
// await here to allow for a caller to await and make the function synchronous
await saveSessionPromise;
}
@ -74,7 +74,7 @@ export async function saveSession() {
*/
async function loadSession(referralNumber, referralDate, referralCorrelationId, accountNumber) {
// await the saveSessionPromise in the store to make sure we're loading up to date information
await store.getters.applicationUser.saveSessionPromise;
await useMainStore.getters.applicationUser.saveSessionPromise;
const response = await baseMixin.methods.dispatchStoreAction(
storeActions.LOAD_SESSION,
{

View file

@ -16,9 +16,10 @@ import {
ValueToLogTypes,
} from "@/constants/analytics";
import { cookieNames } from "@/constants/cookie-names";
import { useMainStore } from "@/store";
//import { useMainStore } from "@/store";
import baseMixin from "@/mixins/base-mixin";
//import { mapStores } from "pinia";
export default {
@ -172,6 +173,7 @@ export default {
},
},
computed: {
//...mapStores(useMainStore),
analyticsPageEvents() {
return analyticsPageEvents;
},

View file

@ -9,7 +9,7 @@ import {
GaEvents,
ValueToLogTypes,
} from "@/constants/analytics";
import { useMainStore } from "@/store";
//import { useMainStore } from "@/store";
describe("analyticsMixin.js", () => {
test("logPageView: calls dispatch with type and payload", () => {

View file

@ -1,10 +1,11 @@
import { useMainStore } from "@/store";
import { mapActions, mapStores } from "pinia";
import { storeActions } from "@/constants/store-actions.js";
import { storeMutations } from "@/constants/store-mutations.js";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
import { vehicleCategories } from "@/constants/vehicle-categories.js";
import { queryStrings } from "@/constants/query-strings";
import { dynamicStrings } from "@/constants/dynamic-strings";
import { useMainStore } from "@/store";
import { mapStores } from "pinia";
export default {
data() {
@ -19,10 +20,27 @@ export default {
getCmsContent(widgetName, fieldName) {
return this.$root.cmsContentByWidget?.[widgetName]?.[fieldName] ? this.$root.cmsContentByWidget[widgetName][fieldName] : '';
},
dispatchStoreAction(type, payload, encodePayload = true) {
const store = useMainStore();
// Encode the payload if required
if (encodePayload) {
encodeUriData(payload);
}
console.log(store);
console.log(type);
console.log(payload);
return store[type](payload);
},
savePageDataToStore(page, data) {
//this.mainStore.commit(storeMutations.UPDATE_PAGE_DATA, { page: page, data: data });
},
},
computed: {
// store will be accessible globally as its id + 'Store'
...mapStores(useMainStore),
storeActions() {
return storeActions;
},
@ -51,4 +69,4 @@ function encodeUriData(payload) {
payload[key] = encodeURIComponent(payload[key]);
});
}
}
}

View file

@ -1,16 +1,20 @@
import { createWebHistory, createRouter } from "vue-router";
import { storeActions } from "@/constants/store-actions";
import { storeMutations } from "../constants/store-mutations";
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader";
import {issPageValues} from '@/router/router-constants/issPage-values';
import { routingTable } from "@/router/router-constants/routing-table";
import { useMainStore } from '@/store';
import { loadSessionIfPresent, saveSession } from "@/helpers/heritage-integration/order-helper";
import analyticsMixin from "@/mixins/analytics-mixin";
const routes = [
{
path: '/',
name: 'root',
async beforeEnter(to, from, next) {
try {
try {
to.query.issPage = !to.query.issPage ? issPageValues.VEHICLE_YEAR : to.query.issPage;
if (router.hasRoute(to.query.issPage)) {
@ -50,9 +54,11 @@ const router = createRouter({
routes,
});
router.afterEach((to, from) => {
router.afterEach((to, from) => {
const store = useMainStore();
// Update lastPageVisited in the store
store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name);
store.updateLastPageVisited(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)) {
@ -71,11 +77,10 @@ router.afterEach((to, from) => {
analyticsMixin.methods.pushExperimentsToDataLayer();
});
// Get route information by page name.
// This will reach out to the Cms and there is a 1:1 relationship between page names and route names.
async function GetRouteInfoFromPageName(pageName) {
const response = await useMainStore().getRouteInfo(pageName);
const jsonFromResponse = JSON.parse(response.data.Result);
@ -89,7 +94,7 @@ async function GetRouteInfoFromPageName(pageName) {
component: lazyLoadComponent(jsonFromResponse[key].LayoutName),
});
});
return routeData;
};

View file

@ -140,15 +140,13 @@ export const useMainStore = defineStore({
endpoint: endpoints.GetHomepageInfo.url(applicationConfig.APPLICATION_ABBREVIATION),
});
},
getPageData(context, { pageName }) {
getPageData(pageName) {
return globalMethods.callHttpClient({
method: endpoints.GetPageData.method,
endpoint: endpoints.GetPageData.url(
applicationConfig.APPLICATION_ABBREVIATION,
pageName
),
payload: {},
});
method: endpoints.GetPageData.method,
endpoint: endpoints.GetPageData.url(applicationConfig.APPLICATION_ABBREVIATION, pageName),
payload: {},
});
},
// Vehicle API Actions
@ -222,7 +220,7 @@ export const useMainStore = defineStore({
},
// Analytics Actions
logExperimentExposure(context, { userId, sessionKey, pageName, experiment }) {
logExperimentExposure({ userId, sessionKey, pageName, experiment }) {
return globalMethods.callHttpClient({
method: endpoints.LogExperimentExposureIfAssigned.method,
endpoint: endpoints.LogExperimentExposureIfAssigned.url,
@ -245,19 +243,8 @@ export const useMainStore = defineStore({
},
});
},
logPageView(
context,
{
userId,
sessionKey,
pageName,
sessionId,
action,
event,
shouldUseSessionId,
experimentsForUser,
}
) {
logPageView({ userId, sessionKey, pageName, sessionId, action })
{
var payload = {
userId: userId,
sessionKey: sessionKey,
@ -268,8 +255,7 @@ export const useMainStore = defineStore({
event: event,
shouldUseSessionId: shouldUseSessionId,
experimentsForUser: experimentsForUser,
};
}
return globalMethods.callHttpClient({
method: endpoints.LogPageView.method,
endpoint: endpoints.LogPageView.url,
@ -333,7 +319,11 @@ export const useMainStore = defineStore({
});
},
GetExperimentsByUser(context, { userId }) {
updateLastPageVisited(state, lastPageVisited) {
this.applicationUser.lastPageVisited = lastPageVisited;
},
GetExperimentsByUser(userId) {
return globalMethods.callHttpClient({
method: endpoints.GetExperimentsByUser.method,
endpoint: `${endpoints.GetExperimentsByUser.url}/${userId}`,