1.1.0 • Published 1 year ago

optimize-abtest v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

npm (scoped)

Use optimize-abtest in code

  1. Install npm i optimize-abtest or yarn add optimize-abtest
  2. Import import useAbTest from 'optimize-abtest'
  3. Use const { variant } = useAbTest('<yourAbTestName>'); to compare with string variant1 or variant2
  4. Or simply use const { isExperienceActive } = useAbTest('<yourAbTestName>'); if there's only 1 variant available

Set up Google Optimize experiment

  1. Create a new experiment
  2. Add a variant to it
  3. Edit Global JavaScript in the variant
  4. Add the next two lines of code listed below:
window.dispatchEvent(new CustomEvent('<yourAbTestName>', {detail: 'variant1'}));
document.cookie = "<yourAbTestName>=variant1";

A bit of explanation here

The package uses a session-long cookie named <yourAbTestName> and one of its corresponding values either variant1 or variant2. const { variant } = useAbTest('<yourAbTestName>'); returns one of the strings either variant1 or variant2. Alternatively, you can import a boolean isExperienceActive witch return either variant1 is active or not.

1.1.0

1 year ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

0.3.13

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.10

3 years ago

0.3.9

3 years ago