Repository navigation
Send analytics events to PostHog alongside GA4 - #165
Merged
Merged
Conversation
Send every tracked event to both GA4 and PostHog so the numbers can be compared for a release before deciding whether to drop GA. - src/js/lib/posthog.js: minimal client posting to PostHog's HTTP capture API (the posthog-js SDK is DOM-oriented and doesn't fit an MV3 service worker). No-ops until a real project API key is pasted in, so this can land before the PostHog project exists. - tracker.js: dual-writes in send() and set(). Reuses the stored GA client_id as the PostHog distinct_id so install continuity would be preserved on a full cutover. Maps page_view -> $pageview and exception -> $exception (with $exception_list) so PostHog's web analytics and error tracking UIs work natively. Events are sent as anonymous ($process_person_profile: false). The Tracker facade and all call sites are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xxfT1FSUpycKgMw8JZ6oS
- rename dimension1/dimension2 to version/channel in the PostHog super properties, since PostHog doesn't share GA's restrictive custom dimension naming, and drop the dimension keys from the PostHog copy - move the exception description into $exception_list instead of duplicating it, since stack traces can be 2000 chars and nothing in PostHog reads the GA-style description property Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xxfT1FSUpycKgMw8JZ6oS
Analysis of the GA4 numbers shows ~92% of the 32.7M monthly events are MV3 service worker lifecycle noise: the startup page_view and background-loaded timing fire together on every worker wakeup (~33/user/day). Proposes deleting the startup pageview, sampling background-loaded, collapsing the update triplet into one event with numeric properties, replacing the popup-focus pageviews with a popup_open property, and investigating the 555K/month exceptions (starting with registering description as a GA4 custom dimension so the messages are visible). Projected 32.7M -> ~2.5M/month, which also makes PostHog's free tier cover a ~40% user sample instead of ~3%. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xxfT1FSUpycKgMw8JZ6oS
fwextensions
marked this pull request as ready for review
October 5, 2026 01:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by John · project thread
Before: the PostHog dual-write only existed on
feature/posthog-analytics, which branches offmaster(v2.0.2) and so sits 468 commits behinddev.After: the same change sits on top of the latest
dev. Every tracked event still goes to GA4 and is also posted to PostHog's capture API. PostHog stays a no-op until a realphc_project key replaces the placeholder insrc/js/lib/posthog.js. The analytics streamlining writeup (analytics-proposal.md) comes along too.How: cherry-picked all three commits from
feature/posthog-analytics(c70b443 "Add PostHog analytics alongside GA4…", 57c01a7 "Clean up PostHog property names", and e4d1ca1 "Add analytics event streamlining proposal"). They applied cleanly on top of dev'stracker.jschanges, including the ignored-errors filter from e5e751f, which still returns before anything is sent to either service.Checked:
npm testpasses (22 files, 175 tests) andnpm run build:devsucceeds with the PostHog client indist/dev/js/background.js. Not yet loaded as an unpacked extension or exercised against a real PostHog project.🤖 Generated with Claude Code
https://claude.ai/code/session_013uHCZeugQLw21d4oFhtPRP