woocommerce/packages/js/explat
moon 9faccc176f Remove unused LoadingExperience 2022-05-13 14:23:40 -07:00
..
changelog Add changelog 2022-05-12 14:39:37 -07:00
src Update woo.explat to check fetchExperimentAssignment params 2022-05-03 17:01:07 +08:00
.eslintrc.js Add .eslintrc config to each packages 2022-03-29 16:08:07 +08:00
.npmrc Moved WCA Packages 2022-03-18 14:25:26 -07:00
CHANGELOG.md Update ExPlat changelog 2022-05-12 14:37:18 -07:00
README.md Remove unused LoadingExperience 2022-05-13 14:23:40 -07:00
composer.json Packages: Add Changelogger scripts (#32813) 2022-05-05 15:26:36 +12:00
composer.lock Packages: Add Changelogger scripts (#32813) 2022-05-05 15:26:36 +12:00
jest.config.json Moved WCA Packages 2022-03-18 14:25:26 -07:00
package.json Packages: Add Changelogger scripts (#32813) 2022-05-05 15:26:36 +12:00
project.json Add build-watch to most js packages and remove packages watch from woocommerce-admin command 2022-03-30 11:46:12 -03:00
tsconfig-cjs.json Added EOF Newlines 2022-05-10 13:35:31 -07:00
tsconfig.json Add Typescript type declarations for js packages 2022-04-15 13:50:17 +08:00

README.md

ExPlat

This packages includes a component and utility functions that can be used to run A/B Tests in WooCommerce dashboard and reports pages.

Installation

Install the module

pnpm install @woocommerce/explat --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Usage with Experiment Component

import { Experiment } from '@woocommerce/explat';

const DefaultExperience = <div>Hello World</div>;

const TreatmentExperience = <div>Hello WooCommerce!</div>;

const LoadingExperience = <div></div>;

<Experiment
	name="woocommerce_example_experiment"
	defaultExperience={ DefaultExperience }
	treatmentExperience={ TreatmentExperience }
	loadingExperience={ LoadingExperience }
/>;

// Get the experiment assignment with authentication as a WPCOM user.
import { ExperimentWithAuth } from '@woocommerce/explat';

<ExperimentWithAuth
	name="woocommerce_example_experiment"
	defaultExperience={ DefaultExperience }
	treatmentExperience={ TreatmentExperience }
	loadingExperience={ LoadingExperience }
/>;

Usage with useExperiment

import { useExperiment } from '@woocommerce/explat';

const DefaultExperience = <div>Hello World</div>;

const TreatmentExperience = <div>Hello WooCommerce!</div>;

const [ isLoadingExperiment, experimentAssignment ] = useExperiment('experiment-name');

if ( ! isLoadingExperiment && experimentAssignment?.variationName === 'treatment' ) {
	return <TreatmentExperience />
}

return <DefaultExperience />