Skip to content

[MAINTENANCE] Fix PostHog pageview tracking and configuration. #11093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 15, 2025

Conversation

ashmortar
Copy link
Contributor

@ashmortar ashmortar commented Apr 11, 2025

Root Cause:

The root cause of the analytics issue was the dotenv library loading API keys from the previously committed .env file (which contained a dummy value). This unintentionally overwrote the correct keys provided via CI secrets/environment variables. Removing the committed .env file then caused build failures because the config previously relied on the object returned by dotenv.config(), which only contains keys parsed from the file. However, dotenv also loads keys from the .env file into process.env. By switching the configuration to read directly from process.env, we ensure the correct key is used in CI (from secrets/env vars) while still allowing local overrides via a .env file.

Summary:

This PR fixes PostHog pageview tracking, associated console errors, and resulting CI build failures.

Changes:

  • Standardized PostHog Setup: Configured the posthog-docusaurus plugin for initialization while simplifying the NavigationTracker for manual $pageview capture.
  • Corrected Environment Variable Handling: Updated docusaurus.config.js to read POSTHOG_API_KEY directly from process.env, fixing CI build failures and ensuring CI secrets/environment variables are used correctly, while still supporting local .env files via dotenv.
  • Improved Local Setup & Git Management: Added .env.example, updated the README with local setup instructions, and ensured .env is correctly ignored and untracked by Git.

Outcome:

This should restore reliable PostHog tracking, fix CI/CD build failures, and clarify the local development setup process.


  • Description of PR changes above includes a link to an existing GitHub issue
  • PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB], [MINORBUMP]
  • Code is linted - run invoke lint (uses ruff format + ruff check)
  • Appropriate tests and docs have been updated

For more information about contributing, visit our community resources.

After you submit your PR, keep the page open and monitor the statuses of the various checks made by our continuous integration process at the bottom of the page. Please fix any issues that come up and reach out on Slack if you need help. Thanks for contributing!

- Disable automatic pageview capture to prevent duplicates
- Add custom NavigationTracker component for SPA navigation
- Configure PostHog to run debug in development
Copy link

netlify bot commented Apr 11, 2025

Deploy Preview for niobium-lead-7998 ready!

Name Link
🔨 Latest commit e69f8d3
🔍 Latest deploy log https://app.netlify.com/sites/niobium-lead-7998/deploys/67fd31b04cc7340008ff6d0c
😎 Deploy Preview https://deploy-preview-11093.docs.greatexpectations.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ashmortar ashmortar changed the title M/GX-626/manual-pageview-capture [MAINTENANCE] Fix PostHog pageview tracking and configuration. Apr 11, 2025
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.03%. Comparing base (55f723a) to head (e69f8d3).
Report is 3 commits behind head on develop.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #11093   +/-   ##
========================================
  Coverage    81.03%   81.03%           
========================================
  Files          497      497           
  Lines        41293    41293           
========================================
  Hits         33461    33461           
  Misses        7832     7832           
Flag Coverage Δ
3.10 70.41% <ø> (+0.01%) ⬆️
3.10 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.10 aws_deps ?
3.10 big ?
3.10 clickhouse ?
3.10 filesystem ?
3.10 mssql ?
3.10 mysql ?
3.10 postgresql ?
3.10 spark_connect ?
3.11 70.40% <ø> (-0.02%) ⬇️
3.11 athena or openpyxl or pyarrow or project or sqlite or aws_creds ?
3.11 aws_deps ?
3.11 big ?
3.11 clickhouse ?
3.11 filesystem ?
3.11 mssql ?
3.11 mysql ?
3.11 spark_connect ?
3.12 70.42% <ø> (ø)
3.12 athena or openpyxl or pyarrow or project or sqlite or aws_creds 56.99% <ø> (ø)
3.12 aws_deps 46.76% <ø> (ø)
3.12 big 55.12% <ø> (ø)
3.12 bigquery 49.45% <ø> (ø)
3.12 databricks 51.08% <ø> (ø)
3.12 filesystem 63.21% <ø> (ø)
3.12 mssql 52.02% <ø> (ø)
3.12 mysql 52.27% <ø> (ø)
3.12 postgresql 55.04% <ø> (ø)
3.12 redshift 48.66% <ø> (ø)
3.12 snowflake 51.85% <ø> (ø)
3.12 spark 58.20% <ø> (ø)
3.12 spark_connect 47.08% <ø> (ø)
3.12 trino 52.69% <ø> (ø)
3.9 70.42% <ø> (-0.02%) ⬇️
3.9 athena or openpyxl or pyarrow or project or sqlite or aws_creds 56.99% <ø> (ø)
3.9 aws_deps 46.78% <ø> (ø)
3.9 big 55.13% <ø> (ø)
3.9 bigquery 49.44% <ø> (ø)
3.9 clickhouse 43.70% <ø> (ø)
3.9 databricks 51.07% <ø> (-0.01%) ⬇️
3.9 filesystem 63.22% <ø> (ø)
3.9 mssql 52.00% <ø> (ø)
3.9 mysql 52.25% <ø> (ø)
3.9 postgresql 55.02% <ø> (ø)
3.9 redshift 48.66% <ø> (ø)
3.9 snowflake 51.85% <ø> (ø)
3.9 spark 58.17% <ø> (ø)
3.9 spark_connect 47.09% <ø> (ø)
3.9 trino 52.68% <ø> (ø)
cloud 0.00% <ø> (ø)
docs-basic 54.08% <ø> (ø)
docs-creds-needed 52.94% <ø> (ø)
docs-spark 52.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines 321 to 322
['0.18']: {
label: '0.18.21',
Copy link
Member

Choose a reason for hiding this comment

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

Was this not being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, this may been a relic from a merge with main, I'll double check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it was actually from running the linter, but I've restored it to the previous state anyway.

@josectobar
Copy link
Member

Were you able to smoke test the page views, and was this helpful feedback in Posthog and JIRA?

@ashmortar
Copy link
Contributor Author

ashmortar commented Apr 14, 2025

Were you able to smoke test the page views, and was this helpful feedback in Posthog and JIRA?

@josectobar I'm not sure what you mean by feedback in Posthog and JIRA, but when turning on debug locally or manually logging in the component you can see that each change in location triggers a send of a pageview. I had not yet been able to smoke test in prod that this is working because of the dummy env var previously committed to the repo causing issues in reporting.

@ashmortar ashmortar requested a review from josectobar April 14, 2025 16:32
@josectobar
Copy link
Member

I think there's a way to test this locally in Posthog but I'm not going to block this PR if it's not working.

@ashmortar ashmortar added this pull request to the merge queue Apr 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 15, 2025
@ashmortar ashmortar added this pull request to the merge queue Apr 15, 2025
Merged via the queue into develop with commit 0ca961e Apr 15, 2025
67 checks passed
@ashmortar ashmortar deleted the m/GX-626/manual-pageview-capture branch April 15, 2025 16:31
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.

2 participants