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 bc925a28b5..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) => ({ @@ -133,7 +134,7 @@ module.exports = withBundleAnalyzer({ }, ] : [] - return [...shutDownMarketsInfo, ...oldSiteCampaigns] + return [...shutDownMarketsInfo, ...oldSiteCampaigns, ...getExperimentVariantRedirects()] }, }) @@ -156,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