Skip to content

Send analytics events to PostHog alongside GA4 - #165

Merged
fwextensions merged 3 commits into
devfrom
claude/posthog-on-dev-aor28f
Oct 5, 2026
Merged

fwextensions merged 3 commits into
devfrom
claude/posthog-on-dev-aor28f

Conversation

@fwextensions

@fwextensions fwextensions commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Requested by John · project thread

Before: the PostHog dual-write only existed on feature/posthog-analytics, which branches off master (v2.0.2) and so sits 468 commits behind dev.

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 real phc_ project key replaces the placeholder in src/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's tracker.js changes, including the ignored-errors filter from e5e751f, which still returns before anything is sent to either service.

Checked: npm test passes (22 files, 175 tests) and npm run build:dev succeeds with the PostHog client in dist/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

claude added 2 commits October 5, 2026 00:31
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
@fwextensions fwextensions self-assigned this Oct 5, 2026
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
fwextensions marked this pull request as ready for review October 5, 2026 01:40
@fwextensions
fwextensions merged commit f6f831c into dev Oct 5, 2026
1 check passed
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