Configuration

persistVariants

  • Type: boolean
  • Default: true
  • Description: This option determines whether to persist the A/B test variants across user sessions. When enabled (true), the assigned variant for each user is stored in a cookie on the user's device. This persistence ensures that once a user has been assigned a variant, they will experience consistent behavior across multiple sessions and visits.

variantMaxAge

  • Type: number
  • Default: 2592000 (equivalent to 30 days)
  • Description: Specifies the maximum age, in seconds, for the cookie that persists the A/B test variant assignment. This duration controls how long the user's variant assignment is remembered before it's considered expired. Once expired, the user may be assigned a new variant upon their next visit.

tests

  • Type: ABTest[]
  • Default: []
  • Description: A list of A/B tests defined within the application. This array should include all the A/B tests you intend to run, each represented by an ABTest object. The framework uses this list to automatically generate the necessary components and composables for implementing the A/B tests in your application.

Example Configuration

Here is an example of how you might configure the A/B testing module within your application:

export default defineNuxtConfig({
  modules: ['.nuxt-ab-testing'],
  abTesting: {
    persistVariants: true,
    variantMaxAge: 60 * 60 * 7,
    tests: [
      {
        id: 'example-test',
        variants: [
          { id: 'variant-a', value: 'Variant A' },
          { id: 'variant-b', value: 'Variant B' },
        ],
      },
    ]
  }
})