Skip to content

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

Notifications You must be signed in to change notification settings

unifygtm/intent-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b3a6c31 · Dec 15, 2024

History

16 Commits
May 30, 2024
Jun 13, 2024
May 30, 2024
May 31, 2024
May 31, 2024
Jun 13, 2024
Dec 15, 2024
Dec 15, 2024
May 30, 2024
May 31, 2024
May 30, 2024

Repository files navigation

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]);
};

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published