Troubleshooting
Common issues and their solutions when integrating the Userlens SDK.
Events Not Appearing in Userlens
Check 1: Verify Events Are Being Sent
Open browser DevTools → Network tab and look for requests to:
Proxy setup: Your backend endpoint (e.g.,
/api/userlens/events)Frontend-only:
raw.userlens.io
If no requests:
Ensure the provider is mounted and
userIdis setCheck that
configis notundefinedEnable debug mode to see console logs
Check 2: Verify Backend Is Forwarding (Proxy Setup)
Check your server logs for:
Incoming requests from the frontend
Outgoing requests to Userlens
Any error messages
Check 3: Verify Write Code
"window is not defined" Error
This happens when the SDK runs on the server (SSR).
Next.js App Router
Make sure your wrapper component has 'use client':
Next.js Pages Router
The SDK only runs client-side, but if you see this error, use dynamic import:
"useUserlens must be used within a UserlensProvider"
Your component is outside the provider tree.
Wrong:
Correct:
Collector is null / pushEvent Not Working
The collector is null until the provider mounts. This is normal during the first render.
Always use optional chaining:
For critical events, add a check:
Events Blocked by Ad Blockers
Ad blockers may block requests to userlens.io domains.
Solution: Use the proxy setup. Events go to your domain first, then your backend forwards to Userlens.
Page Views Not Tracked on Localhost
This is intentional. The SDK skips page view tracking on:
localhost127.0.0.1::1*.localhost
This prevents development traffic from polluting your analytics. Click events and custom events are still tracked.
To test page views, deploy to a staging environment or use a tool like ngrok.
Provider Re-initializing Repeatedly
If you see "EventCollector already initialized" warnings, your config object is being recreated on every render.
Wrong:
Correct:
TypeScript Errors
"Property 'pushEvent' does not exist on type 'null'"
The hook returns { collector: EventCollector | null }. Use optional chaining:
Config Type Mismatch
If TypeScript complains about your config, ensure you're using the correct mode:
Events Have Wrong User ID
The SDK uses the userId from config at initialization time. If your user logs in after the page loads, the provider needs to reinitialize.
Solution: Include userId in your useMemo dependency array:
High Network Traffic / Too Many Requests
Events are batched every 5 seconds by default. If you're seeing too many requests:
Increase batch interval:
Disable click tracking if not needed:
Large Payloads / Performance Issues
DOM snapshots can be large for complex pages.
Use lighter snapshots:
This captures only the direct path to the clicked element instead of siblings.
Debug Mode
Enable detailed console logging:
Debug mode logs:
Initialization steps
Click handler setup
Event sending
Errors
Getting Help
If you're still having issues:
Enable
debug: trueand check console logsCheck Network tab for request/response details
Verify your Write Code at Userlens Settings
Contact support at support@userlens.io
Last updated