integration-nextjs-pages-router

द्वारा posthog

PostHog का एकीकरण Next.js Pages Router अनुप्रयोगों के लिए

npx skills add https://github.com/posthog/skills --skill integration-nextjs-pages-router

PostHog integration for Next.js Pages Router

This skill helps you add PostHog analytics to Next.js Pages Router applications.

Workflow

Follow these steps in order to complete the integration:

  1. basic-integration-1.0-begin.md - PostHog Setup - Begin ← Start here
  2. basic-integration-1.1-edit.md - PostHog Setup - Edit
  3. basic-integration-1.2-revise.md - PostHog Setup - Revise
  4. basic-integration-1.3-conclude.md - PostHog Setup - Conclusion

Reference files

  • references/EXAMPLE.md - Next.js Pages Router example project code
  • references/next-js.md - Next.js - docs
  • references/identify-users.md - Identify users - docs
  • references/basic-integration-1.0-begin.md - PostHog setup - begin
  • references/basic-integration-1.1-edit.md - PostHog setup - edit
  • references/basic-integration-1.2-revise.md - PostHog setup - revise
  • references/basic-integration-1.3-conclude.md - PostHog setup - conclusion

The example project shows the target implementation pattern. Consult the documentation for API details.

Key principles

  • Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
  • Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
  • Match the example: Your implementation should follow the example project's patterns as closely as possible.

Framework guidelines

  • For Next.js 15.3+, initialize PostHog in instrumentation-client.ts for the simplest setup
  • For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
  • Add analytics capture in event handlers where user actions occur, NOT in useEffect reacting to state changes
  • Do NOT use useEffect for data transformation - calculate derived values during render instead
  • Do NOT use useEffect to respond to user events - put that logic in the event handler itself
  • Do NOT use useEffect to chain state updates - calculate all related updates together in the event handler
  • Do NOT use useEffect to notify parent components - call the parent callback alongside setState in the event handler
  • To reset component state when a prop changes, pass the prop as the component's key instead of using useEffect
  • useEffect is ONLY for synchronizing with external systems (non-React widgets, browser APIs, network subscriptions)

Identifying users

Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to maintain correlation.

Error tracking

Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.

posthog की और Skills

error-tracking-hono
posthog
PostHog द्वारा Hono के लिए त्रुटि ट्रैकिंग
tuning-incremental-sync-config
posthog
एक सिंक का कॉन्फ़िगरेशन ExternalDataSchema पर रहता है और इसे external-data-schemas-partial-update के माध्यम से कभी भी बदला जा सकता है। अधिकांश परिवर्तन गैर-विनाशकारी होते हैं (अगले सिंक पर प्रभावी होते हैं), लेकिन कुछ (sync_type बदलना, प्राथमिक कुंजियाँ बदलना) को सिंक किए गए डेटा को दूषित होने से बचाने के लिए सावधानीपूर्वक संभालने की आवश्यकता होती है।
playwright-test
posthog
प्लेराइट परीक्षण लिखें, सुनिश्चित करें कि यह चले, और अस्थिर न हो।
error-tracking-ruby
posthog
PostHog द्वारा Ruby के लिए त्रुटि ट्रैकिंग
authoring-log-alerts
posthog
PostHog प्रोजेक्ट में सेवाओं पर उपयोगी, कम-शोर वाले लॉग अलर्ट लिखें। जब उपयोगकर्ता अपने लॉग के लिए अलर्ट सेट करने, जोड़ने के लिए सुझाव देने आदि के लिए कहे, तब उपयोग करें।
making-scenes-tab-aware
posthog
Guides converting PostHog frontend scenes to be tab aware for internal scene tabs. Use when adding or refactoring a `SceneExport` scene, fixing state leaking…
posthog-survey-creator
posthog
PostHog में सर्वेक्षण बनाएँ और कॉन्फ़िगर करें, मार्गदर्शित बातचीत के माध्यम से। इस कौशल का उपयोग तब करें जब कोई उपयोगकर्ता सर्वेक्षण बनाना चाहता है, उपयोगकर्ता प्रतिक्रिया एकत्र करना चाहता है, चलाना चाहता है…
authoring-scouts
posthog
PostHog Signals स्काउट्स को लिखने, संपादित करने और अनुकूलित करने का तरीका — ये निर्धारित एजेंट हैं जो किसी प्रोजेक्ट को स्कैन करते हैं और Signals इनबॉक्स में रिपोर्ट लिखते हैं। उपयोग तब करें जब कोई उपयोगकर्ता…