@unifygtm/intent-react
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Unify Intent React

Library for using the Unify Intent JS Client in a React app.

Installation

npm

npm install @unifygtm/intent-react

yarn

yarn add @unifygtm/intent-react

Usage

Wrap your React app in a UnifyIntentProvider:

import {
  UnifyIntentClient,
  UnifyIntentClientConfig,
  UnifyIntentProvider
} from '@unifygtm/intent-react';

const writeKey = 'YOUR_PUBLIC_API_KEY';

const config: UnifyIntentClientConfig = {
  autoPage: true,
  autoIdentify: false,
};

const intentClient = new UnifyIntentClient(writeKey, config);

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement,
);

root.render(
  <UnifyIntentProvider intentClient={intentClient}>
    <App />
  </UnifyIntentProvider>
);

Then, any components rendered in your app can access the intent client using the useUnifyIntent hook:

import { useUnifyIntent } from '@unifygtm/intent-react';

const SomeComponent = () => {
  // However you access the current user...
  const currentUser = useCurrentUser();

  const unify = useUnifyIntent();

  useEffect(() => {
    // Log an identify event for the current user
    unify.identify(currentUser.emailAddress);
  }, [currentUser.emailAddress]);
};

/@unifygtm/intent-react/

    Package Sidebar

    Install

    npm i @unifygtm/intent-react

    Weekly Downloads

    2,175

    Version

    1.2.0

    License

    UNLICENSED

    Unpacked Size

    40.8 kB

    Total Files

    14

    Last publish

    Collaborators

    • samwaterbury
    • connorunify
    • solomon-unifygtm