Autocapture

Last updated:

|Edit this page|

PostHog can automatically capture a variety of events in your app without specific tracking code. This page covers the different types of events that PostHog can capture and how to configure them.

Types of autocaptured events

PostHog can automatically capture these types of data without specific tracking code:

TypeDescription
InteractionCaptures clicks, taps, and other user interactions
NavigationCaptures pageviews, pageleaves, and screen views
ClipboardCaptures copy and paste actions
HeatmapShows where users interact with your product the most
Dead clicksCaptures clicks that don't trigger a change to the page
ExceptionCaptures errors and crashes. See the error tracking docs for more information.
SessionRecords real user behavior for playback. See the session replay docs for more information.
Web vitalsCaptures largest contentful paint, first input delay, cumulative layout shift, and first contentful paint
LifecycleCaptures app launches, backgrounds, and updates.

Supported SDKs

Autocapture is available in the following SDKs, each with a different set of captured events:

Looking for session and exception autocapture?

You can also autocapture session and exception events. See session replay and error tracking for more information.

Interaction autocapture

Web interaction autocapture

The JavaScript web SDK captures the following events by default:

  • Interactions like clicks with a tag like a, button, form, input, select, textarea, label
  • Form submissions and form changes
  • Changes on content with contenteditable="true".
  • Copies from clipboard

Autocaptures are displayed with names like clicked span with text "Delete". You can filter for Autocapture events to see all interactions.

Configuring interaction autocapture

You can configure posthog-js to autocapture information that users copy or cut on your page with the capture_copied_text config option.

You can configure the following options:

OptionDescription
url_allowlist
Type: (string \| RegExp)[]
List of URLs to enable autocapture on. Can be strings to match or regexes (e.g., ['https://example.com', 'test.com/.*']). Useful when you want to autocapture on specific pages only. If both url_allowlist and url_ignorelist are set, the allowlist is checked first, then the ignorelist (which can override the allowlist).
url_ignorelist
Type: (string \| RegExp)[]
List of URLs to not enable autocapture on. Can be strings to match or regexes (e.g., ['https://example.com', 'test.com/.*']). Useful when you want to autocapture on most pages but not some specific ones.
dom_event_allowlist
Type: DomAutocaptureEvents[]
List of DOM events to enable autocapture on (e.g., ['click', 'change', 'submit']).
element_allowlist
Type: AutocaptureCompatibleElement[]
List of DOM elements to enable autocapture on (e.g., ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']). We consider the element tree from root to target, so if button is in the allowlist, clicks on button or its children (like svg) are captured, but not clicks on parent div elements.
css_selector_allowlist
Type: string[]
List of CSS selectors to enable autocapture on (e.g., ['[ph-capture]']). We consider the element tree from root to target, so if ['[id]'] is in the allowlist, clicks on elements with IDs or their parents with IDs are captured. Everything is enabled when there's no allowlist.
element_attribute_ignorelist
Type: string[]
Exclude certain element attributes from autocapture (e.g., ['aria-label'] or ['data-attr-pii']).
capture_copied_text
Type: boolean
When set to true, autocapture will capture the text of any element that is cut or copied.

Here's a full example of how to configure autocapture:

Web
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
defaults: '2025-05-24',
autocapture: {
// URL filtering
url_allowlist: ['https://example.com', 'test.com/.*'],
url_ignorelist: ['https://example.com/admin', 'test.com/private/.*'],
// Event filtering
dom_event_allowlist: ['click', 'change', 'submit', 'input'],
// Element filtering
element_allowlist: ['a', 'button', 'form', 'input', 'select', 'textarea', 'label'],
css_selector_allowlist: ['[ph-capture]', '[data-track]'],
// Attribute filtering
element_attribute_ignorelist: ['aria-label', 'data-attr-pii', 'data-sensitive'],
// Copy/cut capture
capture_copied_text: true,
},
})

Disabling interaction autocapture

You can disable autocapture in two ways:

Web
// Before initialization
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
defaults: '2025-05-24',
autocapture: false,
})
// Or after initialization
posthog.set_config({ autocapture: false })

Note: Disabling autocapture in your project settings isn't instant. PostHog will continue to capture events where it is initialized. Instead, autocaptured events will taper off as users trigger reinitialization of PostHog (like when they reload your site).

