Skip to content

Add Mixpanel + PostHog analytics to docs#44

Merged
abhishekmishragithub merged 1 commit intomainfrom
feat/add-analytics-instrumentation
Apr 10, 2026
Merged

Add Mixpanel + PostHog analytics to docs#44
abhishekmishragithub merged 1 commit intomainfrom
feat/add-analytics-instrumentation

Conversation

@abhishekmishragithub
Copy link
Copy Markdown
Collaborator

Summary

  • Adds PostHog native integration via docs.yml analytics config (project: docs.smallest.ai)
  • Adds analytics.js custom script that loads Mixpanel SDK and sets up custom event tracking
  • Both platforms receive identical events via dual-send pattern

Events Tracked

Event Trigger
docs_page_viewed Every page load/SPA navigation
docs_code_copied Code block copy button click
docs_search_performed Search input (debounced, 3+ chars)
docs_search_result_clicked Click on search result
docs_nav_clicked Sidebar/nav link click
docs_product_toggled Waves ↔ Atoms toggle
docs_signup_clicked CTA / signup / console links
docs_console_link_clicked Any link to console.smallest.ai
docs_sdk_install_copied pip/npm/yarn install command copy
docs_feedback_submitted Thumbs up/down feedback widget
docs_scroll_depth 25%, 50%, 75%, 100% scroll milestones
docs_api_playground_used API playground "Try it" button

Files Changed

  • fern/docs.yml — Added analytics: (PostHog) + js: (analytics.js) sections
  • fern/docs/assets/scripts/analytics.js — New: Mixpanel loader + all event trackers

How to Test

  1. Merge → fern generate --docs
  2. Visit docs.smallest.ai → open browser devtools → Network tab
  3. Verify requests going to cdn.mxpnl.com (Mixpanel) and us.i.posthog.com (PostHog)
  4. Check Mixpanel Live View + PostHog Live Events for event stream

PostHog Dashboards (already created)

  • Docs — TOFU Overview (8 insights)
  • Docs — BOFU & Activation (10 insights)
  • Docs — Funnels & User Journeys (3 funnels)
  • Docs — UX Deep Dive (9 insights for friction/stuck analysis)

- Add PostHog native integration to docs.yml (project: docs.smallest.ai)
- Add analytics.js custom script for Mixpanel SDK + event tracking
- Tracks: page views, code copies, search, product toggle, CTAs,
  SDK installs, feedback, scroll depth, API playground usage
- PostHog SDK loaded by Fern natively; analytics.js only loads Mixpanel
- Both platforms receive identical events via dual-send pattern
@github-actions
Copy link
Copy Markdown

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

entelligence-ai-pr-reviews bot commented Apr 10, 2026

EntelligenceAI PR Summary

Adds dual-platform analytics instrumentation (Mixpanel + PostHog) to the Fern documentation site.

  • fern/docs.yml: Registers PostHog analytics with API key/endpoint and includes analytics.js as a custom script
  • fern/docs/assets/scripts/analytics.js: Dynamically loads Mixpanel SDK and sets up 10 event trackers
  • Tracks page views, code copy, search, navigation clicks, product toggling, CTA/signup/console links, SDK install copy, feedback buttons, and scroll depth milestones (25/50/75/100%)
  • Enriches all events with product, page path, and UTM parameter metadata
  • Implements History API monkey-patching for SPA-aware route change detection

Confidence Score: 2/5 - Changes Needed

Not safe to merge — analytics.js contains a runtime-breaking bug where call2_args and call2 are implicitly assigned without var/let/const inside a "use strict" context, causing a ReferenceError whenever get_group is invoked and silently disabling Mixpanel group tracking. The PR itself is well-scoped and achieves a clean dual-platform analytics integration (Mixpanel + PostHog) with meaningful event coverage including scroll depth milestones, SDK copy tracking, and CTA clicks, but this strict-mode variable declaration bug must be fixed before the script can run reliably in production.

Key Findings:

  • In analytics.js, the variables call2_args and call2 are assigned without any var/let/const declaration inside a "use strict" file — this is a hard ReferenceError in strict mode that will throw at runtime whenever get_group is called, not a silent failure or degraded experience.
  • The analytics instrumentation is otherwise comprehensive, covering 10 distinct event types (page views, code copy, search, scroll depth at 25/50/75/100%, CTA links, feedback buttons) which represents solid coverage for a docs analytics initiative.
  • Only 1 of 2 changed files was reviewed, meaning fern/docs.yml — which registers the PostHog API key and endpoint — was not assessed; hardcoded API keys in config files warrant verification that these are public/client-side safe keys and not secret tokens.
Files requiring special attention
  • fern/docs/assets/scripts/analytics.js
  • fern/docs.yml

Comment on lines +57 to +59
call2_args = arguments;
call2 = [c].concat(Array.prototype.slice.call(call2_args, 0));
a.push([e, call2]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correctness: call2_args and call2 are assigned without var/let/const declarations inside a file that opens with "use strict" — this throws a ReferenceError at runtime whenever get_group is invoked, silently breaking any Mixpanel group tracking call.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In fern/docs/assets/scripts/analytics.js, lines 57-58, inside the `b()` function within `a.get_group`, the variables `call2_args` and `call2` are assigned without any `var`/`let`/`const` declaration. Because the outer IIFE file uses `"use strict"`, assigning to undeclared variables throws a ReferenceError at runtime. Fix by prepending `var` to both assignments: `var call2_args = arguments;` and `var call2 = [c].concat(...)`.  The same variables are referenced on lines 58-59 (the push call) so no further changes are needed there once they are properly declared.

@abhishekmishragithub abhishekmishragithub merged commit fd22f29 into main Apr 10, 2026
2 checks 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.

1 participant