A powerful SDK for tracking user sessions, interactions, and API calls in Next.js applications.
- User session tracking
- Click event tracking with element paths
- API call interception (both fetch and axios)
- Tab visibility tracking
- Automatic event batching and sending
- TypeScript support
npm install circuit-sdk
# or
yarn add circuit-sdk
// In your _app.tsx or similar entry point
import { useCircuit } from "circuit-sdk";
function MyApp({ Component, pageProps }) {
useCircuit({
apiKey: "your-api-key",
debug: true, // Optional, enables console logging
});
return <Component {...pageProps} />;
}
export default MyApp;
If you need more control over the Circuit instance:
import { initCircuit } from "circuit-sdk";
const circuit = initCircuit({
apiKey: "your-api-key",
});
The SDK automatically tracks:
-
Session Events
- Session start/end
- Includes unique session ID
-
Click Events
- Coordinates (x, y)
- Target element
- Element path in DOM
-
API Calls
- URL
- Method
- Status
- Error information (if any)
-
Tab Visibility
- Tracks when user switches tabs
- Records timestamps for video pause points
Events are automatically sent to Circuit's servers in the following format:
{
sessionId: string;
events: Array<{
type:
| "click"
| "api_call"
| "tab_visibility"
| "session_start"
| "session_end";
timestamp: number;
data: {
// Varies based on event type
};
}>;
}
Option | Type | Required | Description |
---|---|---|---|
apiKey | string | Yes | Your Circuit API key |
debug | boolean | No | Enable console logging of events |
- Initialize the SDK as early as possible in your application
- Use the
useCircuit
hook in your top-level component - Enable debug mode during development
MIT