Skip to content

Commit 8fd5c5f

Browse files
JeanMeijeradriaandotcom
authored andcommitted
Add React package docs
1 parent b8e83e6 commit 8fd5c5f

File tree

1 file changed

+49
-6
lines changed

1 file changed

+49
-6
lines changed

_docs/31_integrations/00_react.md

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,58 @@ title: Install Simple Analytics with React
33
hidden: true
44
category: integrations
55
permalink: /install-simple-analytics-with-react
6-
last_modified_at: 2022-04-14
6+
last_modified_at: 2025-10-22
77
---
88

9-
Most projects have the structure of `npx create-react-app my-app`. Let's follow that structure.
9+
Add Simple Analytics to React apps with our official React package.
1010

11-
You don't need any dependency to install Simple Analytics.
11+
## Install
1212

13-
1. Go to your HTML file: usually in `public/index.html`
14-
2. Paste the embed code from [how to add our script](/script) at the end of body of that file.
15-
3. Save this file and you're done!
13+
Run this command to install Simple Analytics for React:
14+
15+
```bash
16+
npm i @simpleanalytics/react
17+
```
18+
19+
## Usage
20+
21+
Import the `<SimpleAnalytics />` to start tracking pageviews
22+
23+
```tsx
24+
import { SimpleAnalytics } from "@simpleanalytics/react";
25+
26+
export function App() {
27+
return (
28+
<>
29+
{/* your app */}
30+
<SimpleAnalytics />
31+
</>
32+
);
33+
}
34+
```
35+
36+
## Options
37+
38+
- **Custom domain**: see [/bypass-ad-blockers](/bypass-ad-blockers)
39+
40+
```tsx
41+
<SimpleAnalytics domain="custom.domain.com" />
42+
```
43+
44+
## Send events
45+
46+
```tsx
47+
import { trackEvent } from "@simpleanalytics/react";
48+
49+
function Button() {
50+
return (
51+
<button onClick={() => trackEvent("clicked")}>
52+
Track event
53+
</button>
54+
);
55+
}
56+
```
57+
58+
Note: `trackEvent` requires `<SimpleAnalytics />` to be present in your app.
1659

1760
If you encounter issues, don't hesitate to contact us via [our support channels](https://simpleanalytics.com/contact).

0 commit comments

Comments
 (0)