@@ -9,7 +9,7 @@ import type { Plugin } from "unified"
99import * as Icons from "@medusajs/icons"
1010import * as HookValues from "@/specs/hook-values"
1111import { colors as allColors } from "@/config/colors"
12- import { posthog } from "posthog-js "
12+ import { PostHog } from "posthog-node "
1313
1414type Params = {
1515 params : Promise < { slug : string [ ] } >
@@ -43,24 +43,20 @@ export async function GET(req: NextRequest, { params }: Params) {
4343 acceptHeader . includes ( "text/plain" ) ||
4444 acceptHeader . includes ( "text/markdown" )
4545 ) {
46- if ( ! posthog . __loaded ) {
47- posthog . init ( process . env . NEXT_PUBLIC_POSTHOG_KEY ! , {
48- api_host : process . env . NEXT_PUBLIC_POSTHOG_HOST ,
49- person_profiles : "always" ,
50- defaults : "2025-05-24" ,
51- } )
52- }
46+ const client = new PostHog ( process . env . NEXT_PUBLIC_POSTHOG_KEY ! , {
47+ host : process . env . NEXT_PUBLIC_POSTHOG_HOST ,
48+ } )
5349
54- posthog . capture (
55- "md_content_requested_agents" ,
56- {
50+ client . capture ( {
51+ distinctId : "anonymous" ,
52+ event : "md_content_requested_agents" ,
53+ properties : {
5754 $current_url : req . url ,
5855 $raw_user_agent : req . headers . get ( "user-agent" ) || undefined ,
5956 } ,
60- {
61- send_instantly : true ,
62- }
63- )
57+ } )
58+
59+ await client . shutdown ( )
6460 }
6561
6662 return new NextResponse ( cleanMdContent + PLAINTEXT_DOC_MESSAGE , {
0 commit comments