토론

프로덕션 등급 PostHog 통합 for Next.js 15

Wikiprompt, 무료 프롬프트 백과사전에서

Tugrul Erdem

2026년 1월 23일

프로덕션 등급 PostHog 통합 for Next.js 15 Next.js 15 SaaS 앱( Supabase 인증 및 Polar 결제 사용)에 PostHog 분석, 세션 리플레이, 기능 플래그, 오류 추적을 통합하기 위한 시니어 Next.js 아키텍트용 종합 시스템 프롬프트입니다.

프롬프트 내용저장

🌐
{ "package.json": { "dependencies": { "posthog-js": "^1.200.0" } }, "app/providers.tsx": "'use client'; import { PostHogProvider } from 'posthog-js/react'; import posthog from 'posthog-js'; import { Suspense, useEffect } from 'react'; import PostHogPageView from '@/components/PostHogPageView'; import { useAnalyticsAuth } from '@/hooks/useAnalyticsAuth'; if (typeof window !== 'undefined') { posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, { api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', capture_pageview: false, capture_pageleave: true, session_replay: { mask_all_text_inputs: true } }); } export function Providers({ children }: { children: React.ReactNode }) { useAnalyticsAuth(); return ( <PostHogProvider client={posthog}> <Suspense fallback={null}> <PostHogPageView /> </Suspense> {children} </PostHogProvider> ); }", "lib/analytics.ts": "import posthog from 'posthog-js'; export enum AnalyticsEvents { CHECKOUT_STARTED = 'CHECKOUT_STARTED', SUBSCRIPTION_CREATED = 'SUBSCRIPTION_CREATED', ERROR = '$exception' } interface AnalyticsProperties { [key: string]: string | number | boolean | null | undefined; } export function trackEvent(event: AnalyticsEvents, properties?: AnalyticsProperties) { if (typeof window === 'undefined') return; posthog.capture(event, properties); } export function trackError(message: string, stack?: string) { if (typeof window === 'undefined') return; posthog.capture(AnalyticsEvents.ERROR, { message, stack }); }", "hooks/useAnalyticsAuth.ts": "'use client'; import { useEffect } from 'react'; import { createClient } from '@supabase/supabase-js'; import posthog from 'posthog-js'; const supabase = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY! ); export function useAnalyticsAuth() { useEffect(() => { const { data: { subscription } } = supabase.auth.onAuthStateChange((event, session) => { if (event === 'SIGNED_IN' && session?.user) { posthog.identify(session.user.id, { email: session.user.email, polar_customer_id: session.user.user_metadata?.polar_customer_id }); } if (event === 'SIGNED_OUT') { posthog.reset(); } }); return () => subscription.unsubscribe(); }, []); }", "components/PostHogPageView.tsx": "'use client'; import { usePathname, useSearchParams } from 'next/navigation'; import { useEffect } from 'react'; import posthog from 'posthog-js'; export default function PostHogPageView() { const pathname = usePathname(); const searchParams = useSearchParams(); useEffect(() => { if (pathname) { posthog.capture('$pageview', { pathname, search: searchParams?.toString() || '' }); } }, [pathname, searchParams]); return null; }", "app/layout.tsx": "import type { Metadata } from 'next'; import { Providers } from './providers'; export const metadata: Metadata = { title: 'SaaS App', description: 'Production-grade SaaS application' }; export default function RootLayout({ children }: { children: React.ReactNode; }) { return ( <html lang=\"en\"> <body> <Providers>{children}</Providers> </body> </html> ); }" }

전체 프롬프트를 보려면 로그인하세요

Continue with:

By logging in, you agree to our Terms of Use and Privacy Policy

사용법

이 프롬프트는 coding와 함께 사용하도록 설계되었습니다. 위의 프롬프트 내용을 복사하여 원하는 AI 도구에 붙여넣으세요.

최상의 결과를 얻으려면 자리 표시자(대괄호 또는 대문자로 표시)를 특정 요구 사항으로 사용자 지정할 수 있습니다.

참고 자료

분류:coding| prompts.chat| nextjs-15| posthog

토론