Skip to content

feat: DR-7614 Add posthog to blog#7638

Open
carlagn wants to merge 1 commit intomainfrom
feat/DR-7614-blog-posthog
Open

feat: DR-7614 Add posthog to blog#7638
carlagn wants to merge 1 commit intomainfrom
feat/DR-7614-blog-posthog

Conversation

@carlagn
Copy link
Contributor

@carlagn carlagn commented Mar 12, 2026

Summary by CodeRabbit

  • New Features
    • Integrated analytics tracking on the blog to monitor user engagement and usage patterns for improving user experience.

@carlagn carlagn requested a review from mhartington March 12, 2026 15:25
@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment Mar 12, 2026 3:28pm
docs Ready Ready Preview, Comment Mar 12, 2026 3:28pm
eclipse Ready Ready Preview, Comment Mar 12, 2026 3:28pm

Request Review

@carlagn carlagn changed the title feat: DR-7614 Add instrumentation-client to blog feat: DR-7614 Add posthog to blog Mar 12, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

This pull request adds PostHog analytics integration to the blog application by introducing a new client-side instrumentation module and its corresponding dependency, while also updating the root package manager specification with a SHA512 integrity hash for package consistency.

Changes

Cohort / File(s) Summary
PostHog Analytics Integration
apps/blog/package.json, apps/blog/src/instrumentation-client.ts
Adds posthog-js dependency via catalog reference and introduces new TypeScript client module that initializes PostHog analytics with environment configuration (api_host, pageview capture, site metadata).
Package Manager Specification
package.json
Updates packageManager field to include SHA512 integrity hash for pnpm@10.30.0, strengthening version verification and reproducibility without altering runtime behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: DR-7614 Add posthog to blog' accurately describes the main change: adding PostHog analytics instrumentation to the blog application.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan for PR comments
  • Generate coding plan

Comment @coderabbitai help to get the list of available commands and usage tips.

@argos-ci
Copy link

argos-ci bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 1 removed Mar 12, 2026, 3:35 PM

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/blog/src/instrumentation-client.ts (1)

3-4: Non-null assertion on environment variable may cause silent failures.

Using process.env.NEXT_PUBLIC_POSTHOG_KEY! assumes the key is always defined. If it's missing (e.g., in a local dev environment without the env var set), PostHog will receive undefined as the API key, potentially causing initialization errors or silent failures.

A defensive approach ensures graceful degradation:

🛡️ Proposed defensive initialization
+const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;
+
+if (posthogKey) {
-posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
+  posthog.init(posthogKey, {
   api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
   capture_pageview: "history_change",
-  defaults: "2025-11-30",
   loaded: (posthog) => {
     posthog.register({
       site_name: "mono-blog",
-      environment: "production",
+      environment: process.env.NODE_ENV,
     });
   },
 });
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/blog/src/instrumentation-client.ts` around lines 3 - 4, Replace the
non-null assertion on process.env.NEXT_PUBLIC_POSTHOG_KEY in the posthog.init
call with a defensive check: verify NEXT_PUBLIC_POSTHOG_KEY is defined before
calling posthog.init (in the instrumentation client where posthog.init is
invoked), and if it's missing, skip initialization or call posthog.init with a
safe fallback only after logging/warning (use
process.env.NEXT_PUBLIC_POSTHOG_HOST as needed), ensuring you surface an
explicit log message or telemetry so missing key cases are visible instead of
passing undefined into posthog.init.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/blog/src/instrumentation-client.ts`:
- Line 10: The hardcoded environment: "production" should be replaced with a
derived value so dev/staging traffic isn't mislabeled; update the
object/property named environment (in apps/blog/src/instrumentation-client.ts)
to read from an environment variable such as process.env.NEXT_PUBLIC_ENVIRONMENT
with a fallback to process.env.NODE_ENV and then to "production" only as last
resort, and ensure any build-time exposure requirements are respected (use
NEXT_PUBLIC_ prefix if this value must be client-accessible).

---

Nitpick comments:
In `@apps/blog/src/instrumentation-client.ts`:
- Around line 3-4: Replace the non-null assertion on
process.env.NEXT_PUBLIC_POSTHOG_KEY in the posthog.init call with a defensive
check: verify NEXT_PUBLIC_POSTHOG_KEY is defined before calling posthog.init (in
the instrumentation client where posthog.init is invoked), and if it's missing,
skip initialization or call posthog.init with a safe fallback only after
logging/warning (use process.env.NEXT_PUBLIC_POSTHOG_HOST as needed), ensuring
you surface an explicit log message or telemetry so missing key cases are
visible instead of passing undefined into posthog.init.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 659ff7db-fe2b-4b9a-a264-9b7132fa37e3

📥 Commits

Reviewing files that changed from the base of the PR and between 0f1bc35 and 64b81fe.

⛔ Files ignored due to path filters (2)
  • apps/blog/public/fonts/MonaSansMonoVF[wght].woff2 is excluded by !**/*.woff2
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • apps/blog/package.json
  • apps/blog/src/instrumentation-client.ts
  • package.json

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