@@ -4,37 +4,42 @@ import { defineNuxtPlugin } from '#imports'
44
55// ////////////////////////////////////////////////////////////////////// Export
66// -----------------------------------------------------------------------------
7- export default defineNuxtPlugin ( ( nuxtApp ) => {
7+ export default defineNuxtPlugin ( ( ) => {
8+ if ( process . server ) { return } // only run client-side
89
9- // Do not fire Plausible if not in production mode
10- // unless tracking localhost is explicitly enabled in the config
11- if ( process . env . NODE_ENV !== 'production' ) {
12- if ( ! nuxtApp . $config . public . plausible . trackLocalhost ) {
13- return
14- }
10+ const router = useRouter ( )
11+ const config = useRuntimeConfig ( ) . public
12+
13+ // Only run in production OR if trackLocalhost is explcitly set to true
14+ if ( process . env . NODE_ENV !== 'production' || ! config . trackLocalhost === true ) {
15+ return
1516 }
1617
17- const router = nuxtApp . $router
18- const config = nuxtApp . $config . public . siteUrl
18+ console . log ( 'PASS' )
19+
1920 let isInitialPageLoad = true
2021
21- router . afterEach ( ( to ) => {
22+ router . afterEach ( to => {
23+
24+ console . log ( to )
2225
2326 // Ignore initial page because it's fired in the head
2427 if ( isInitialPageLoad ) {
2528 isInitialPageLoad = false
2629 return
2730 }
2831
29- // Check if we're on client-side
30- if ( process . client ) {
31- // Track virtual navigation changes
32- window . plausible = window . plausible || function ( ) {
33- ( window . plausible . q = window . plausible . q || [ ] ) . push ( arguments )
34- }
35- window . plausible ( 'pageview' , {
36- url : `${ config . public . siteUrl } ${ to . fullPath } `
37- } )
32+ // Track virtual navigation changes
33+ window . plausible = window . plausible || function ( ) {
34+ ( window . plausible . q = window . plausible . q || [ ] ) . push ( arguments )
3835 }
36+
37+ console . log ( {
38+ url : `${ config . siteUrl } ${ to . fullPath } `
39+ } )
40+
41+ window . plausible ( 'pageview' , {
42+ url : `${ config . siteUrl } ${ to . fullPath } `
43+ } )
3944 } )
4045} )
0 commit comments