Socket
Socket
Sign inDemoInstall

@jitsu/jitsu-react

Package Overview
Dependencies
1
Maintainers
3
Versions
77
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jitsu/jitsu-react


Version published
Maintainers
3
Created

Readme

Source

jitsu-react

NPM

Install

npm install --save @jitsu/jitsu-react

Usage

To setup Jitsu-React library you need to add JitsuProvider component close to the root level of your app:

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.

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]

FAQs

Last updated on 26 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc