From d556a4492e9109a64de904da44f3a142e65a5bff Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 3 May 2022 08:09:02 -0400 Subject: [PATCH 1/6] Add current environment to cookie name --- azure-pipelines.yml | 2 ++ src/constants/application-config.js | 3 ++- src/constants/cookie-names.js | 4 +++- vue.config.js | 1 + vue.release.config.js | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) 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..5f5e77cdc 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 // Current environment following SV2's EnvironmentConfiguration.SV2Environment }; 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/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__"; From a42600f24cf7d2fc062facff0a7f69ac91b1fb24 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Tue, 3 May 2022 15:08:19 -0400 Subject: [PATCH 2/6] adjusted endpoint and logic --- src/constants/endpoints.js | 4 ++-- src/constants/store-actions.js | 2 +- src/global-methods.js | 5 ++++- src/mixins/analytics-mixin.js | 2 +- src/router/index.js | 7 +++++-- src/store/index.js | 6 +++--- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index ca1555e7b..13ad55b34 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -75,8 +75,8 @@ const endpoints = { url: "/analytics/api/v1/analytics/activity", 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 74dac5043..fe100d5e3 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -20,7 +20,7 @@ const storeActions = { VALIDATE_ZIP: "validateZip", LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", LOG_ACTIVITY: "logActivity", - GET_EXPERIMENTS_BY_USER_FOR_GA: "getExperimentsByUserForGa", + GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser", // DEPENDENCY MUTATIONS RESET_VEHICLE_STATE_AND_DEPENDENCIES: "resetVehicleAndDependencies", diff --git a/src/global-methods.js b/src/global-methods.js index 5e4d04ea3..71f153bdf 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -7,7 +7,10 @@ import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; export default { callHttpClient({ method, endpoint, payload, logApiCall = true }) { return new Promise((resolve, reject) => { - const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; + let cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; + if(endpoint.includes("analytics")){ + cfDistroUrl = 'https://localhost:44324'; + } const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" }); axios({ method: method, url: cfDistroUrl + endpoint, data: payloadAndAnalyticsData, crossDomain: true, responseType: {} }) diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index 85402c8cb..d4cf7ccd1 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -62,7 +62,7 @@ export default { }, pushExperimentsToDataLayer(experiments) { - experiments?.data?.forEach(exp => { + experiments?.forEach(exp => { // Set Google Dimension Index based on experiment settings. let googleDimensionIndex = 99; 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 66005abd5..c12caff07 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -459,10 +459,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: {} }); }, From 57bd4dbaf75f788e10b1844ba0c8a1d3044763d1 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Tue, 3 May 2022 15:09:50 -0400 Subject: [PATCH 3/6] removed temp code --- src/global-methods.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/global-methods.js b/src/global-methods.js index 71f153bdf..5e4d04ea3 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -7,10 +7,7 @@ import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; export default { callHttpClient({ method, endpoint, payload, logApiCall = true }) { return new Promise((resolve, reject) => { - let cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; - if(endpoint.includes("analytics")){ - cfDistroUrl = 'https://localhost:44324'; - } + const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" }); axios({ method: method, url: cfDistroUrl + endpoint, data: payloadAndAnalyticsData, crossDomain: true, responseType: {} }) From 809c6d7aa95020a4f39c8b433c11a3b548a9cc08 Mon Sep 17 00:00:00 2001 From: FrankRua Date: Tue, 3 May 2022 15:33:56 -0400 Subject: [PATCH 4/6] mapping --- src/mixins/analytics-mixin.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index d4cf7ccd1..36ec73fe4 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -72,11 +72,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); From fc0ea703bac9f5cd65d874a025cef336e108854b Mon Sep 17 00:00:00 2001 From: FrankRua Date: Tue, 3 May 2022 15:46:32 -0400 Subject: [PATCH 5/6] fix unit tests --- src/mixins/analytics-mixin.spec.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/mixins/analytics-mixin.spec.js b/src/mixins/analytics-mixin.spec.js index ae1ba00a7..1e29e35de 100644 --- a/src/mixins/analytics-mixin.spec.js +++ b/src/mixins/analytics-mixin.spec.js @@ -40,21 +40,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' + }]); }); @@ -62,21 +68,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 From e3bf843e0a45042e3b3ed1f840375deef138a484 Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 3 May 2022 16:28:09 -0400 Subject: [PATCH 6/6] CSR-113 Edit comment --- src/constants/application-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/application-config.js b/src/constants/application-config.js index 5f5e77cdc..0d173db19 100644 --- a/src/constants/application-config.js +++ b/src/constants/application-config.js @@ -5,7 +5,7 @@ const applicationConfig = { ANALYTICS_SESSION_TIMEOUT_MINUTES: 30, SAVED_SESSION_TIMEOUT_DAYS: 45, COOKIE_PATH: "/", - CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT // Current environment following SV2's EnvironmentConfiguration.SV2Environment + CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT // "Localhost", "Dev", "QA", and "Prod" }; export { applicationConfig }; \ No newline at end of file