diff --git a/src/router/index.js b/src/router/index.js index 4c3f435e..3f647a5f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,6 +5,13 @@ import { routingTable } from "@/router/router-constants/routing-table"; import { useMainStore } from '@/store'; import eventBus from "@/helpers/event-bus/event-bus"; import { globalEvents, globalEventTypes } from "@/constants/events"; +import { + getDeviceIdValue, + updateOrCreateISSCookie, + updateSessionIdCookie, +} from "@/helpers/cookie-helper"; +import { experimentTriggers } from "@/constants/experiments"; +import { applicationConfig } from "@/constants/application-config"; import analyticsMixin from "@/mixins/analytics-mixin"; @@ -13,8 +20,19 @@ 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 (analyticsMixin.methods.noSession()) { + await analyticsMixin.methods.initSession(); + } else { + updateSessionIdCookie(); + } + + await runExperiments(to.query.issPage); + + // Process ISS cookie. + updateOrCreateISSCookie(); if (router.hasRoute(to.query.issPage)) { return next({ name: to.query.issPage, query: to.query, params: to.params }); @@ -184,4 +202,23 @@ function GoToStartOn404(next) { }; +// Run SiteEntry and PageEntry triggers for experiments +async function runExperiments(nextPage) { + const store = useMainStore(); + + if (!store.applicationUser.triggeredSiteEntry) { + await store.runExperimentsForTrigger({ + userId: getDeviceIdValue(), + triggerEvent: experimentTriggers.SITE_ENTRY, + triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE, + }); + } + + await store.runExperimentsForTrigger({ + userId: getDeviceIdValue(), + triggerEvent: experimentTriggers.PAGE_ENTRY, + triggerValue: nextPage, + }); +} + export default router; \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index afc88a42..696250d5 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2,6 +2,7 @@ import { defineStore } from "pinia"; import { endpoints } from "@/constants/endpoints.js"; import { getDateForSavedSessionTimeout } from "@/helpers/session-helper"; import globalMethods from "@/global-methods"; +import { experimentTriggers } from "@/constants/experiments"; import { applicationConfig } from "@/constants/application-config"; const storeId = 'main'; @@ -38,6 +39,15 @@ const getDefaultState = () => { moldingQuestionAnswers: null, capabilityQuestionAnswers: null, }, + lineItems: { + glassParts: null, + }, + serviceLocation: { + address: null, + city: null, + state: null, + zipCode: null, + }, referralNumber: null, referralDate: null, accountNumber: 0, @@ -92,9 +102,10 @@ export const useMainStore = defineStore({ funnelServiceState: state.order.serviceLocation.state, funnelServiceZipCode: state.order.serviceLocation.zipCode, funnelParentAccountNumber: state.order.accountNumber, - funnelIsCoverageVerified: state.order.payment.insuranceCoverage.isVerified, - funnelHasRecalibrationPart: getHasRecalibrationPart(state), + //funnelIsCoverageVerified: state.order.payment.insuranceCoverage.isVerified, + //funnelHasRecalibrationPart: getHasRecalibrationPart(state), funnelSelectedMultiGlass: state.order.damage.glassToReplace?.length > 1, + /* funnelSelectedWindshieldGlass: getNonFalseValuesOfPropertyInArrayOfObjects( state.order.damage.glassToReplace, "glassLocation" @@ -111,7 +122,7 @@ export const useMainStore = defineStore({ state.order.damage.glassToReplace, "glassLocation" ).includes(damageLocationsSelected.PASSENGER), - + */ funnelOrderPartNumbers: [ ...getNonFalseValuesOfPropertyInArrayOfObjects( state.order.lineItems.glassParts, @@ -451,3 +462,7 @@ export const useMainStore = defineStore({ }, persist: true }); + +function getNonFalseValuesOfPropertyInArrayOfObjects(array, propertyName) { + return (array ?? []).map((x) => x[propertyName]).filter((x) => x); +}