Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/nuxt/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { Analytics, type BeforeSendEvent } from '@vercel/analytics/nuxt';

const beforeSend = (event: BeforeSendEvent) => {
console.log('Sending event:', event);
return event;
};
</script>

<template>
<Analytics :before-send="beforeSend" />
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
20 changes: 0 additions & 20 deletions apps/nuxt/app/app.vue

This file was deleted.

1 change: 0 additions & 1 deletion apps/nuxt/app/assets/logo.svg

This file was deleted.

4 changes: 0 additions & 4 deletions apps/nuxt/app/pages/blog.vue

This file was deleted.

9 changes: 0 additions & 9 deletions apps/nuxt/app/pages/blog/[category].vue

This file was deleted.

16 changes: 0 additions & 16 deletions apps/nuxt/app/plugins/analytics.ts

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions apps/nuxt/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<script setup lang="ts">
import { track } from '@vercel/analytics';

function navigate(event: { target: { href: string } }) {
track('navigation', { to: event.target.href });
}
</script>

<template>
<header>
<img alt="Nuxt logo" class="logo" src="@/assets/logo.svg" width="180" />
<img
alt="Vue logo"
class="logo"
src="@/assets/logo.svg"
width="125"
height="125"
/>
<div class="wrapper">
<nav>
<NuxtLink to="/">Home</NuxtLink>
<NuxtLink to="/blog/various/hi">Hi!</NuxtLink>
<NuxtLink to="/blog/various/hallo">Hallo!</NuxtLink>
<NuxtLink @click="navigate" to="/">Home</NuxtLink>
<NuxtLink @click="navigate" to="/blog/various/hi">Hi!</NuxtLink>
<NuxtLink @click="navigate" to="/blog/various/hallo">Hallo!</NuxtLink>
</nav>
</div>
<slot />
Expand All @@ -18,12 +32,11 @@
header {
line-height: 1.5;
max-height: 100vh;
text-align: center;
}

.logo {
display: block;
margin: 2rem auto 2rem;
margin: 0 auto 2rem;
}

nav {
Expand Down
3 changes: 1 addition & 2 deletions apps/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-11-06',
modules: ['@vercel/analytics/nuxt/module'],
compatibilityDate: '2024-04-03',
devtools: { enabled: true },
});
3 changes: 2 additions & 1 deletion apps/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"postinstall": "nuxt prepare",
"preview": "nuxt preview"
},
"dependencies": {
"@vercel/analytics": "workspace:*",
"nuxt": "^4.2.0",
"nuxt": "^4.2.1",
"vue": "latest",
"vue-router": "latest"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<script setup lang="ts">
import { track } from '@vercel/analytics/nuxt';

const route = useRoute();
</script>

<template>
<div class="greetings">
<h1 class="green">{{ route.params.slug }}!</h1>
<button @click="track('click-button', { route: $route.path })">
Button with tracking
</button>
<h3>Category {{ route.params.category }}</h3>
</div>
</template>
File renamed without changes.
3 changes: 3 additions & 0 deletions apps/nuxt/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
17 changes: 2 additions & 15 deletions apps/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
{
"files": [],
"references": [
{
"path": "./.nuxt/tsconfig.app.json"
},
{
"path": "./.nuxt/tsconfig.server.json"
},
{
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
}
]
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
10 changes: 1 addition & 9 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/analytics",
"version": "1.6.0",
"version": "1.6.1",
"description": "Gain real-time traffic insights with Vercel Web Analytics",
"keywords": [
"analytics",
Expand Down Expand Up @@ -31,11 +31,6 @@
"import": "./dist/nuxt/index.mjs",
"require": "./dist/nuxt/index.js"
},
"./nuxt/module": {
"browser": "./dist/nuxt/module.mjs",
"import": "./dist/nuxt/module.mjs",
"require": "./dist/nuxt/module.js"
},
"./react": {
"browser": "./dist/react/index.mjs",
"import": "./dist/react/index.mjs",
Expand Down Expand Up @@ -114,8 +109,6 @@
]
},
"devDependencies": {
"@nuxt/kit": "^4.2.0",
"@nuxt/schema": "^4.2.0",
"@swc/core": "^1.9.2",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
Expand All @@ -133,7 +126,6 @@
"@remix-run/react": "^2",
"@sveltejs/kit": "^1 || ^2",
"next": ">= 13",
"nuxt": ">= 3",
"react": "^18 || ^19 || ^19.0.0-rc",
"svelte": ">= 4",
"vue": "^3",
Expand Down
37 changes: 0 additions & 37 deletions packages/web/src/nuxt/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
import { onNuxtReady, useRouter, useRoute } from 'nuxt/app';
import type { AnalyticsProps, BeforeSend, BeforeSendEvent } from '../types';
import { createComponent } from '../vue/create-component';
import { inject, pageview, track } from '../generic';
import { isBrowser, computeRoute } from '../utils';
import { getBasePath } from './utils';

// Export the Analytics component
// Not recommended as must be used in both app.vue and error.vue
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- vue's defineComponent return type is any
export const Analytics = createComponent('nuxt');
export type { AnalyticsProps, BeforeSend, BeforeSendEvent };

// Export the injectAnalytics script with automatic tracking on page changes
function injectAnalytics(props: Omit<AnalyticsProps, 'framework'> = {}): void {
if (isBrowser()) {
// eslint-disable-next-line react-hooks/rules-of-hooks -- we are not using a React here
const router = useRouter();

onNuxtReady(() => {
inject({
...props,
framework: 'nuxt',
disableAutoTrack: true,
basePath: getBasePath(),
});
const route = useRoute();
pageview({
route: computeRoute(route.path, route.params),
path: route.path,
});
});
// On navigation to a new page
router.afterEach((to) => {
pageview({
route: computeRoute(to.path, to.params),
path: to.path,
});
});
}
}

export { injectAnalytics, track };
29 changes: 0 additions & 29 deletions packages/web/src/nuxt/module.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/web/src/nuxt/utils.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/web/tsup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export default defineConfig([
...cfg,
entry: {
index: 'src/nuxt/index.ts',
module: 'src/nuxt/module.ts',
},
external: ['vue', 'vue-router', 'nuxt', '@nuxt/kit', '@nuxt/schema'],
external: ['vue', 'vue-router'],
outDir: 'dist/nuxt',
},
{
Expand Down
Loading