Library for using the Unify Intent JS Client in a React app.
npm install @unifygtm/intent-reactyarn add @unifygtm/intent-reactWrap 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]);
};