diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e6fa6d0ff..816a6746f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -79,6 +79,7 @@ stages: __VUE_APP_CONSUMER_CF_DISTRO__: $(__VUE_APP_CONSUMER_CF_DISTRO__) __VUE_APP_GOOGLE_PLACES_API_KEY__: $(__VUE_APP_GOOGLE_PLACES_API_KEY__) __VUE_APP_HERITAGE_FUNNEL__: $(__VUE_APP_HERITAGE_FUNNEL__) + __VUE_APP_CURRENT_ENVIRONMENT__: $(__VUE_APP_CURRENT_ENVIRONMENT__) indexDeployVariables: __VUE_APP_GOOGLE_TAG_MANAGER_SCRIPT_BODY__: $(__VUE_APP_GOOGLE_TAG_MANAGER_SCRIPT_BODY__) __VUE_APP_GOOGLE_TAG_MANAGER_NOSCRIPT_FRAME_SRC__: $(__VUE_APP_GOOGLE_TAG_MANAGER_NOSCRIPT_FRAME_SRC__) @@ -119,4 +120,5 @@ stages: __VUE_APP_CONSUMER_CF_DISTRO__: $(__VUE_APP_CONSUMER_CF_DISTRO__) __VUE_APP_GOOGLE_PLACES_API_KEY__: $(__VUE_APP_GOOGLE_PLACES_API_KEY__) __VUE_APP_HERITAGE_FUNNEL__: $(__VUE_APP_HERITAGE_FUNNEL__) + __VUE_APP_CURRENT_ENVIRONMENT__: $(__VUE_APP_CURRENT_ENVIRONMENT__) cfDistributionId: $(cfDistributionId) \ No newline at end of file diff --git a/src/constants/application-config.js b/src/constants/application-config.js index b1ab342a7..0d173db19 100644 --- a/src/constants/application-config.js +++ b/src/constants/application-config.js @@ -4,7 +4,8 @@ const applicationConfig = { GOOGLE_PLACES_API_KEY: process.env.VUE_APP_GOOGLE_PLACES_API_KEY, ANALYTICS_SESSION_TIMEOUT_MINUTES: 30, SAVED_SESSION_TIMEOUT_DAYS: 45, - COOKIE_PATH: "/" + COOKIE_PATH: "/", + CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT // "Localhost", "Dev", "QA", and "Prod" }; export { applicationConfig }; \ No newline at end of file diff --git a/src/constants/cookie-names.js b/src/constants/cookie-names.js index c52debc2a..f4b4aaa9d 100644 --- a/src/constants/cookie-names.js +++ b/src/constants/cookie-names.js @@ -1,5 +1,7 @@ +import { applicationConfig } from "@/constants/application-config.js" + const cookieNames = { - FUNNEL_SESSION_INFO: "FunnelSessionInfo", + FUNNEL_SESSION_INFO: `FunnelSessionInfo-${applicationConfig.CURRENT_ENVIRONMENT}`, // Existing Safelite.com cookies DXDEV: "dxdev", diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 50efbda04..3860ad97d 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -83,8 +83,8 @@ const endpoints = { url: "/analytics/api/v1/analytics/log-custom-event", method: "POST", }, - GetExperimentsByUserForGa: { - url: "/analytics/api/v1/analytics/get-experiments-for-GA", + GetExperimentsByUser: { + url: "/analytics/api/v1/analytics/get-experiments", method: "GET", } }; diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index b6d3793f4..2a0a7f29d 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -21,7 +21,7 @@ const storeActions = { LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", LOG_PAGE_VIEW: "logPageView", LOG_CUSTOM_EVENT: "logCustomEvent", - GET_EXPERIMENTS_BY_USER_FOR_GA: "getExperimentsByUserForGa", + GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser", // DEPENDENCY MUTATIONS RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index df2d073c4..6b1943241 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -72,7 +72,7 @@ export default { }, pushExperimentsToDataLayer(experiments) { - experiments?.data?.forEach(exp => { + experiments?.forEach(exp => { // Set Google Dimension Index based on experiment settings. let googleDimensionIndex = 99; @@ -82,11 +82,13 @@ export default { } // Create object with dimension index and value. - const experimentWithDimension = {}; - - Object.keys(exp).forEach(key => { - experimentWithDimension[`${key}_${googleDimensionIndex}`] = exp[key]; - }); + const experimentWithDimension = { + [`experimentId_${googleDimensionIndex}`]: exp.universeId, + [`variationId_${googleDimensionIndex}`]: exp.variationId, + [`experimentName_${googleDimensionIndex}`]: exp.universeName, + [`variationName_${googleDimensionIndex}`]: exp.variationName, + [`customDimension_${googleDimensionIndex}`]: `${exp.universeId}_${exp.variationId}_${exp.universeName}_${exp.variationName}` + }; // Push to the data layer with the Google Custom Dimension Index. pushToDataLayerIfDefined(experimentWithDimension); diff --git a/src/mixins/analytics-mixin.spec.js b/src/mixins/analytics-mixin.spec.js index 4158bdeff..e63778466 100644 --- a/src/mixins/analytics-mixin.spec.js +++ b/src/mixins/analytics-mixin.spec.js @@ -56,21 +56,27 @@ describe("analyticsMixin.js", () => { // Arrange window.dataLayer = []; - const mockExperimentData = { - data: [ + const mockExperimentData = + [ { settings: {}, variationName: 'test', universeName: 'testUniverse' } ] - } + // Act analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData); // Assert - expect(window.dataLayer).toEqual([ { settings_99: {}, variationName_99: 'test', universeName_99: 'testUniverse' } ]); + expect(window.dataLayer).toEqual([{ + experimentId_99: undefined, + variationId_99: undefined, + experimentName_99: 'testUniverse', + variationName_99: 'test', + customDimension_99: 'undefined_undefined_testUniverse_test' + }]); }); @@ -78,21 +84,27 @@ describe("analyticsMixin.js", () => { // Arrange window.dataLayer = []; - const mockExperimentData = { - data: [ + const mockExperimentData = + [ { - settings: { "Google Custom Dimension Index": "5"}, + settings: { "Google Custom Dimension Index": "5" }, variationName: 'test', universeName: 'testUniverse' } ] - } + // Act analyticsMixin.methods.pushExperimentsToDataLayer(mockExperimentData); // Assert - expect(window.dataLayer).toEqual([ { settings_5: {"Google Custom Dimension Index": "5"}, variationName_5: 'test', universeName_5: 'testUniverse' } ]); + expect(window.dataLayer).toEqual([{ + experimentId_5: undefined, + variationId_5: undefined, + experimentName_5: 'testUniverse', + variationName_5: 'test', + customDimension_5: 'undefined_undefined_testUniverse_test' + }]); }); }); \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 1af18ec1b..f11bd4228 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -127,8 +127,11 @@ router.afterEach(async (to, from) => { // Push page view to GA analyticsMixin.methods.pushPageViewToGA(to.query[queryStrings.FMG_PAGE]); - const assignedExperiments = await baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER_FOR_GA, { userId: getDeviceIdValue() }); - analyticsMixin.methods.pushExperimentsToDataLayer(assignedExperiments); + baseMixin.methods.dispatchStoreAction(storeActions.GET_EXPERIMENTS_BY_USER, { userId: getDeviceIdValue() }) + .then( (response) => { + analyticsMixin.methods.pushExperimentsToDataLayer(response.data); + }); + }); router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => { diff --git a/src/store/index.js b/src/store/index.js index 9e7f2f459..2c52053bb 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -475,10 +475,10 @@ export const actions = { }); }, - getExperimentsByUserForGa(context, { userId }){ + GetExperimentsByUser(context, { userId }){ return globalMethods.callHttpClient({ - method: endpoints.GetExperimentsByUserForGa.method, - endpoint: `${endpoints.GetExperimentsByUserForGa.url}/${userId}`, + method: endpoints.GetExperimentsByUser.method, + endpoint: `${endpoints.GetExperimentsByUser.url}/${userId}`, payload: {} }); }, diff --git a/vue.config.js b/vue.config.js index 99c9cd754..6ddcd54de 100644 --- a/vue.config.js +++ b/vue.config.js @@ -4,6 +4,7 @@ process.env.VUE_APP_HERITAGE_FUNNEL = "http://localhost:38000/default.aspx"; process.env.VUE_APP_GOOGLE_PLACES_API_KEY = "AIzaSyDptGCkOPgN2uWJOy4ou4M33phRD4MAoJo"; +process.env.VUE_APP_CURRENT_ENVIRONMENT = "Localhost"; // GA & GTM process.env.VUE_APP_GOOGLE_TAG_MANAGER_SCRIPT_BODY = "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl+ '>m_auth=amlAYNhxUxuskQo7jmjadg>m_preview=env-38>m_cookies_win=x';f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-M6XCRH');"; diff --git a/vue.release.config.js b/vue.release.config.js index 8c705b074..ad2732e41 100644 --- a/vue.release.config.js +++ b/vue.release.config.js @@ -1,6 +1,7 @@ process.env.VUE_APP_CONSUMER_CF_DISTRO = "__VUE_APP_CONSUMER_CF_DISTRO__"; process.env.VUE_APP_GOOGLE_PLACES_API_KEY = "__VUE_APP_GOOGLE_PLACES_API_KEY__"; process.env.VUE_APP_HERITAGE_FUNNEL = "__VUE_APP_HERITAGE_FUNNEL__"; +process.env.VUE_APP_CURRENT_ENVIRONMENT = "__VUE_APP_CURRENT_ENVIRONMENT__"; // GA & GTM process.env.VUE_APP_GOOGLE_TAG_MANAGER_SCRIPT_BODY = "__VUE_APP_GOOGLE_TAG_MANAGER_SCRIPT_BODY__";