Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect A/B test variant page to home #2764

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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