Skip to content

Enable PostHog pageview and pageleave tracking#319

Open
Ganeshship wants to merge 1 commit into
mainfrom
chore/posthog-pageview-tracking
Open

Enable PostHog pageview and pageleave tracking#319
Ganeshship wants to merge 1 commit into
mainfrom
chore/posthog-pageview-tracking

Conversation

@Ganeshship
Copy link
Copy Markdown
Collaborator

Summary

  • Enables capture_pageview and capture_pageleave in PostHog init config on the website
  • Gives visibility into total site traffic, page-level conversion rates, and time-on-page
  • Currently we only track 4 explicit events (early_access_signup, newsletter_signup, docs_download_click, page_reaction) but have no idea how many total visitors we get

Test plan

  • Deploy website and verify $pageview events appear in PostHog dashboard
  • Confirm $pageleave events include duration data
  • Verify existing custom events still fire correctly

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>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +458 to +459
capture_pageview: true,
capture_pageleave: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.83%. Comparing base (9a0b2b5) to head (b4eaf47).

Additional details and impacted files

Impacted file tree graph

@@           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     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant