google-optimize-react-hooks

0.0.6 • Public • Published

Google Optimize React Hooks

Installation

npm i google-optimize-react-hooks

Usage

React

import React from 'react';
import { useGoogleOptimizeSPA } from 'google-optimize-react-hooks';

function Home(props) {
    const [loading, variant] = useGoogleOptimizeSPA(
        '[experimentID]',
        '[customEventName]'
    );

    if (loading) return null; // Or a loading indicator

    if (variant === '0') {
        return <OriginalExperiment />
    }

    if (variant === '1') {
        return <ExperimentA />
    }

    ...
}

Don't forget to put the anti-flicker snippet code provided by Google Optimize in <HEAD> section of every page.

Readme

Keywords

none

Package Sidebar

Install

npm i google-optimize-react-hooks

Weekly Downloads

7

Version

0.0.6

License

MIT

Unpacked Size

28.1 kB

Total Files

12

Last publish

Collaborators

  • anwar