Skip to content

Commit

Permalink
Redirect A/B test variant page to home (#2764)
Browse files Browse the repository at this point in the history
<!--
PR title: GRW-123 / Feature / Awesome new thing
-->

## Describe your changes

<!--
What changes are made?
If there are many changes, a list might be a good format.
If it makes sense, add screenshots and/or screen recordings here.
-->

## Justify why they are needed

## Checklist before requesting a review

- [ ] I have performed a self-review of my code
  • Loading branch information
gustaveen committed Jul 17, 2023
1 parent d9809ad commit a371b95
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 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"
}
]
}
24 changes: 22 additions & 2 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']
const shutDownMarketsInfo = [
...locales.map((locale) => ({
Expand Down Expand Up @@ -133,7 +134,7 @@ module.exports = withBundleAnalyzer({
},
]
: []
return [...shutDownMarketsInfo, ...oldSiteCampaigns]
return [...shutDownMarketsInfo, ...oldSiteCampaigns, ...getExperimentVariantRedirects()]
},
})

Expand All @@ -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)
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

1 comment on commit a371b95

@vercel
Copy link

@vercel vercel bot commented on a371b95 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.