diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 2325c29cd..322dab574 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -66,6 +66,10 @@ const endpoints = { LogExperimentExposureIfAssigned:{ url: "/analytics/api/v1/analytics/log-experiment-exposure", method: "POST", + }, + LogActivity:{ + url: "/analytics/api/v1/analytics/activity", + method: "POST", } }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 9e87416d4..7587907dc 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -18,6 +18,7 @@ const storeActions = { SET_REFERRAL_INFORMATION: "setReferralInformation", VALIDATE_ZIP: "validateZip", LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", + LOG_ACTIVITY: "logActivity", // DEPENDENCY MUTATIONS RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index bf1c56b72..d9cabc734 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -72,7 +72,7 @@ export function getDeviceIdValue(){ return cookieValueMatch[0].split('=')[1]; } - return ''; + return '00000000-0000-0000-0000-000000000000'; } /* @@ -88,6 +88,19 @@ export function getSessionKeyValue(){ return 0; } +/* + Gets value of skey cookie, returns 0 if not found. +*/ +export function getSessionIdValue(){ + const cookieValue = getCookieValueByName(cookieNames.SESSION_ID); + + if(cookieValue){ + return cookieValue; + } + + return '00000000-0000-0000-0000-000000000000'; +} + /* =========================== = PRIVATE FUNCTIONS = diff --git a/src/router/index.js b/src/router/index.js index ace5b43cc..fadcf66a1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -18,6 +18,8 @@ import store from "@/store"; // Components import ComponentTest from "@/layouts/component-test/component-test.vue"; import FormTest from "@/layouts/form-test/form-test.vue"; +import { getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper"; +import { settleAllPromises } from "@/helpers/layout-helper"; const routes = [ { @@ -36,7 +38,6 @@ const routes = [ async beforeEnter(to, from, next) { // If we have no query string, or we don't have the FmgPage query string. try { - // If the saved session has timed out, clear the session, execute 404 logic. if (getFunnelCookie() !== null && !isSavedSessionStillActive()) { await GoToFunnelStartOn404(next); @@ -76,6 +77,7 @@ const routes = [ await GoToFunnelStartOn404(next); } + logPageEvent(to.query.fmgPage); return next({ name: to.query.fmgPage, query: to.query, params: to.params }); } @@ -97,6 +99,8 @@ const routes = [ await GoToFunnelStartOn404(next); } + logPageEvent(to.query.fmgPage); + // Assign current query string parameters, as well as our fmgPage one. next({ name: routeData[0].name, @@ -162,7 +166,7 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery if (getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) { await saveOrder(); } - + router.push({ name: "root", query: Object.assign(optionalQuery, { @@ -264,4 +268,29 @@ function resetDependentState(component) { return component.default.methods.resetDependentState(); } +async function logPageEvent(destinationFmgPageValue){ + const logActivityPromise = baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOG_ACTIVITY, + { + userId: getDeviceIdValue(), + sessionKey: getSessionKeyValue(), + pageName: destinationFmgPageValue, + sessionId: getSessionIdValue(), + shouldUseSessionId: true, + pageEvent: { + action: '', + event: 'ENTRY', + } + }, false); + + // Settle promises and get results + const promiseResultMap = [ + { + resultKey: "logActivity", + promise: logActivityPromise, + }, + ]; + + let resultMap = await settleAllPromises(promiseResultMap); +} + export default router; \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index 33fa6e0f0..04c966518 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -409,6 +409,42 @@ export const actions = { }); }, + logActivity(context, { userId, sessionKey, pageName, sessionId, pageEvent, customEvent, shouldUseSessionId }) { + var customEventData = {}; + customEvent?.forEach(function(event) + { + var category = event.category; + var action = event.action; + var label = event.label; + var value = event.value; + customEventData[category] = { + category: category, + action: action, + label: label, + value: value + }; + }) + + return globalMethods.callHttpClient({ + method: endpoints.LogActivity.method, + endpoint: endpoints.LogActivity.url, + payload: { + userId: userId, + sessionKey: sessionKey, + sessionId: sessionId, + pageName: pageName, + applicationName: 'SafeliteContent', + shouldUseSessionId: shouldUseSessionId, + pageEvent: { + action: pageEvent.action, + event: pageEvent.event, + }, + customEvent: customEventData + } + }); + }, + + // Parts API Actions getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) { return globalMethods.callHttpClient({