Skip to content

Commit

Permalink
Store experiment setup in JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
robinandeer committed Jul 17, 2023
1 parent e9a618a commit ae1a329
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
17 changes: 17 additions & 0 deletions apps/store/experiment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Start page",
"slug": "/se",
"variants": [
{
"name": "Original",
"id": 0,
"weight": 50
},
{
"name": "Variant",
"id": 1,
"weight": 50,
"slug": "/start"
}
]
}
33 changes: 22 additions & 11 deletions apps/store/next.config.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -93,7 +94,7 @@ module.exports = withBundleAnalyzer({
],
}
},
async redirects() {
redirects() {
const locales = ['no', 'no-en', 'dk', 'dk-en']

return [
Expand All @@ -109,16 +110,7 @@ module.exports = withBundleAnalyzer({
permanent: true,
locale: false,
})),
...(process.env.NODE_ENV === 'production'
? [
{
source: `/se/start`,
destination: `/se`,
permanent: false,
locale: false,
},
]
: []),
...getExperimentVariantRedirects(),
]
},
})
Expand All @@ -142,5 +134,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)
17 changes: 2 additions & 15 deletions apps/store/src/services/Tracking/experiment.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const EXPERIMENT_COOKIE_NAME = 'hedvig-experiment'
import experimentJson from '../../../experiment.json'

export type Experiment = {
id: string
Expand All @@ -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

0 comments on commit ae1a329

Please sign in to comment.