File tree Expand file tree Collapse file tree 1 file changed +55
-1
lines changed Expand file tree Collapse file tree 1 file changed +55
-1
lines changed Original file line number Diff line number Diff line change 11# react-optimize
22
3- Integration with Google Optimize
3+ Integration with Google Optimize.
4+
5+ Docs:
6+ - Optimize Deploy with GTAG: https://support.google.com/optimize/answer/7513085
7+ - Optimize JS API: https://support.google.com/optimize/answer/9059383
8+
9+
10+ ## Instalation
11+ ```
12+ yarn add react-optimize
13+ ```
14+
15+ ## How to use
16+ You first need to add the gtag snippet with the optimize container id in it. If you are using [ create-react-app] ( https://github.com/facebook/create-react-app )
17+ you can add the following to ` public/index.html `
18+ ```
19+ <script async src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_GA_ID%"></script>
20+ <script>
21+ window.dataLayer = window.dataLayer || [];
22+ gtag = function () { dataLayer.push(arguments); }
23+ gtag('js', new Date());
24+
25+ gtag('config', '%REACT_APP_GA_ID%', { 'optimize_id': '%REACT_APP_OPTIMIZE_ID%'});
26+ </script>
27+ ```
28+
29+ and define them in your ` .env `
30+ ```
31+ REACT_APP_GA_ID=UA-xyz
32+ REACT_APP_OPTIMIZE_ID=GTM-abc
33+ ```
34+
35+ After that you can use the lib like the following:
36+ ```
37+ import React from 'react';
38+ import { Experiment, Variant } from "react-optimize";
39+
40+ class App extends React.Component {
41+ render() {
42+ return(
43+ <Experiment id="<experiment-id>">
44+ <Variant id="0">
45+ Original
46+ </Variant>
47+ <Variant id="1">
48+ Variant 1
49+ </Variant>
50+ <Variant id="2">
51+ Variant 2
52+ </Variant>
53+ </Experiment>
54+ )
55+ }
56+ }
57+ ```
You can’t perform that action at this time.
0 commit comments