File tree Expand file tree Collapse file tree 11 files changed +121
-234
lines changed
Expand file tree Collapse file tree 11 files changed +121
-234
lines changed Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ if (import .meta .server ) {
3+ await trackPageview ();
4+ }
5+ </script >
6+
17<template >
28 <div >
39 <NuxtRouteAnnouncer />
4- <NuxtWelcome />
10+ <NuxtPage />
511 </div >
612</template >
Original file line number Diff line number Diff line change 1+ export default defineNuxtRouteMiddleware ( async ( to ) => {
2+ // We track pageviews on the server only
3+ if ( import . meta. client ) {
4+ return ;
5+ }
6+
7+ if ( to . path . startsWith ( "/api/" ) ) {
8+ return ;
9+ }
10+
11+ await trackPageview ( ) ;
12+ } ) ;
Original file line number Diff line number Diff line change 22export default defineNuxtConfig ( {
33 compatibilityDate : "2025-07-15" ,
44 devtools : { enabled : true } ,
5+ modules : [ "@simpleanalytics/nuxt" ] ,
56} ) ;
Original file line number Diff line number Diff line change 1+ import { defineEventHandler , createError } from "h3" ;
2+
3+ export default defineEventHandler ( async ( event ) => {
4+ try {
5+ await trackEvent ( "button_clicked" , {
6+ event,
7+ metadata : {
8+ source : "test_page" ,
9+ } ,
10+ } ) ;
11+
12+ return {
13+ success : true ,
14+ message : "Button click event tracked successfully" ,
15+ } ;
16+ } catch ( error ) {
17+ console . error ( "Error tracking event:" , error ) ;
18+ throw createError ( {
19+ statusCode : 500 ,
20+ statusMessage : "Failed to track event" ,
21+ } ) ;
22+ }
23+ } ) ;
Original file line number Diff line number Diff line change 3636 "test:types" : " vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
3737 },
3838 "dependencies" : {
39- "@nuxt/kit" : " ^4.0.2"
39+ "@nuxt/kit" : " ^4.0.2" ,
40+ "simple-analytics-vue" : " ^3.0.3"
4041 },
4142 "devDependencies" : {
4243 "@nuxt/devtools" : " ^2.6.2" ,
4748 "@types/node" : " ^24.2.0" ,
4849 "changelogen" : " ^0.6.2" ,
4950 "eslint" : " ^9.32.0" ,
50- "nuxt" : " ^3 || ^ 4" ,
51+ "nuxt" : " ^4" ,
5152 "typescript" : " ~5.9.2" ,
5253 "vitest" : " ^3.2.4" ,
5354 "vue-tsc" : " ^3.0.5"
Original file line number Diff line number Diff line change 44 addServerHandler ,
55 addImports ,
66 addServerImports ,
7+ addPlugin ,
78} from "@nuxt/kit" ;
89import type { SimpleAnalyticsOptions } from "./runtime/server/lib/options" ;
910
@@ -35,7 +36,7 @@ export default defineNuxtModule<ModuleOptions>({
3536
3637 nuxt . options . runtimeConfig . public . simpleAnalytics = configOptions ;
3738
38- // addPlugin(resolver.resolve(' ./runtime/plugin'))
39+ addPlugin ( resolver . resolve ( " ./runtime/plugin" ) ) ;
3940
4041 addImports ( [
4142 {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import { defineNuxtPlugin } from "#app" ;
1+ import { useRuntimeConfig } from "#imports" ;
2+ import { defineNuxtPlugin } from "nuxt/app" ;
23
3- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4- export default defineNuxtPlugin ( ( nuxtApp ) => { } ) ;
4+ import SimpleAnalytics from "simple-analytics-vue" ;
5+
6+ export default defineNuxtPlugin ( ( nuxtApp ) => {
7+ const config = useRuntimeConfig ( ) ;
8+
9+ nuxtApp . vueApp . use ( SimpleAnalytics , {
10+ skip : ! config . public . simpleAnalytics . enabled ,
11+ domain : config . public . simpleAnalytics . domain ,
12+ } ) ;
13+ } ) ;
Original file line number Diff line number Diff line change 11export interface SimpleAnalyticsOptions {
22 autoCollect ?: boolean ;
33 collectDnt ?: boolean ;
4+ domain ?: string ;
45 hostname ?: string ;
56 mode ?: "dash" ;
67 ignoreMetrics ?: {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ declare module "@nuxt/schema" {
88 simpleAnalytics : {
99 autoCollect ?: boolean ;
1010 collectDnt ?: boolean ;
11+ domain ?: string ;
1112 hostname ?: string ;
1213 mode ?: "dash" ;
1314 ignoreMetrics ?: {
You can’t perform that action at this time.
0 commit comments