Skip to main content

Only one analytics instance is initialized

ab-001699 · marketing-analytics.core-analytics.single-analytics-instance
Severity: mediumactive

Why it matters

Duplicate initialization doubles every event. Pageview counts inflate, conversion rates halve against truth, session counts get split across two cookies, and funnel steps show impossible transitions because the same user is being tracked as two identities. Once bad data is in GA4 or PostHog you cannot retroactively deduplicate it — every historical report based on that period is permanently corrupted. A/B test significance calculations lie. Board metrics lie.

Severity rationale

Medium because duplicate events corrupt historical data irreversibly but do not break user-facing functionality.

Remediation

Consolidate every posthog.init(), gtag('config', ...), or mixpanel.init() call into a single provider at src/components/analytics-provider.tsx mounted once in the root layout. Delete every per-page initialization. Multiple providers tracking different surfaces (Vercel Analytics plus PostHog) are fine; two instances of the same provider are not. Grep the repo for every init call before shipping the fix.

Detection

  • ID: marketing-analytics.core-analytics.single-analytics-instance
  • Severity: medium
  • What to look for: Search for multiple initialization calls to the same analytics provider, or multiple analytics providers loading the same type of tracking (e.g., two GA4 measurement IDs, GA4 AND Google Universal Analytics, PostHog initialized twice). Look for:
    • Multiple gtag('config', ...) calls with different measurement IDs (could be legitimate GTM + direct GA4 — check if both are actually needed)
    • PostHog or Mixpanel init() called in multiple components
    • Analytics library imported in both a provider component AND individual page files
    • Both @vercel/analytics AND a full analytics suite like GA4 without intentional dual-tracking setup
  • Pass criteria: Count every analytics initialization call across the codebase. Each analytics provider is initialized exactly 1 time in the application — no more than 1 init call per provider. Multiple providers (e.g., GA4 for marketing + PostHog for product) are acceptable as long as each is initialized once. Report the count even on pass: "Found N providers, each initialized once."
  • Fail criteria: The same analytics provider is initialized more than once in the component tree, OR 2 or more overlapping tracking scripts load the same data into the same destination. Do NOT pass when the same posthog.init() or gtag('config', ...) appears in more than 1 component file — even if one file is "unused" it still represents a risk of duplicate initialization.
  • Skip (N/A) when: No analytics is present (script-present failed).
  • Detail on fail: "PostHog posthog.init() called in both AnalyticsProvider.tsx and in 3 individual page components — this creates duplicate events and inflated session counts"
  • Remediation: Consolidate analytics initialization to a single provider component in src/components/analytics-provider.tsx at the top of your component tree. Remove any per-page initialization calls. If you intentionally use multiple analytics tools (common — e.g., Vercel Analytics for infrastructure metrics + PostHog for product analytics), ensure each is initialized in exactly one place.

Taxons

History