From ac35bd56feba0d62a7bfb73bb312af732e0842d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20E=C3=A9n?= Date: Fri, 14 Jul 2023 10:24:28 +0200 Subject: [PATCH 1/2] Redirect A/B test variant page to home --- apps/store/next.config.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/store/next.config.js b/apps/store/next.config.js index bc925a28b5..5113e7bdb0 100644 --- a/apps/store/next.config.js +++ b/apps/store/next.config.js @@ -108,6 +108,16 @@ module.exports = withBundleAnalyzer({ permanent: true, locale: false, })), + ...(process.env.NODE_ENV === 'production' + ? [ + { + source: `/se/start`, + destination: `/se`, + permanent: false, + locale: false, + }, + ] + : []), ] const oldSiteCampaigns = process.env.FEATURE_OLD_SITE_REDIRECTS === 'true' From 9a0df13522aed9714c76b722c8901574b39f8987 Mon Sep 17 00:00:00 2001 From: Robin Andeer Date: Mon, 17 Jul 2023 09:13:31 +0200 Subject: [PATCH 2/2] Store experiment setup in JSON file --- apps/store/experiment.json | 17 ++++++++++ apps/store/next.config.js | 34 ++++++++++++------- .../services/Tracking/experiment.constants.ts | 17 ++-------- 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 apps/store/experiment.json diff --git a/apps/store/experiment.json b/apps/store/experiment.json new file mode 100644 index 0000000000..e0a0b4c6e4 --- /dev/null +++ b/apps/store/experiment.json @@ -0,0 +1,17 @@ +{ + "name": "Start page", + "slug": "/se", + "variants": [ + { + "name": "Original", + "id": 0, + "weight": 50 + }, + { + "name": "Variant", + "id": 1, + "weight": 50, + "slug": "/start" + } + ] +} diff --git a/apps/store/next.config.js b/apps/store/next.config.js index 5113e7bdb0..b109b5ccf9 100644 --- a/apps/store/next.config.js +++ b/apps/store/next.config.js @@ -1,6 +1,7 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', }) +const experimentJson = require('./experiment.json') const { SiteCsp, StoryblokCsp } = require('./next-csp.config') const { i18n } = require('./next-i18next.config') @@ -93,7 +94,7 @@ module.exports = withBundleAnalyzer({ ], } }, - async redirects() { + redirects() { const locales = ['no', 'no-en', 'dk', 'dk-en'] const shutDownMarketsInfo = [ ...locales.map((locale) => ({ @@ -108,16 +109,6 @@ module.exports = withBundleAnalyzer({ permanent: true, locale: false, })), - ...(process.env.NODE_ENV === 'production' - ? [ - { - source: `/se/start`, - destination: `/se`, - permanent: false, - locale: false, - }, - ] - : []), ] const oldSiteCampaigns = process.env.FEATURE_OLD_SITE_REDIRECTS === 'true' @@ -143,7 +134,7 @@ module.exports = withBundleAnalyzer({ }, ] : [] - return [...shutDownMarketsInfo, ...oldSiteCampaigns] + return [...shutDownMarketsInfo, ...oldSiteCampaigns, ...getExperimentVariantRedirects()] }, }) @@ -166,5 +157,24 @@ const securityHeaders = [ }, ] +/** + * @returns {import('next').Redirect[]} + * */ +const getExperimentVariantRedirects = () => { + if (typeof process.env.NEXT_PUBLIC_EXPERIMENT_ID !== 'string') return [] + + const variantSlug = experimentJson.variants.find((item) => item.slug).slug + if (!variantSlug) return [] + + return [ + { + source: [experimentJson.slug, variantSlug].join(''), + destination: experimentJson.slug, + permanent: false, + locale: false, + }, + ] +} + // Don't delete this console log, useful to see the commerce config in Vercel deployments console.log('next.config.js %O', module.exports) diff --git a/apps/store/src/services/Tracking/experiment.constants.ts b/apps/store/src/services/Tracking/experiment.constants.ts index 9ca1698ca1..1e71c3b5b9 100644 --- a/apps/store/src/services/Tracking/experiment.constants.ts +++ b/apps/store/src/services/Tracking/experiment.constants.ts @@ -1,4 +1,5 @@ export const EXPERIMENT_COOKIE_NAME = 'hedvig-experiment' +import experimentJson from '../../../experiment.json' export type Experiment = { id: string @@ -18,21 +19,7 @@ const EXPERIMENT_ID = process.env.NEXT_PUBLIC_EXPERIMENT_ID export const CURRENT_EXPERIMENT: Experiment | undefined = EXPERIMENT_ID ? { - name: 'Start page', + ...experimentJson, id: EXPERIMENT_ID, - slug: '/se', - variants: [ - { - name: 'Original', - id: 0, - weight: 50, - }, - { - name: 'Variant', - id: 1, - weight: 50, - slug: '/start', - }, - ], } : undefined