@jitsu/jitsu-react
Advanced tools
Comparing version 1.5.1 to 1.6.1
{ | ||
"name": "@jitsu/jitsu-react", | ||
"version": "1.5.1", | ||
"version": "1.6.1", | ||
"description": "", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@jitsu/js": "1.5.1" | ||
"@jitsu/js": "1.6.1" | ||
}, | ||
@@ -17,0 +17,0 @@ "peerDependencies": { |
@@ -14,40 +14,2 @@ # jitsu-react | ||
To setup Jitsu-React library you need to add `JitsuProvider` component close to the root level of your app: | ||
```tsx | ||
import React from "react"; | ||
import { JitsuProvider } from "@jitsu/jitsu-react"; | ||
export default function App() { | ||
return <JitsuProvider options={{ host: "https://<id>.d.jitsu.com" }}> | ||
<Page /> | ||
</JitsuProvider>; | ||
} | ||
``` | ||
Then use `useJitsu` hook in components where you want to track events. | ||
```tsx | ||
import * as React from "react"; | ||
import { useJitsu } from "@jitsu/jitsu-react"; | ||
import { useEffect } from "react"; | ||
export default function Page() { | ||
const { analytics } = useJitsu(); | ||
useEffect(() => { | ||
// Track page view | ||
analytics.track("event", { prop: "value" }); | ||
}, [location]); | ||
return ( | ||
<div> | ||
<button onClick={() => analytics.track("button-click")}>Click me!</button> | ||
</div> | ||
); | ||
} | ||
``` | ||
As `location` you should use an value that changes on every navigation. Examples: | ||
* React Router: `useLocationHook()` | ||
* Next.js: `const rounter = useRouter()`; then `router.asPath` | ||
* Others: `[window.location.pathname, window.location.search, window.location.hash]` | ||
**Please read a documentation on [Jitsu Docs](https://docs.jitsu.com/sending-data/react)** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17670
15
+ Added@jitsu/js@1.6.1(transitive)
- Removed@jitsu/js@1.5.1(transitive)
Updated@jitsu/js@1.6.1