Set up HumanBehavior SDK with Remix applications
npm install humanbehavior-js # or yarn add humanbehavior-js
app/root.tsx
import { HumanBehaviorTracker } from 'humanbehavior-js'; import { useEffect } from 'react'; export default function App() { useEffect(() => { // Initialize the tracker once globally (client-side only) const tracker = HumanBehaviorTracker.init('your-api-key-here'); }, []); return ( <html lang="en"> <head> <Meta /> <Links /> </head> <body> <Outlet /> <ScrollRestoration /> <Scripts /> <LiveReload /> </body> </html> ); }
import { HumanBehaviorTracker } from 'humanbehavior-js'; import { useEffect, useLocation } from 'react'; export default function App() { const location = useLocation(); let tracker: any; useEffect(() => { tracker = HumanBehaviorTracker.init('your-api-key-here'); }, []); useEffect(() => { if (tracker) { // Track route changes tracker.trackPageView(location.pathname); } }, [location, tracker]); return ( <html lang="en"> <head> <Meta /> <Links /> </head> <body> <Outlet /> <ScrollRestoration /> <Scripts /> <LiveReload /> </body> </html> ); }
import { useEffect } from 'react'; import { HumanBehaviorTracker } from 'humanbehavior-js'; export default function MyComponent() { useEffect(() => { const tracker = HumanBehaviorTracker.init('your-api-key-here'); // Track component view tracker.customEvent('component_viewed', { componentName: 'MyComponent' }); }, []); const handleButtonClick = async () => { const tracker = HumanBehaviorTracker.init('your-api-key-here'); await tracker.customEvent('button_clicked', { buttonLocation: 'header' }); }; return ( <div> <h1>My Component</h1> <button onClick={handleButtonClick}>Click Me</button> </div> ); }
.env
HUMANBEHAVIOR_API_KEY=your-api-key-here
import { HumanBehaviorTracker } from 'humanbehavior-js'; const apiKey = process.env.HUMANBEHAVIOR_API_KEY; const tracker = HumanBehaviorTracker.init(apiKey);