WordPress web analytics installation
- 1
Install via plugin (recommended)
RequiredInstall a header/footer script plugin like WPCode or similar. Go to the plugin settings and add a new header script with the following code:
HTMLSave and activate the script.
- 2
Alternative: Edit theme directly
Add the same code snippet to your theme's
header.phpfile, just before the closing</head>tag. Note: this may be overwritten when updating themes.More detailsSee the WordPress integration docs for more details.
- 3
Send events
RecommendedClick around and view a couple pages to generate some events. PostHog automatically captures pageviews, clicks, and other interactions for you.
If you'd like, you can also manually capture custom events:
JavaScriptSee the WordPress integration docs for more details on tracking events.
- 4
Next steps
RecommendedAfter installing PostHog and ensuring autocapture is enabled, head to your web analytics dashboard to see your data. And then check out our getting started guide.
PostHog tip: Web analytics works with anonymous events. This means if you are primarily using PostHog for web analytics, it can be significantly cheaper for you.