Package Exports
- @unifygtm/intent-react
- @unifygtm/intent-react/dist/js/index.cjs.js
- @unifygtm/intent-react/dist/js/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@unifygtm/intent-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Unify Intent React
Library for using the Unify Intent JS Client in a React app.
Installation
npm
npm install @unifygtm/intent-reactyarn
yarn add @unifygtm/intent-reactUsage
Wrap your React app in a UnifyIntentProvider:
import { UnifyIntentProvider, UnifyIntentClientConfig } from '@unifygtm/intent-react';
const writeKey = 'YOUR_PUBLIC_API_KEY';
const config: UnifyIntentClientConfig = {
autoPage: true,
autoIdentify: false,
};
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement,
);
root.render(
<UnifyIntentProvider writeKey={writeKey} config={config}>
<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]);
};