Socket
Socket
Sign inDemoInstall

@jitsu/jitsu-react

Package Overview
Dependencies
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jitsu/jitsu-react


Version published
Weekly downloads
1.6K
decreased by-4.05%
Maintainers
3
Weekly downloads
 
Created
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

Package last updated on 20 Oct 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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc