I Fixed Double Counting. Then Analytics Counted Nothing.

I Fixed Double Counting. Then Analytics Counted Nothing.

Tags
Engineering
Analytics
PostHog
Next.js
Published
September 29, 2026
Last Updated
Last updated September 29, 2026

I Fixed Double Counting. Then Analytics Counted Nothing.

I opened PostHog and found every pageview on abd.dev was being counted twice.
The two events arrived about 25 milliseconds apart. One came from PostHog's automatic pageview capture. The other came from my own tracking code, enriched with things like the page type.
Easy fix. Disable automatic capture and keep the better event.
I shipped it.
Then pageviews dropped to zero.
Not lower. Not cleaner. Zero.
The duplicate event had been hiding a second bug.
My custom pageview ran from the page component's first effect. PostHog was initialized in a provider effect inside a Suspense boundary. On prerendered pages, the page tried to record the event before PostHog had initialized.
PostHog silently discarded it.
That had always been broken. I just couldn't see it because automatic capture fired later and gave me one apparently healthy event alongside the duplicate.
Removing the duplicate didn't create the initialization bug. It removed the thing masking it.
The fix was to initialize PostHog in Next.js's `instrumentation-client.ts`, before hydration. Local interception then showed exactly one enriched pageview for each load and navigation.
This is the annoying part of cleaning up duplicated behavior: sometimes the duplicate is doing accidental failover.
You see two systems producing the same result and assume one is redundant. But if one path is broken and the other is carrying production, deleting the second path doesn't simplify the system. It exposes the broken contract underneath it.
The sequence looked ridiculous:
  1. Analytics counted every page twice.
  1. I fixed it.
  1. Analytics counted every page zero times.
  1. I fixed the initialization order.
  1. Analytics finally counted every page once.
The lesson is not "don't remove duplicates." Remove them.
But when two paths claim to do the same job, verify each path independently before deleting one. Redundancy can hide failure just as easily as it can provide resilience.
One event is correct only when you know why it exists.