Merge pull request #663 from Safelite/feature/CSR-512A
Feature/csr 512 a
This commit is contained in:
commit
26433cee76
7 changed files with 74 additions and 26 deletions
|
|
@ -72,7 +72,7 @@ const endpoints = {
|
|||
method: "GET",
|
||||
},
|
||||
LogExperimentExposureIfAssigned:{
|
||||
url: "/analytics/api/v1/analytics/log-experiment-exposure",
|
||||
url: "/experiments/api/v1/experiments/log-exposure",
|
||||
method: "POST",
|
||||
},
|
||||
LogPageView:{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ import store from "@/store";
|
|||
jest.mock("@/store", () => ({
|
||||
commit: jest.fn(),
|
||||
dispatch: jest.fn(),
|
||||
getters: {
|
||||
applicationUser: {
|
||||
experiments: []
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Mock our module for promises.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import { settleAllPromises } from "@/helpers/layout-helper";
|
|||
import { storeActions } from "@/constants/store-actions";
|
||||
import { experimentUniverses } from "@/constants/experiments";
|
||||
import { getDeviceIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||
import store from "@/store";
|
||||
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
|
||||
|
|
@ -48,13 +49,15 @@ export default {
|
|||
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
||||
const yearQuestionInitialDataPromise = yearQuestion.methods.loadInitialData();
|
||||
|
||||
const experimentForLogging = store.getters.applicationUser.experiments.find(e => e.universeName === experimentUniverses.CONCEPT_FUNNEL);
|
||||
|
||||
// Log experiment exposure
|
||||
const logExperimentExposurePromise = baseMixin.methods.dispatchStoreAction(storeActions.LOG_EXPERIMENT_EXPOSURE,
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_EXPERIMENT_EXPOSURE,
|
||||
{
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: to.query.fmgPage,
|
||||
universeName: experimentUniverses.CONCEPT_FUNNEL
|
||||
experiment: experimentForLogging
|
||||
}, false);
|
||||
|
||||
// Settle promises and get results
|
||||
|
|
@ -67,10 +70,6 @@ export default {
|
|||
resultKey: "yearQuestionInitialData",
|
||||
promise: yearQuestionInitialDataPromise,
|
||||
},
|
||||
{
|
||||
resultKey: "logExperimentExposure",
|
||||
promise: logExperimentExposurePromise,
|
||||
},
|
||||
];
|
||||
|
||||
let resultMap = await settleAllPromises(promiseResultMap);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { queryStrings } from "@/constants/query-strings";
|
|||
import { experimentSettings } from "@/constants/experiments";
|
||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents, ValueToLogTypes } from "@/constants/analytics";
|
||||
import { cookieNames } from "@/constants/cookie-names";
|
||||
import store from "@/store";
|
||||
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ export default {
|
|||
action: '',
|
||||
event: pageEvent,
|
||||
shouldUseSessionId: false,
|
||||
experimentsForUser: store.getters.applicationUser.experiments,
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||
|
|
@ -37,6 +39,7 @@ export default {
|
|||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: false,
|
||||
experimentsForUser: store.getters.applicationUser.experiments
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
||||
|
|
@ -57,7 +60,7 @@ export default {
|
|||
pushToDataLayerIfDefined(eventToBePushed);
|
||||
|
||||
if (pushToLogApp) {
|
||||
this.logCustomEvent(category, action, labelToLog, undefined);
|
||||
this.logCustomEvent(category, action, labelToLog, undefined);
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -75,7 +78,8 @@ export default {
|
|||
this.logPageView(analyticsPageEvents.ENTRY);
|
||||
},
|
||||
|
||||
pushExperimentsToDataLayer(experiments) {
|
||||
pushExperimentsToDataLayer() {
|
||||
const experiments = store.getters.applicationUser.experiments;
|
||||
experiments?.forEach(exp => {
|
||||
|
||||
// Set Google Dimension Index based on experiment settings.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import analyticsMixin from "@/mixins/analytics-mixin";
|
|||
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents, ValueToLogTypes } from "@/constants/analytics";
|
||||
import store from "@/store";
|
||||
|
||||
describe("analyticsMixin.js", () => {
|
||||
test("logPageView: calls dispatch with type and payload", () => {
|
||||
|
|
@ -119,6 +120,21 @@ describe("analyticsMixin.js", () => {
|
|||
}
|
||||
]
|
||||
|
||||
// Mock store
|
||||
jest.mock("@/store", () => { return {}; }, { virtual: true });
|
||||
|
||||
store.getters = {
|
||||
applicationUser: {
|
||||
experiments: [
|
||||
{
|
||||
settings: {},
|
||||
variationName: 'test',
|
||||
universeName: 'testUniverse'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
||||
|
|
@ -147,6 +163,20 @@ describe("analyticsMixin.js", () => {
|
|||
}
|
||||
]
|
||||
|
||||
// Mock store
|
||||
jest.mock("@/store", () => { return {}; }, { virtual: true });
|
||||
|
||||
store.getters = {
|
||||
applicationUser: {
|
||||
experiments: [
|
||||
{
|
||||
settings: { "Google Custom Dimension Index": "5" },
|
||||
variationName: 'test',
|
||||
universeName: 'testUniverse'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData);
|
||||
|
|
|
|||
|
|
@ -128,13 +128,12 @@ const router = createRouter({
|
|||
router.afterEach((to, from) => {
|
||||
// Update lastPageVisited in the store
|
||||
store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name);
|
||||
// Push page view to GA
|
||||
analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]);
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() })
|
||||
.then( (response) => {
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer(response.data);
|
||||
});
|
||||
// Push page view to GA
|
||||
analyticsMixin.methods.pushPageViewToGA();
|
||||
|
||||
// Push experiments to Data Layer
|
||||
analyticsMixin.methods.pushExperimentsToDataLayer();
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -142,7 +141,6 @@ router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams =
|
|||
navigate(scenario, currentRoute, optionalQuery, optionalParams, optionalPageData);
|
||||
}
|
||||
|
||||
|
||||
router.navigateToExternalUrl = (url, optionalQuery = {}) => {
|
||||
navigateToUrl(url, optionalQuery);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,15 +547,26 @@ export const actions = {
|
|||
},
|
||||
|
||||
// Analytics Actions
|
||||
logExperimentExposure(context, { userId, sessionKey, pageName, universeName }) {
|
||||
logExperimentExposure(context, { userId, sessionKey, pageName, experiment }) {
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LogExperimentExposureIfAssigned.method,
|
||||
endpoint: endpoints.LogExperimentExposureIfAssigned.url,
|
||||
payload: {
|
||||
userId: userId,
|
||||
sessionKey: sessionKey,
|
||||
pageName: pageName,
|
||||
universeName: universeName
|
||||
experimentForLogging: {
|
||||
userId: userId,
|
||||
experimentUniverseId: experiment.universeId,
|
||||
experimentUniverseName: experiment.universeName,
|
||||
experimentTestId: experiment.testId,
|
||||
experimentTestName: experiment.testName,
|
||||
experimentVariationId: experiment.variationId,
|
||||
experimentVariationName: experiment.variationName,
|
||||
enabled: experiment.isActive,
|
||||
isExposed: experiment.isExposed,
|
||||
userPartitionNumber: experiment.userPartitionNumber,
|
||||
assignmentId: experiment.assignmentId,
|
||||
sessionKey: sessionKey,
|
||||
pageName: pageName,
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -570,8 +581,7 @@ export const actions = {
|
|||
context.commit(storeMutations.UPDATE_SAVED_SESSION_ID, savedSessionId);
|
||||
context.commit(storeMutations.UPDATE_CRM_CUSTOMER_ID, crmCustomerId);
|
||||
},
|
||||
|
||||
logPageView(context, { userId, sessionKey, pageName, sessionId, action, event, shouldUseSessionId }) {
|
||||
logPageView(context, { userId, sessionKey, pageName, sessionId, action, event, shouldUseSessionId, experimentsForUser }) {
|
||||
var payload = {
|
||||
userId: userId,
|
||||
sessionKey: sessionKey,
|
||||
|
|
@ -580,7 +590,8 @@ export const actions = {
|
|||
applicationName: applicationConfig.APPLICATION_NAME,
|
||||
action: action,
|
||||
event: event,
|
||||
shouldUseSessionId: shouldUseSessionId
|
||||
shouldUseSessionId: shouldUseSessionId,
|
||||
experimentsForUser: experimentsForUser
|
||||
};
|
||||
|
||||
return globalMethods.callHttpClient({
|
||||
|
|
@ -590,7 +601,7 @@ export const actions = {
|
|||
logApiCall: false
|
||||
});
|
||||
},
|
||||
logCustomEvent(context, { userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId }) {
|
||||
logCustomEvent(context, { userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId, experimentsForUser }) {
|
||||
var payload = {
|
||||
userId: userId,
|
||||
sessionKey: sessionKey,
|
||||
|
|
@ -601,7 +612,8 @@ export const actions = {
|
|||
action: action,
|
||||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: shouldUseSessionId
|
||||
shouldUseSessionId: shouldUseSessionId,
|
||||
experimentsForUser: experimentsForUser
|
||||
};
|
||||
|
||||
return globalMethods.callHttpClient({
|
||||
|
|
|
|||
Loading…
Reference in a new issue