Enable PostHog pageview and pageleave tracking#319
Conversation
Adds capture_pageview and capture_pageleave to the PostHog init config so we can measure total site traffic and time-on-page alongside existing event tracking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
There was a problem hiding this comment.
Code Review
This pull request enables automatic pageview and pageleave tracking in the PostHog configuration within the default layout. The review feedback suggests moving the PostHog script block from the bottom of the body to the head section to ensure more reliable event capture for users who navigate away quickly, noting that the asynchronous nature of the script will prevent it from blocking page rendering.
| capture_pageview: true, | ||
| capture_pageleave: true, |
There was a problem hiding this comment.
The PostHog initialization and snippet are currently located at the bottom of the <body>. For more accurate tracking of 'total site traffic' and to ensure that $pageview and $pageleave events (as well as existing custom events like docs_download_click) are captured for users who interact with the page or navigate away before the script is reached, it is recommended to move the PostHog <script> block into the <head> section. Since the library is loaded asynchronously (p.async=!0), moving it to the head will not block page rendering but will significantly improve the reliability of your analytics data.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #319 +/- ##
=======================================
Coverage 83.83% 83.83%
=======================================
Files 223 223
Lines 11460 11460
Branches 3144 3144
=======================================
+ Hits 9607 9608 +1
Misses 1070 1070
+ Partials 783 782 -1 🚀 New features to boost your workflow:
|



Summary
capture_pageviewandcapture_pageleavein PostHog init config on the websiteTest plan
$pageviewevents appear in PostHog dashboard$pageleaveevents include duration data