Disabling autocapture does not disable capture of page views or page leaves. See navigation autocapture for more information.

Capturing additional properties in autocapture events

If you add a data attribute onto an element in the format data-ph-capture-attribute-some-key={someValue}, then any autocapture event from that element or one of its children will have the property some-key: 'someValue' added to it. This can be useful when you want to add additional information to autocapture events.

As an example, say you have a notification bell with a value like this:

a notification bell showing 1 unread notification

You can include the unread count in the autocapture event by adding the data-ph-capture-attribute class like this:

HTML
<div
onClick={toggleNotificationsPopover}
data-ph-capture-attribute-unread-notifications-count={unreadCount}
>

The autocapture event for clicks on the bell will include the unread count as an unread-notifications-count property.

Tracking metadata

You can also attach metadata to autocapture events by adding data attributes to the element that triggers the event. This helps you track something like a customer performing a transaction (adding an item to a cart or completing a purchase).

The below ecommerce example helps you understand what users are interested in, even if they don't complete a transaction. It can also reveal which products users are interested in when correlated with information like marketing campaigns, regionality, or device type.

HTML
<button
data-ph-capture-attribute-product-id={productId}
data-ph-capture-attribute-product-name={productName}
data-ph-capture-attribute-product-price={productPrice}
data-ph-capture-attribute-product-quantity={productQuantity}
>
Add to cart
</button>

Replace the {productXx} values with the relevant information available on the webpage. Now when the Add to cart button is clicked, the autocapture event will include the product information in the event's properties, like:

JSON
properties: {
"product-id": "12345678",
"product-name": "Red t-shirt",
"product-price": "30",
"product-quantity": "1"
}

Sending custom properties with autocaptured form submissions

To prevent accidental sensitive data capture, we do not automatically capture form values from form submissions. To add custom properties to form submissions, you can use the data-ph-capture-attribute attribute on the form element.

In this example, the product-id property will be sent with the form submission event. The product-name input will not be captured.

HTML
<form
data-ph-capture-attribute-product-id="12345678"
>
<input name="product-name" placeholder="this input will not be autocaptured"/>
<button type="submit">Submit</button>
</form>

The following example shows how you can use the data-ph-capture-attribute attribute dynamically in a React component. The product-name property will be sent with the form submission event.

TSX
import { useState } from 'react'
const MyForm = () => {
const [productName, setProductName] = useState('')
return (
<form
data-ph-capture-attribute-name={productName}
>
<input name="product-name" onChange={(e) => setProductName(e.target.value)} value={productName}/>
<button type="submit">Submit</button>
</form>
)
}

Rage clicks autocapture

A rage click is when a user clicks a button multiple times in quick succession, specifically more than 3 clicks in 1 second.

The event is captured as a $rageclick event. You can use this event to identify opportunities to improve your UI, as it shows where users are frustrated with your product.


Web navigation autocapture

PostHog automatically captures navigation events as $pageview and $pageleave events.

Configuring page navigation autocapture

You can configure the following options:

OptionDescription
capture_pageviewType: boolean, 'history_change' (default). When set to history_change, autocapture will capture pageviews. This also works on single-page apps.
capturePageleavesType: boolean, 'if_capture_pageview' (default). When set to true, autocapture will capture pageleaves. If set to 'if_capture_pageview', it only captures pageleaves if capturePageviews is also set to true or 'history_change'.

For example, your initialization code might look like this:

Web
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
defaults: '2025-05-24',
capture_pageview: 'history_change',
capture_pageleave: 'if_capture_pageview'
})

Disabling page navigation autocapture

You can disable $pageview and $pageleave autocapture in two ways:

For example:

Web
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
defaults: '2025-05-24',
capture_pageview: false,
capture capture_pageleave ageleaves: false,
})

Clipboard autocapture

Note: This is only available for the JavaScript web SDK and framework libraries for web like React and Next.js.

When enabled with capture_copied_text set to true, we capture the copied or cut text as a Clipboard autocapture event. You can then use the $selected_content property in analysis or use the activity page to view the copied content in context.

The activity view showing the copied content highlighted in context

Clipboard autocapture respects other privacy settings. For example, won't capture content from a password field.

Note: Browsers don't directly allow access to copied data for privacy reasons so when posthog-js sees a clipboard event, we capture any text currently selected in the browser.import { useSelector } from 'react-redux'

