├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .npmrc ├── .nuxtrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── docs └── cover.png ├── eslint.config.js ├── package.json ├── playground ├── app.vue ├── nuxt.config.ts └── package.json ├── pnpm-lock.yaml ├── renovate.json ├── src ├── module.ts └── runtime │ └── plugin.client.ts └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | push: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | - run: corepack enable 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: 20 21 | cache: "pnpm" 22 | 23 | - name: 📦 Install dependencies 24 | run: pnpm install --frozen-lockfile 25 | 26 | - name: 🔠 Lint project 27 | run: pnpm lint 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | node_modules 3 | 4 | # Logs 5 | *.log* 6 | 7 | # Temp directories 8 | .temp 9 | .tmp 10 | .cache 11 | 12 | # Yarn 13 | **/.yarn/cache 14 | **/.yarn/*state* 15 | 16 | # Generated dirs 17 | dist 18 | 19 | # Nuxt 20 | .nuxt 21 | .output 22 | .vercel_build_output 23 | .build-* 24 | .env 25 | .netlify 26 | 27 | # Env 28 | .env 29 | 30 | # Testing 31 | reports 32 | coverage 33 | *.lcov 34 | .nyc_output 35 | 36 | # VSCode 37 | .vscode/* 38 | !.vscode/settings.json 39 | !.vscode/tasks.json 40 | !.vscode/launch.json 41 | !.vscode/extensions.json 42 | !.vscode/*.code-snippets 43 | 44 | # Intellij idea 45 | *.iml 46 | .idea 47 | 48 | # OSX 49 | .DS_Store 50 | .AppleDouble 51 | .LSOverride 52 | .AppleDB 53 | .AppleDesktop 54 | Network Trash Folder 55 | Temporary Items 56 | .apdisk 57 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | strict-peer-dependencies=false 3 | -------------------------------------------------------------------------------- /.nuxtrc: -------------------------------------------------------------------------------- 1 | imports.autoImport=false 2 | typescript.includeWorkspace=true 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.0.3 4 | 5 | [compare changes](https://github.com/xanderbale/nuxt-vercel-analytics/compare/v1.0.2...v1.0.3) 6 | 7 | ### 🏡 Chore 8 | 9 | - Update dependency @vercel/analytics to v1.2.2 ([#78](https://github.com/xanderbale/nuxt-vercel-analytics/pull/78)) 10 | - **release:** V1.0.2 ([3a328cc](https://github.com/xanderbale/nuxt-vercel-analytics/commit/3a328cc)) 11 | - Delete .eslintignore ([46058c4](https://github.com/xanderbale/nuxt-vercel-analytics/commit/46058c4)) 12 | - Migrate eslint config ([51d4779](https://github.com/xanderbale/nuxt-vercel-analytics/commit/51d4779)) 13 | - Fix eslint config ([71b255e](https://github.com/xanderbale/nuxt-vercel-analytics/commit/71b255e)) 14 | - Update @nuxt/eslint-config ([989e333](https://github.com/xanderbale/nuxt-vercel-analytics/commit/989e333)) 15 | - Update author info ([fa4ee68](https://github.com/xanderbale/nuxt-vercel-analytics/commit/fa4ee68)) 16 | 17 | ### ❤️ Contributors 18 | 19 | - Alexander Barkhatov 20 | 21 | ## v1.0.2 22 | 23 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v1.0.1...v1.0.2) 24 | 25 | ### 🏡 Chore 26 | 27 | - Update dependency @vercel/analytics to v1.2.2 ([#78](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/pull/78)) 28 | 29 | ### ❤️ Contributors 30 | 31 | - Alexander Barkhatov ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 32 | 33 | ## v1.0.1 34 | 35 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v1.0.0...v1.0.1) 36 | 37 | ### 📖 Documentation 38 | 39 | - Use new `nuxi module add` command in installation ([#81](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/pull/81)) 40 | 41 | ### ❤️ Contributors 42 | 43 | - Daniel Roe ([@danielroe](http://github.com/danielroe)) 44 | 45 | ## v1.0.0 46 | 47 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.2.3...v1.0.0) 48 | 49 | ## v0.2.3 50 | 51 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.0.1...v0.2.3) 52 | 53 | ### 💅 Refactors 54 | 55 | - Types ([3fc4d69](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/3fc4d69)) 56 | 57 | ### 📖 Documentation 58 | 59 | - Use absolute cover url ([fb54bfe](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/fb54bfe)) 60 | - Fix absolute url ([8e917eb](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/8e917eb)) 61 | 62 | ### ❤️ Contributors 63 | 64 | - Alexander Barkhatov ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 65 | - Alexander B ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 66 | 67 | ## v0.2.2 68 | 69 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.2.1...v0.2.2) 70 | 71 | ### 📖 Documentation 72 | 73 | - Add cover and emojis ([eaa85ff](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/eaa85ff)) 74 | 75 | ### ❤️ Contributors 76 | 77 | - Alexander B ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 78 | 79 | ## v0.2.1 80 | 81 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.2.0...v0.2.1) 82 | 83 | ### 🩹 Fixes 84 | 85 | - Add config types ([3d8450b](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/3d8450b)) 86 | 87 | ### ❤️ Contributors 88 | 89 | - Alexander B ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 90 | 91 | ## v0.2.0 92 | 93 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.1.4...v0.2.0) 94 | 95 | ### 🩹 Fixes 96 | 97 | - ⚠️ Move config to app.config.ts ([275964e](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/275964e)) 98 | 99 | #### ⚠️ Breaking Changes 100 | 101 | - ⚠️ Move config to app.config.ts ([275964e](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/275964e)) 102 | 103 | ### ❤️ Contributors 104 | 105 | - Alexander B ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 106 | 107 | ## v0.1.4 108 | 109 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.1.3...v0.1.4) 110 | 111 | ## v0.1.3 112 | 113 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.1.2...v0.1.3) 114 | 115 | ### 🚀 Enhancements 116 | 117 | - Auto-import track fn ([2a4a8e3](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/2a4a8e3)) 118 | 119 | ### 📖 Documentation 120 | 121 | - Add custom events ([f77e8dd](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/f77e8dd)) 122 | 123 | ### 🏡 Chore 124 | 125 | - Add renovate config ([59f9086](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/59f9086)) 126 | - Update renovate config ([89e4465](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/89e4465)) 127 | - Fix renovate config ([34303bb](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/34303bb)) 128 | - Fix kit ver ([b32611b](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/b32611b)) 129 | - Update analytics package ([9cc60a1](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/9cc60a1)) 130 | 131 | ### 🤖 CI 132 | 133 | - Add PR workflow ([70f9410](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/70f9410)) 134 | - Fix build command ([f76fbe9](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/f76fbe9)) 135 | - Remove build step from test job ([ea8a103](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/ea8a103)) 136 | - Fix test command ([289ffea](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/289ffea)) 137 | - Fix test job ([5cbf89d](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/5cbf89d)) 138 | 139 | ### ❤️ Contributors 140 | 141 | - Alexander B ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 142 | - Alexander ([@xanderbarkhatov](http://github.com/xanderbarkhatov)) 143 | - Alexander Barkhatov 144 | 145 | ## v0.1.2 146 | 147 | [compare changes](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/compare/v0.1.1...v0.1.2) 148 | 149 | ### 📖 Documentation 150 | 151 | - Remove publish info from README ([0ee126a](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/0ee126a)) 152 | 153 | ### ❤️ Contributors 154 | 155 | - Alexander Barkhatov 156 | 157 | ## v0.1.1 158 | 159 | ### 📖 Documentation 160 | 161 | - Fix package name ([50de37c](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/50de37c)) 162 | 163 | ### 🏡 Chore 164 | 165 | - **release:** V0.1.1 ([b1f9c21](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/b1f9c21)) 166 | 167 | ### ❤️ Contributors 168 | 169 | - Alexander Barkhatov 170 | 171 | ## v0.1.1 172 | 173 | ### 📖 Documentation 174 | 175 | - Fix package name ([50de37c](https://github.com/xanderbarkhatov/nuxt-vercel-analytics/commit/50de37c)) 176 | 177 | ### ❤️ Contributors 178 | 179 | - Alexander Barkhatov 180 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 xanderbarkhatov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Nuxt Vercel Analytics](https://raw.githubusercontent.com/xanderbarkhatov/nuxt-vercel-analytics/main/docs/cover.png) 2 | 3 | # Nuxt Vercel Analytics 4 | 5 | [![npm version][npm-version-src]][npm-version-href] 6 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 7 | [![License][license-src]][license-href] 8 | [![Nuxt][nuxt-src]][nuxt-href] 9 | 10 | > [Vercel Analytics](https://vercel.com/docs/concepts/analytics) integration for Nuxt 11 | 12 | ## 📝 Features 13 | 14 | - 🚀 Zero-config 15 | - 📥 Auto-imports 16 | 17 | ## 🔧 Setup 18 | 19 | ```bash 20 | npx nuxi@latest module add vercel-analytics 21 | ``` 22 | 23 | That's it! Vercel Analytics is now integrated in your Nuxt app ✨ 24 | 25 | ## ⚙️ Configuration 26 | 27 | ```js 28 | // app.config.ts 29 | export default defineAppConfig({ 30 | vercelAnalytics: { 31 | mode: "auto", 32 | debug: true, 33 | beforeSend: (event) => { 34 | if (event.url.includes("/private")) return null; 35 | 36 | return event; 37 | }, 38 | }, 39 | }); 40 | ``` 41 | 42 | ## 📈 Custom Events 43 | 44 | To track an event, call `vercelTrack` and pass in a string representing the event name as the first argument 45 | 46 | ```js 47 | const onSignup = () => { 48 | vercelTrack("Signup"); 49 | // ...other logic 50 | }; 51 | ``` 52 | 53 | ### Custom data 54 | 55 | You can also pass custom data along with an event by passing an object as the second argument 56 | 57 | ```js 58 | const onSignup = () => { 59 | vercelTrack("Signup", { location: "footer" }); 60 | // ...other logic 61 | }; 62 | ``` 63 | 64 | 65 | 66 | [npm-version-src]: https://img.shields.io/npm/v/nuxt-vercel-analytics/latest.svg?style=flat&colorA=18181B&colorB=28CF8D 67 | [npm-version-href]: https://npmjs.com/package/nuxt-vercel-analytics 68 | [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-vercel-analytics.svg?style=flat&colorA=18181B&colorB=28CF8D 69 | [npm-downloads-href]: https://npmjs.com/package/nuxt-vercel-analytics 70 | [license-src]: https://img.shields.io/npm/l/nuxt-vercel-analytics.svg?style=flat&colorA=18181B&colorB=28CF8D 71 | [license-href]: https://npmjs.com/package/nuxt-vercel-analytics 72 | [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js 73 | [nuxt-href]: https://nuxt.com 74 | -------------------------------------------------------------------------------- /docs/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aleksdotbar/nuxt-vercel-analytics/a2841870310965c9ab44876da4500f7869d51679/docs/cover.png -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import { createConfigForNuxt } from "@nuxt/eslint-config/flat"; 2 | 3 | export default createConfigForNuxt({ 4 | // options here 5 | }); 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt-vercel-analytics", 3 | "version": "1.0.3", 4 | "description": "Nuxt module to integrate Vercel Analytics", 5 | "keywords": [ 6 | "nuxt", 7 | "nuxt3", 8 | "vercel", 9 | "analytics" 10 | ], 11 | "homepage": "https://github.com/xanderbale/nuxt-vercel-analytics#readme", 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/xanderbale/nuxt-vercel-analytics.git" 15 | }, 16 | "license": "MIT", 17 | "type": "module", 18 | "exports": { 19 | ".": { 20 | "types": "./dist/types.d.ts", 21 | "import": "./dist/module.mjs", 22 | "require": "./dist/module.cjs" 23 | } 24 | }, 25 | "main": "./dist/module.cjs", 26 | "types": "./dist/types.d.ts", 27 | "files": [ 28 | "dist" 29 | ], 30 | "scripts": { 31 | "build": "pnpm dev:prepare && nuxt-module-build", 32 | "dev": "nuxi dev playground", 33 | "dev:build": "nuxi build playground", 34 | "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground", 35 | "lint": "eslint .", 36 | "prepack": "pnpm build", 37 | "release": "npm run lint && npm run prepack && changelogen --release && npm publish && git push --follow-tags" 38 | }, 39 | "dependencies": { 40 | "@nuxt/kit": "3.10.1", 41 | "@vercel/analytics": "^1.0.0", 42 | "defu": "^6.1.2" 43 | }, 44 | "devDependencies": { 45 | "@nuxt/eslint-config": "0.3.13", 46 | "@nuxt/module-builder": "0.5.5", 47 | "@nuxt/schema": "3.10.1", 48 | "changelogen": "0.5.5", 49 | "eslint": "9.2.0", 50 | "nuxt": "3.10.1" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /playground/app.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /playground/nuxt.config.ts: -------------------------------------------------------------------------------- 1 | export default defineNuxtConfig({ 2 | modules: ["../src/module"], 3 | }); 4 | -------------------------------------------------------------------------------- /playground/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "nuxt-vercel-analytics-playground" 4 | } 5 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["github>danielroe/renovate"] 4 | } 5 | -------------------------------------------------------------------------------- /src/module.ts: -------------------------------------------------------------------------------- 1 | import { 2 | defineNuxtModule, 3 | addPlugin, 4 | addImports, 5 | createResolver, 6 | } from "@nuxt/kit"; 7 | import type { AnalyticsProps } from "@vercel/analytics"; 8 | 9 | export default defineNuxtModule({ 10 | meta: { 11 | name: "nuxt-vercel-analytics", 12 | }, 13 | setup() { 14 | const { resolve } = createResolver(import.meta.url); 15 | 16 | addPlugin({ 17 | src: resolve("./runtime/plugin.client"), 18 | mode: "client", 19 | }); 20 | 21 | addImports({ 22 | from: "@vercel/analytics", 23 | name: "track", 24 | as: "vercelTrack", 25 | }); 26 | }, 27 | }); 28 | 29 | interface VercelAnanalyticsOptions { 30 | /** 31 | * Override the automatic environment detection. 32 | * This option allows you to force a specific environment for the package. 33 | * @default 'auto' 34 | */ 35 | mode?: AnalyticsProps["mode"]; 36 | 37 | /** 38 | * You'll see all analytics events in the browser's console with the debug mode. 39 | * This option is automatically enabled if the NODE_ENV environment variable is available and is either development or test. 40 | */ 41 | debug?: AnalyticsProps["debug"]; 42 | 43 | /** 44 | * With the beforeSend option, you can modify the event data before it's sent to Vercel. 45 | * Returning null will ignore the event and no data will be sent. 46 | */ 47 | beforeSend?: AnalyticsProps["beforeSend"]; 48 | } 49 | 50 | declare module "nuxt/schema" { 51 | interface CustomAppConfig { 52 | vercelAnalytics?: VercelAnanalyticsOptions; 53 | } 54 | } 55 | 56 | declare module "@nuxt/schema" { 57 | interface CustomAppConfig { 58 | vercelAnalytics?: VercelAnanalyticsOptions; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/runtime/plugin.client.ts: -------------------------------------------------------------------------------- 1 | import { defineNuxtPlugin, useAppConfig } from "#app"; 2 | import { inject } from "@vercel/analytics"; 3 | 4 | export default defineNuxtPlugin(() => { 5 | const config = useAppConfig(); 6 | 7 | inject(config.vercelAnalytics); 8 | }); 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./playground/.nuxt/tsconfig.json" 3 | } 4 | --------------------------------------------------------------------------------