@@ -4,37 +4,42 @@ import { defineNuxtPlugin } from '#imports'
4
4
5
5
// ////////////////////////////////////////////////////////////////////// Export
6
6
// -----------------------------------------------------------------------------
7
- export default defineNuxtPlugin ( ( nuxtApp ) => {
7
+ export default defineNuxtPlugin ( ( ) => {
8
+ if ( process . server ) { return } // only run client-side
8
9
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
15
16
}
16
17
17
- const router = nuxtApp . $router
18
- const config = nuxtApp . $config . public . siteUrl
18
+ console . log ( 'PASS' )
19
+
19
20
let isInitialPageLoad = true
20
21
21
- router . afterEach ( ( to ) => {
22
+ router . afterEach ( to => {
23
+
24
+ console . log ( to )
22
25
23
26
// Ignore initial page because it's fired in the head
24
27
if ( isInitialPageLoad ) {
25
28
isInitialPageLoad = false
26
29
return
27
30
}
28
31
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 )
38
35
}
36
+
37
+ console . log ( {
38
+ url : `${ config . siteUrl } ${ to . fullPath } `
39
+ } )
40
+
41
+ window . plausible ( 'pageview' , {
42
+ url : `${ config . siteUrl } ${ to . fullPath } `
43
+ } )
39
44
} )
40
45
} )
0 commit comments