Heatmap autocapture

Note: This is only available for the JavaScript web SDK and framework libraries for web like React and Next.js.

If you use our JavaScript libraries and enable heatmap autocapture in your project settings, we can capture general clicks, mouse movements, and scrolling to create heatmaps. No additional events are created.

Whereas autocapture creates events whenever it can uniquely identify an interacted element, heatmaps are generated based on overall mouse or touch positions and are useful for understanding more general user behavior across your site.

Dead clicks autocapture

A dead click (or slow click) is a click which isn't followed by a change to the page.

Dead clicks are a great way to identify opportunities to improve your UI, showing you where your users expect to be able to interact with the page but cannot.

You can collect dead clicks with the Web SDK by enabling them in your project settings.

Or by setting your config:

Web
posthog.init('<ph_project_api_key>', {
api_host: 'https://us.i.posthog.com',
defaults: '2025-05-24',
capture_dead_clicks: true,
// any other config
})

Note: The PostHog heatmap captures dead clicks for free, collecting only the coordinates of dead clicks to display in heatmaps. Enabling the autocapture of dead clicks here allows for deeper analysis and is priced as a standard product analytics event.

Analyzing autocaptured events and properties

Autocapture events and properties can be used like any other event type. You can use them in trends, funnels, cohorts, surveys, and more. Beyond this, they come with some special features:

  • When using the autocapture event series, you can filter by the autocaptured element's tag name, text, href target, and/or CSS selector.
Trends using autocapture properties
  • Autocapture events can be organized and renamed using actions.

  • You can query autocapture elements_chain using SQL.

Captured properties

Autocaptured events (and client-side custom events) have many default properties. These are distinguished by $ prefix in their name, the PostHog logo next to them in the activity tab, and the verified event logo. You can find them in PostHog or in the references.

NameKeyExample value
Timestamp$timestamp2024-05-29T17:32:07.202Z
OS$osMac OS X
OS Version$os_version10.15.7
Browser$browserChrome
Browser Version$browser_version125
Device Type$device_typeDesktop
Current URL$current_urlhttps://example.com/page
Host$hostexample.com
Path Name$pathname/page
Screen Height$screen_height1080
Screen Width$screen_width1920
Viewport Height$viewport_height950
Viewport Width$viewport_width1903
Library$libweb
Library Version$lib_version1.31.0
Referrer URL$referrerhttps://google.com
Referring Domain$referring_domainwww.google.com
Active Feature Flags$active_feature_flags['beta_feature']
Event Type$event_typeclick
UTM Source$utm_sourcenewsletter
UTM Medium$utm_mediumemail
UTM Campaign$utm_campaignproduct_launch
UTM Term$utm_termnew+product
UTM Content$utm_contentlogolink
Google Click ID$gclidTeSter-123
Google Ads Source$gad_sourcegoogle_ads
Google Search Ads 360 Click$gclsrcdsa
Google DoubleClick Click ID$dclidtestDclid123
Google Web-to-app Measure$wbraidtestWbraid123
Google App-to-web Measure$gbraidtestGbraid123
Facebook Click ID$fbclidtestFbclid123
Microsoft Click ID$msclkidtestMsclkid123
Twitter Click ID$twclidtestTwclid123
LinkedIn Ad Tracking ID$la_fat_idtestLaFatId123
Mailchimp Campaign ID$mc_cidtestMcCid123
Instagram Share Id$igshidtestIgshid123
TikTok Click ID$ttclidtestTtclid123
IP Address$ip192.168.1.1

Notes:

  • If enabled, GeoIP data is added also as properties at ingestion.
  • Many of these are also captured as session properties.
  • These properties can be hidden in activity by checking the Hide PostHog properties box.

Questions? Ask Max AI.

It's easier than reading through 718 pages of documentation

Community questions

Was this page useful?

Next article

Privacy controls

PostHog offers a range of controls to limit what data is captured by product analytics. They are listed below in order of least to most restrictive. EU-cloud hosting PostHog offers hosting on EU cloud. To use this, sign up at eu.posthog.com . If you've already created a US cloud instance and wish to migrate ticket, you must raise a support ticket in-app with the Data pipelines topic for the PostHog team to do this migration for you. This option is only available to customers on the boost…

Read next article