File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Public URL, used for OG Image when running nuxt generate
22NUXT_PUBLIC_SITE_URL =
3+
4+ # PostHog Analytics (Europe region)
5+ # Get your project API key from: https://eu.posthog.com/settings/project
6+ NUXT_PUBLIC_POSTHOG_PUBLIC_KEY =
7+
8+ # SubmitJSON API Key
9+ NUXT_PUBLIC_SUBMIT_JSON_API_KEY =
Original file line number Diff line number Diff line change 1+ import posthog from 'posthog-js'
2+
3+ export default defineNuxtPlugin ( ( ) => {
4+ const runtimeConfig = useRuntimeConfig ( )
5+ const posthogClient = posthog . init ( runtimeConfig . public . posthogPublicKey , {
6+ api_host : runtimeConfig . public . posthogHost ,
7+ person_profiles : 'identified_only' ,
8+ capture_pageview : false , // We'll handle this manually with the router,
9+ cookieless_mode : 'always' , // Use cookieless mode to avoid cookie consent issues
10+ loaded : ( posthog ) => {
11+ if ( import . meta. env . MODE === 'development' ) posthog . debug ( )
12+ }
13+ } )
14+
15+ // Track page views with Vue Router
16+ const router = useRouter ( )
17+ router . afterEach ( ( to ) => {
18+ nextTick ( ( ) => {
19+ posthog . capture ( '$pageview' , {
20+ current_url : to . fullPath
21+ } )
22+ } )
23+ } )
24+
25+ return {
26+ provide : {
27+ posthog : ( ) => posthogClient
28+ }
29+ }
30+ } )
Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ export default defineNuxtConfig({
4141
4242 runtimeConfig : {
4343 public : {
44- submitJsonApiKey : ''
44+ submitJsonApiKey : '' ,
45+ posthogPublicKey : '' ,
46+ posthogHost : 'https://eu.i.posthog.com'
4547 }
4648 } ,
4749
You can’t perform that action at this time.
0 commit comments