Skip to content

[FEAT] : PostHog Integration for user analytics#118

Merged
SatyamPandey-07 merged 3 commits into
niharika-mente:mainfrom
AshutoshDash1999:feat/posthog-integration
Jun 23, 2026
Merged

[FEAT] : PostHog Integration for user analytics#118
SatyamPandey-07 merged 3 commits into
niharika-mente:mainfrom
AshutoshDash1999:feat/posthog-integration

Conversation

@AshutoshDash1999

@AshutoshDash1999 AshutoshDash1999 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

  • PostHog setup
  • Add event names and function for tracking events
  • Track app crashes as well in posthog

Next Step

  • Please create your account in Posthog
  • Add these keys in the env: NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST
  • Use the app, you will see posthog events being called from browser and reflected in dashboard.

Fixes #116

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (non-code modifications)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

  • Manual testing (describe steps and browser tested in)
  • Automated tests added/run (if applicable)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings or console errors
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Added comprehensive analytics tracking across user interactions to better understand usage patterns, including event creation, bookmarking, searches, filter usage, and booking activities.
    • Enhanced error tracking and exception reporting for improved application monitoring and reliability.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@AshutoshDash1999 is attempting to deploy a commit to the niharika-mente's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@AshutoshDash1999, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 2 minutes and 16 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c98548d9-0e49-4b7c-9693-e48d1c481963

📥 Commits

Reviewing files that changed from the base of the PR and between b9677e0 and ad51d58.

📒 Files selected for processing (1)
  • instrumentation-client.ts
📝 Walkthrough

Walkthrough

PostHog initialization is moved from lib/posthog.js and app/providers.tsx to a new instrumentation-client.ts module. A new lib/posthog/events.ts defines typed event name constants, and lib/posthog/helpers.ts exports captureEvent, captureException, and identifyUser wrappers. All components and app modules are updated to use these helpers instead of direct posthog-js calls.

Changes

PostHog Analytics Instrumentation

Layer / File(s) Summary
PostHog init, event constants, and helper wrappers
instrumentation-client.ts, lib/posthog/events.ts, lib/posthog/helpers.ts
instrumentation-client.ts initializes PostHog at module load time from env vars. lib/posthog/events.ts exports the POSTHOG_EVENTS constant with as const typing. lib/posthog/helpers.ts exports identifyUser, captureEvent, and captureException as thin wrappers. The old lib/posthog.js client export and init block are removed.
Page-view and error boundary tracking
app/providers.tsx, app/error.tsx
app/providers.tsx replaces the direct posthog.capture("$pageview", ...) call with captureEvent(POSTHOG_EVENTS.PAGE_VIEW, ...) and removes the module-scope posthog.init(...) block. app/error.tsx adds captureException(error, { digest }) inside the existing useEffect.
UI component event tracking
components/BookEvent.tsx, components/CreateNewEvent.tsx, components/EventCard.tsx, components/SearchFilters.tsx
Replaces direct posthog-js calls with captureEvent/captureException helpers and POSTHOG_EVENTS constants across booking, event creation, bookmark toggles, card views, search, and filter change flows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • niharika-mente/DevEvent_Tracker#5: Introduces PostHog booking analytics in components/BookEvent.tsx — the same code path this PR refactors to use captureEvent/POSTHOG_EVENTS helpers.
  • niharika-mente/DevEvent_Tracker#61: Adds PostHog success/failure event capture to BookEvent.tsx's handleSubmit, directly overlapping with this PR's refactor of that same logic.
  • niharika-mente/DevEvent_Tracker#85: Modifies app/providers.tsx PostHog wiring and page-view tracking, the same area this PR changes by removing the module-scope init and switching to helpers.

Suggested labels

enhancement, Medium, SSoC26

