All Projects → nuxt-community → Google Optimize Module

nuxt-community / Google Optimize Module

Licence: mit
SSR friendly Google Optimize module for Nuxt.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Google Optimize Module

Auth Module
auth.nuxtjs.org
Stars: ✭ 1,624 (+802.22%)
Mutual labels:  nuxt, module, ssr
Virapro.ru
[E-commerce] Plumbing Store
Stars: ✭ 45 (-75%)
Mutual labels:  nuxt, ssr
Nuxt Client Init Module
Provide client version of nuxtServerInit
Stars: ✭ 176 (-2.22%)
Mutual labels:  nuxt, module
Vue Masonry Wall
A pure vue responsive masonry layout without direct dom manipulation and ssr support.
Stars: ✭ 79 (-56.11%)
Mutual labels:  nuxt, ssr
Nuxt Static Render
Nuxt module for SSR without rehydration payload
Stars: ✭ 32 (-82.22%)
Mutual labels:  nuxt, ssr
Veluxi Starter
Veluxi Vue.js Starter Project with Nuxt JS and Vuetify
Stars: ✭ 39 (-78.33%)
Mutual labels:  nuxt, ssr
Laravel Vuejs.com
Laravel and VueJs Blog, using Laravel nova, GraphQL, NuxtJs, Apollo and ...more
Stars: ✭ 54 (-70%)
Mutual labels:  nuxt, ssr
Hackernews
HackerNews clone built with Nuxt.js
Stars: ✭ 758 (+321.11%)
Mutual labels:  nuxt, ssr
Nuxt Env
Inject env vars for your Nuxt app at runtime
Stars: ✭ 169 (-6.11%)
Mutual labels:  nuxt, ssr
Naice Blog
😺 新的博客上线啦
Stars: ✭ 93 (-48.33%)
Mutual labels:  nuxt, ssr
Laravel Nuxt
A Laravel-Nuxt starter kit.
Stars: ✭ 943 (+423.89%)
Mutual labels:  nuxt, ssr
Nuxt Image Loader Module
An image loader module for nuxt.js that allows you to configure image style derivatives.
Stars: ✭ 135 (-25%)
Mutual labels:  nuxt, module
Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+21558.89%)
Mutual labels:  nuxt, ssr
Axios Module
Secure and easy axios integration with Nuxt.js
Stars: ✭ 998 (+454.44%)
Mutual labels:  nuxt, ssr
Essay
A blog system based on Nuxt.js
Stars: ✭ 913 (+407.22%)
Mutual labels:  nuxt, ssr
Hapi Nuxt
Nuxt.js plugin for Hapi.js
Stars: ✭ 46 (-74.44%)
Mutual labels:  nuxt, ssr
Wemake Vue Template
Bleeding edge vue template focused on code quality and developer happiness.
Stars: ✭ 645 (+258.33%)
Mutual labels:  nuxt, ssr
Vuecnodejs
⚽️🎉Vue初/中级项目,CnodeJS社区重构。( a junior project of Vue.js, rewrite cnodejs.org ) 预览(DEMO):
Stars: ✭ 705 (+291.67%)
Mutual labels:  nuxt, ssr
Sails Nuxt
Sails + Nuxt + Vuetify Combo <3
Stars: ✭ 92 (-48.89%)
Mutual labels:  nuxt, ssr
Surmon.me
🆒 My personal website and blog, powered by @vuejs (3)
Stars: ✭ 1,767 (+881.67%)
Mutual labels:  nuxt, ssr

nuxt-google-optimize

npm (scoped with tag) npm CircleCI Codecov Dependencies js-standard-style

SSR friendly Google Optimize module for Nuxt.js

📖 Release Notes

Features

  • Support multiple experiments (AB or MVT[Multi-Variant])
  • Auto assign experiment/variant to users
  • SSR support using cookies
  • CSS and state injection
  • Automatically revoke expired experiments from testers
  • Ability to assign experiments based on context conditions (Route, State, etc)

Setup

  • Add nuxt-google-optimize dependency using yarn or npm to your project
yarn add nuxt-google-optimize

OR

npm install nuxt-google-optimize --save
  • Add nuxt-google-optimize to modules section of nuxt.config.js
{
  modules: [
    'nuxt-google-optimize',
  ],

  // Optional options
  googleOptimize: {
    // experimentsDir: '~/experiments',
    // maxAge: 60 * 60 * 24 * 7 // 1 Week
    // pushPlugin: true,
    // excludeBots: true,
    // botExpression: /(bot|spider|crawler)/i
  }
}

Usage

Create experiments directory inside your project.

Create experiments/index.js to define all available experiments:

import backgroundColor from './background-color'

export default [
  backgroundColor
]

Creating an experiment

Each experiment should export an object to define itself.

experiments/background-color/index.js:

export default {
  // A helper exp-{name}-{var} class will be added to the root element
  name: 'background-color',

  // Google optimize experiment id
  experimentID: '....',

  // [optional] specify number of sections for MVT experiments
  // sections: 1,

  // [optional] maxAge for a user to test this experiment
  // maxAge: 60 * 60 * 24, // 24 hours,

  // [optional] Enable/Set experiment on certain conditions
  // isEligible: ({ route }) => route.path !== '/foo'

  // Implemented variants and their weights
  variants: [
    { weight: 0 }, // <-- This is the default variant
    { weight: 2 },
    { weight: 1 }
  ],
}

$exp

Global object $exp will be universally injected in the app context to determine the currently active experiment.

It has the following keys:

{
  // Index of currently active experiment
  "$experimentIndex": 0,

  // Index of currently active experiment variants
  "$variantIndexes": [
    1
  ],

  // Same as $variantIndexes but each item is the real variant object
  "$activeVariants": [
    {
      /* */
    }
  ],

  // Classes to be globally injected (see global style tests section)
  "$classes": [
    "exp-background-color-1" // exp-{experiment-name}-{variant-id}
  ],

  // All of the keys of currently active experiment are available
  "name": "background-color",
  "experimentID": "testid",
  "sections": 1,
  "maxAge": 60,
  "variants": [
    /* all variants */
  ]
}

Using inside components:

<script>
export default {
  methods: {
    foo() {
      // You can use this.$exp here
    }
  }
}
</script>

Using inside templates:

<div v-if="$exp.name === 'something'">
  <!-- You can optionally use $exp.$activeVariants and $exp.$variantIndexes here -- >
  ...
</div>
<div v-else>
  ...
</div>

Global style tests

Inject global styles to page body.

layouts/default.vue:

<template>
  <nuxt/>
</template>

<script>
export default {
      head () {
        return {
            bodyAttrs: {
                class: this.$exp.$classes.join(' ')
            }
        }
    },
}
</script>

If you have custom CSS for each test, you can import it inside your experiment's .js file.

experiments/background-color/index.js:

import './styles.scss'

With Sass:

.exp-background-color {
  // ---------------- Variant 1 ----------------
  &-1 {
    background-color: red;
  }
  // ---------------- Variant 2 ----------------
  &-2 {
    background-color: blue;
  }
}

With CSS:

/* Variant 1 */
.exp-background-color-1 {
  background-color: red;
}

/* Variant 2 */
.exp-background-color-2 {
  background-color: blue;
}

Development

  • Clone this repository
  • Install dependencies using yarn install or npm install
  • Start development server using yarn run dev or npm run dev
  • Point your browser to http://localhost:3000
  • You will see a different colour based on the variant set for you
  • In order to test your luck, try clearing your cookies and see if the background colour changes or not

License

MIT License - Alibaba Travels Co

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].