Socket
Book a DemoInstallSign in
Socket

@quotientjs/react

Package Overview
Dependencies
Maintainers
4
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quotientjs/react

React provider for the Quotient SDK client.

0.8.8
latest
npmnpm
Version published
Weekly downloads
152
3700%
Maintainers
4
Weekly downloads
 
Created
Source

@quotientjs/react

React provider for the Quotient SDK client.

Installation

npm install @quotientjs/react
# or
yarn add @quotientjs/react
# or
pnpm add @quotientjs/react

Usage

Provider Setup

Wrap your application with the QuotientProvider:

import { QuotientProvider } from "@quotientjs/react";

function App() {
  return (
    <QuotientProvider
      clientOptions={{
        apiKey: "your_api_key",
        baseUrl: "https://api.quotient.com",
      }}
      // Automatically track page views on initial load and route changes
      autoTrackPageViews={true}
    >
      <YourApp />
    </QuotientProvider>
  );
}

Using the Client

Access the Quotient client with the useQuotient hook:

import { useQuotient } from "@quotientjs/react";

function YourComponent() {
  // Get the client context - includes all needed functionality
  const { client, isInitializing, error, reset, trackPageView } = useQuotient();

  // Example: manually track page view
  const handleTrackPageView = () => {
    trackPageView();
  };

  // Example: track a person
  const handleSubmit = async (email) => {
    if (client) {
      await client.people.upsert({
        emailAddress: email,
        emailMarketingState: "SUBSCRIBED",
      });
    }
  };

  return (
    <div>
      {isInitializing ? (
        <p>Initializing client...</p>
      ) : error ? (
        <p>Error: {error.message}</p>
      ) : (
        <p>Client ready!</p>
      )}

      <button onClick={handleTrackPageView}>Track Page View</button>
      <button onClick={reset}>Reset Client</button>
    </div>
  );
}

Automatic Page View Tracking

When autoTrackPageViews is enabled, the provider will:

  • Track a page view when the component mounts
  • Track page views when the pathname changes (works with history API)
  • Works with most modern React routers like React Router

This is ideal for Single Page Applications where you want analytics for each virtual page.

Additional Hooks

For components that only need to know the client status:

import { useQuotientStatus } from "@quotientjs/react";

function ClientStatus() {
  // Get just the client status without the client itself
  const { isInitializing, error } = useQuotientStatus();

  return (
    <div>
      {isInitializing
        ? "Initializing..."
        : error
          ? `Error: ${error.message}`
          : "Ready"}
    </div>
  );
}

Manual Initialization

If you need to initialize the client manually:

import { QuotientProvider, useQuotient } from "@quotientjs/react";

function App() {
  return (
    <QuotientProvider
      clientOptions={{
        apiKey: "your_api_key",
        baseUrl: "https://api.quotient.com",
      }}
      autoInitialize={false}
    >
      <InitializeButton />
    </QuotientProvider>
  );
}

function InitializeButton() {
  const { initialize, isInitializing, client } = useQuotient();

  return (
    <div>
      {client ? (
        <p>Client initialized!</p>
      ) : (
        <button onClick={initialize} disabled={isInitializing}>
          {isInitializing ? "Initializing..." : "Initialize Client"}
        </button>
      )}
    </div>
  );
}

License

MIT

FAQs

Package last updated on 26 Aug 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.