Skip to content

Commit a7eb6c5

Browse files
author
Hudo Assenco
committed
Update README.md
1 parent f6c3317 commit a7eb6c5

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
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+
```

0 commit comments

Comments
 (0)