commit
5d42cd659f
9 changed files with 135 additions and 4 deletions
|
|
@ -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",
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {getFunnelCookie, getDeviceIdValue, getSessionKeyValue} from "@/helpers/heritage-integration/cookie-helper.js";
|
||||
import {getFunnelCookie, getDeviceIdValue, getSessionKeyValue, getSessionIdValue} from "@/helpers/heritage-integration/cookie-helper.js";
|
||||
import { removeAllTestCookies, setupCookies } from "@/helpers/unit-test-helper";
|
||||
|
||||
describe("cookies", () => {
|
||||
|
|
@ -126,5 +126,19 @@ describe("cookies", () => {
|
|||
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSessionIdValue", () => {
|
||||
test("getSessionIdValue, should return GUID", () => {
|
||||
// Arrange
|
||||
setupCookies({});
|
||||
|
||||
// Act
|
||||
const result = getSessionIdValue();
|
||||
|
||||
//Assert
|
||||
expect(result).toBe('cba0c3d1-3c1b-4305-bb56-31aa50f58e27');
|
||||
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
|
|
@ -62,6 +62,7 @@ export const cookies = {
|
|||
"anotherCookie": "{}",
|
||||
"someOtherCookie": "{}",
|
||||
"dxdev": "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
||||
"sid": "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
||||
"skey": "12345"
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ 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";
|
||||
import { analyticsPageEvents } from "./router-constants/analytics-page-events";
|
||||
|
||||
const routes = [
|
||||
{
|
||||
|
|
@ -37,7 +40,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);
|
||||
|
|
@ -77,6 +79,7 @@ const routes = [
|
|||
await GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// logPageEvent(to.query.fmgPage, analyticsPageEvents.ENTRY);
|
||||
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +101,8 @@ const routes = [
|
|||
await GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// logPageEvent(to.query.fmgPage, analyticsPageEvents.ENTRY);
|
||||
|
||||
// Assign current query string parameters, as well as our fmgPage one.
|
||||
next({
|
||||
name: routeData[0].name,
|
||||
|
|
@ -123,6 +128,7 @@ const router = createRouter({
|
|||
|
||||
router.afterEach((to, from) => {
|
||||
baseMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]);
|
||||
logPageEvent(to.query[queryStrings.FMG_PAGE], analyticsPageEvents.ENTRY);
|
||||
});
|
||||
|
||||
router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => {
|
||||
|
|
@ -167,7 +173,7 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
if (getFunnelCookie()?.ReferralNumber && getFunnelCookie()?.ReferralDate) {
|
||||
await saveOrder();
|
||||
}
|
||||
|
||||
|
||||
router.push({
|
||||
name: "root",
|
||||
query: Object.assign(optionalQuery, {
|
||||
|
|
@ -269,4 +275,29 @@ function resetDependentState(component) {
|
|||
return component.default.methods.resetDependentState();
|
||||
}
|
||||
|
||||
async function logPageEvent(destinationFmgPageValue, pageEvent){
|
||||
const logActivityPromise = baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.LOG_ACTIVITY,
|
||||
{
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: destinationFmgPageValue,
|
||||
sessionId: getSessionIdValue(),
|
||||
shouldUseSessionId: true,
|
||||
pageEvent: {
|
||||
action: '',
|
||||
event: pageEvent,
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Settle promises and get results
|
||||
const promiseResultMap = [
|
||||
{
|
||||
resultKey: "logActivity",
|
||||
promise: logActivityPromise,
|
||||
},
|
||||
];
|
||||
|
||||
let resultMap = await settleAllPromises(promiseResultMap);
|
||||
}
|
||||
|
||||
export default router;
|
||||
5
src/router/router-constants/analytics-page-events.js
Normal file
5
src/router/router-constants/analytics-page-events.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const analyticsPageEvents = {
|
||||
ENTRY: "ENTRY",
|
||||
};
|
||||
|
||||
export { analyticsPageEvents };
|
||||
|
|
@ -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: 'SafeliteDotCom',
|
||||
shouldUseSessionId: shouldUseSessionId,
|
||||
pageEvent: {
|
||||
action: pageEvent.action,
|
||||
event: pageEvent.event,
|
||||
},
|
||||
customEvent: customEventData
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
// Parts API Actions
|
||||
getPartsOrQuestions(context, { carId, glassArray, zipCode, vin = '' }) {
|
||||
return globalMethods.callHttpClient({
|
||||
|
|
|
|||
|
|
@ -617,6 +617,32 @@ describe("Actions", () => {
|
|||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, "xxx-xxx-xxx");
|
||||
});
|
||||
|
||||
it("logActivity action, should return nothing", async () => {
|
||||
|
||||
// Arrange
|
||||
const context = state;
|
||||
var pageEvent = {
|
||||
action: "",
|
||||
event: "ENTRY",
|
||||
}
|
||||
|
||||
var customEvent = [{
|
||||
category: "tstCat",
|
||||
action: "click",
|
||||
label: "damage",
|
||||
value: "psych"
|
||||
}];
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ });
|
||||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.logActivity(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, customEvent: customEvent, shouldUseSessionId: true });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Getters", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue