How to enable event autocapture on PostHog
Event autocapture in PostHog can be enabled through the project settings by toggling the autocapture option and configuring the JavaScript snippet. This feature automatically tracks clicks, form submissions, and page views without manual event tracking code.
Prerequisites
- PostHog account with admin access
- PostHog JavaScript library installed on your website
- Project created in PostHog dashboard
- Basic understanding of web analytics concepts
Step-by-Step Instructions
Access your PostHog project dashboard
Navigate to autocapture settings
Enable autocapture features
ON. This will automatically capture clicks, form submissions, and other interactions. Also enable Capture pageviews and Capture pageleaves if you want to track page navigation events.Configure autocapture options
Example allowlist:
.track-button, #signup-formUpdate your JavaScript snippet
posthog.init('your-api-key', {
api_host: 'https://app.posthog.com',
autocapture: true
})Deploy the updated snippet
<head> section with the updated code. Make sure the autocapture: true option is present in the initialization configuration.Verify autocapture is working
$autocapture events are being recorded. You should see events with details about the captured interactions.Configure event filtering and processing
Common Issues & Troubleshooting
Autocapture events not appearing in dashboard
Check that the JavaScript snippet is properly installed and autocapture: true is set in the configuration. Verify there are no browser console errors and that your website can reach PostHog's servers.
Too many irrelevant events being captured
Use the CSS selector denylist in autocapture settings to exclude unwanted elements. Add selectors like .no-track, [data-private] to prevent capturing clicks on specific elements.
Sensitive form data being captured
Add form input selectors to your denylist: input[type="password"], input[name*="credit"], .sensitive-field. You can also disable form autocapture entirely in the settings.
Autocapture settings not taking effect
Clear your browser cache and ensure the updated JavaScript snippet is deployed. Check that you have admin permissions and that the project settings were saved successfully. Wait 5-10 minutes for changes to propagate.