Why use a separate providers file? This pattern keeps your app layout as a Server Component while only making the provider client-side. This preserves the performance benefits of Server Components and ensures optimal rendering.
That’s it! The SDK now automatically tracks user interactions, navigation, and console events. Everything past here is optional.
If you prefer manual setup, you can initialize the tracker directly:
Copy
'use client'; // This line is CRUCIAL - it tells Next.js this is a client componentimport { useEffect } from 'react';import { HumanBehaviorTracker } from 'humanbehavior-js';function MyApp({ Component, pageProps }) { useEffect(() => { // Initialize the tracker once globally const tracker = HumanBehaviorTracker.init(process.env.NEXT_PUBLIC_HUMANBEHAVIOR_API_KEY); }, []); return <Component {...pageProps} />;}export default MyApp;