Suggested reviewers

  • SatyamPandey-07
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: PostHog integration for user analytics, which matches the changeset's primary objective of implementing PostHog analytics tracking.
Description check ✅ Passed The PR description covers key sections including what was done, next steps, issue reference, type of change, testing approach, and a completed checklist, aligning with the repository template.
Linked Issues check ✅ Passed The PR successfully implements PostHog integration addressing issue #116 by setting up PostHog, defining event tracking functions, implementing crash tracking, and tracking user activities across the application.
Out of Scope Changes check ✅ Passed All changes are directly scoped to PostHog analytics integration: helper utilities, event definitions, client instrumentation, and event tracking calls across relevant components.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@AshutoshDash1999 AshutoshDash1999 changed the title Feat/posthog integration [FEAT] : PostHog Integration for user analytics Jun 23, 2026
@AshutoshDash1999 AshutoshDash1999 force-pushed the feat/posthog-integration branch from 290af12 to b9677e0 Compare June 23, 2026 07:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
lib/posthog/helpers.ts (1)

10-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Type captureEvent to the shared event union.

Line 11 accepts any string, which bypasses your typed event map and allows silent event-name typos. Use the POSTHOG_EVENTS value union for compile-time safety.

Suggested refactor
 import posthog from "posthog-js";
+import { POSTHOG_EVENTS } from "./events";
+
+type PostHogEventName =
+  (typeof POSTHOG_EVENTS)[keyof typeof POSTHOG_EVENTS];
@@
 export function captureEvent(
-  event: string,
+  event: PostHogEventName,
   properties?: Record<string, unknown>
 ) {
   posthog.capture(event, properties);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/posthog/helpers.ts` around lines 10 - 15, The captureEvent function
currently accepts any string for the event parameter, which allows silent typos
and bypasses type safety. Replace the event parameter type from a generic string
to use the POSTHOG_EVENTS value union instead. This will enforce compile-time
safety by ensuring only valid event names from your typed event map can be
passed to the captureEvent function.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/BookEvent.tsx`:
- Around line 31-34: The captureEvent call for POSTHOG_EVENTS.BOOKING_FAILED is
sending raw email as part of the payload, which violates the PII protection rule
established earlier in the code (line 30). Remove the email parameter from the
captureEvent function call on line 34 where BOOKING_FAILED is captured, keeping
only the eventId and slug parameters which are safe to log.

In `@components/SearchFilters.tsx`:
- Around line 32-34: The captureEvent call with POSTHOG_EVENTS.EVENT_SEARCHED is
sending the raw search query string which may contain PII. Instead of passing
the raw search query directly to the analytics event, create a redacted or
derived version of the search data before sending it. This could involve
sanitizing the query string, hashing it, or sending only safe metadata about the
search (such as search length or category) instead of the full text. Update the
properties object passed to captureEvent to exclude or transform the raw query
parameter.

In `@instrumentation-client.ts`:
- Around line 3-5: In the posthog.init() call, replace the environment variable
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN with NEXT_PUBLIC_POSTHOG_KEY to match the
documented configuration contract. Additionally, add a guard condition to check
that both NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST are defined
before calling posthog.init(), ensuring that the initialization only proceeds
when both required environment variables are present to prevent undefined values
from being passed to the init method.

---

Nitpick comments:
In `@lib/posthog/helpers.ts`:
- Around line 10-15: The captureEvent function currently accepts any string for
the event parameter, which allows silent typos and bypasses type safety. Replace
the event parameter type from a generic string to use the POSTHOG_EVENTS value
union instead. This will enforce compile-time safety by ensuring only valid
event names from your typed event map can be passed to the captureEvent
function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e1ea13f0-e6c4-4720-b6c0-15233a28cb8f

📥 Commits

Reviewing files that changed from the base of the PR and between 77d2176 and b9677e0.

📒 Files selected for processing (10)
  • app/error.tsx
  • app/providers.tsx
  • components/BookEvent.tsx
  • components/CreateNewEvent.tsx
  • components/EventCard.tsx
  • components/SearchFilters.tsx
  • instrumentation-client.ts
  • lib/posthog.js
  • lib/posthog/events.ts
  • lib/posthog/helpers.ts
💤 Files with no reviewable changes (1)
  • lib/posthog.js

Comment thread components/BookEvent.tsx
Comment thread components/SearchFilters.tsx
Comment thread instrumentation-client.ts Outdated
@SatyamPandey-07 SatyamPandey-07 added SSoC26 TO CONTRIBUTE Hard labels Jun 23, 2026
@SatyamPandey-07 SatyamPandey-07 merged commit a5a0175 into niharika-mente:main Jun 23, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hard SSoC26 TO CONTRIBUTE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] : Posthog integration for tracking user and generate analytics

2 participants