CSR-18 log page events

This commit is contained in:
CarlNation 2022-04-25 08:39:17 -04:00
parent d25e779dba
commit ce988ee120
5 changed files with 86 additions and 3 deletions

View file

@ -66,6 +66,10 @@ const endpoints = {
LogExperimentExposureIfAssigned:{ LogExperimentExposureIfAssigned:{
url: "/analytics/api/v1/analytics/log-experiment-exposure", url: "/analytics/api/v1/analytics/log-experiment-exposure",
method: "POST", method: "POST",
},
LogActivity:{
url: "/analytics/api/v1/analytics/activity",
method: "POST",
} }
}; };

View file

@ -18,6 +18,7 @@ const storeActions = {
SET_REFERRAL_INFORMATION: "setReferralInformation", SET_REFERRAL_INFORMATION: "setReferralInformation",
VALIDATE_ZIP: "validateZip", VALIDATE_ZIP: "validateZip",
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
LOG_ACTIVITY: "logActivity",
// DEPENDENCY MUTATIONS // DEPENDENCY MUTATIONS
RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies",

View file

@ -72,7 +72,7 @@ export function getDeviceIdValue(){
return cookieValueMatch[0].split('=')[1]; return cookieValueMatch[0].split('=')[1];
} }
return ''; return '00000000-0000-0000-0000-000000000000';
} }
/* /*
@ -88,6 +88,19 @@ export function getSessionKeyValue(){
return 0; 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 = = PRIVATE FUNCTIONS =

View file

@ -18,6 +18,8 @@ import store from "@/store";
// Components // Components
import ComponentTest from "@/layouts/component-test/component-test.vue"; import ComponentTest from "@/layouts/component-test/component-test.vue";
import FormTest from "@/layouts/form-test/form-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 = [ const routes = [
{ {
@ -36,7 +38,6 @@ const routes = [
async beforeEnter(to, from, next) { async beforeEnter(to, from, next) {
// If we have no query string, or we don't have the FmgPage query string. // If we have no query string, or we don't have the FmgPage query string.
try { try {
// If the saved session has timed out, clear the session, execute 404 logic. // If the saved session has timed out, clear the session, execute 404 logic.
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) { if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);
@ -76,6 +77,7 @@ const routes = [
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);
} }
logPageEvent(to.query.fmgPage);
return next({ name: to.query.fmgPage, query: to.query, params: to.params }); return next({ name: to.query.fmgPage, query: to.query, params: to.params });
} }
@ -97,6 +99,8 @@ const routes = [
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);
} }
logPageEvent(to.query.fmgPage);
// Assign current query string parameters, as well as our fmgPage one. // Assign current query string parameters, as well as our fmgPage one.
next({ next({
name: routeData[0].name, name: routeData[0].name,
@ -264,4 +268,29 @@ function resetDependentState(component) {
return component.default.methods.resetDependentState(); 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; export default router;

View file

@ -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 // Parts API Actions
getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) { getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) {
return globalMethods.callHttpClient({ return globalMethods.callHttpClient({