This example demonstrates how to integrate HawkEye Observer SDK into a React application.
npm install @hawkeye/observer-sdkimport React, { useEffect } from 'react';
import { initFrustrationObserver, teardown } from '@hawkeye/observer-sdk';
function App() {
useEffect(() => {
initFrustrationObserver({
apiKey: 'your-api-key-here',
ingestionUrl: 'https://api.hawkeye.example.com',
enableDebug: process.env.NODE_ENV === 'development',
environment: process.env.NODE_ENV,
});
return () => {
teardown();
};
}, []);
return <div>Your App</div>;
}For cleaner code, use the provided useHawkEye hook:
import { useHawkEye } from './useHawkEye';
function App() {
useHawkEye({
apiKey: 'your-api-key-here',
ingestionUrl: 'https://api.hawkeye.example.com',
enableDebug: process.env.NODE_ENV === 'development',
});
return <div>Your App</div>;
}import { captureEvent } from '@hawkeye/observer-sdk';
function PremiumButton() {
const handleUpgrade = () => {
captureEvent(
'upgrade_clicked',
{ type: 'button', id: 'premium-upgrade' },
{ plan: 'premium', price: 29.99 }
);
};
return <button onClick={handleUpgrade}>Upgrade to Premium</button>;
}- Initialize Early: Place initialization in your root App component
- Environment Detection: Use
process.env.NODE_ENVfor automatic environment detection - Debug Mode: Enable debug mode in development to see SDK logs
- Cleanup: Always call
teardown()in the useEffect cleanup function - Single Instance: Only initialize once in your application
HawkEye automatically tracks:
- Click events
- Form inputs (content not captured, only interactions)
- Scroll behavior
- JavaScript errors
- Page navigation
- Route changes (React Router compatible)
- No sensitive data: Input values are never captured
- No passwords: Password fields are ignored
- No PII: Personal information is not collected
- GDPR compliant: Only behavioral signals are tracked