{"id":19846159,"url":"https://github.com/l422y/nuxt-analytics-data","last_synced_at":"2026-04-04T22:32:22.593Z","repository":{"id":132939672,"uuid":"611971271","full_name":"L422Y/nuxt-analytics-data","owner":"L422Y","description":"SSR-enabled Nuxt module which allows running of reports via the Google Analytics Data API, and includes pre-defined reports and composables for trending and popular posts, as well as an AnalyticeWidget component for trending and popular posts.","archived":false,"fork":false,"pushed_at":"2023-11-07T14:23:08.000Z","size":236,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-07T03:37:15.629Z","etag":null,"topics":["ga4","google-analytics-api","google-analytics-data","nuxt","popular","trending","typescript","vue"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L422Y.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-09T23:25:10.000Z","updated_at":"2023-03-12T21:52:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"48f813bd-9a8a-4f87-9b79-721a5c597d23","html_url":"https://github.com/L422Y/nuxt-analytics-data","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/L422Y/nuxt-analytics-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L422Y%2Fnuxt-analytics-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L422Y%2Fnuxt-analytics-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L422Y%2Fnuxt-analytics-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L422Y%2Fnuxt-analytics-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L422Y","download_url":"https://codeload.github.com/L422Y/nuxt-analytics-data/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L422Y%2Fnuxt-analytics-data/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263819235,"owners_count":23516122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ga4","google-analytics-api","google-analytics-data","nuxt","popular","trending","typescript","vue"],"created_at":"2024-11-12T13:10:39.905Z","updated_at":"2025-12-30T22:16:24.245Z","avatar_url":"https://github.com/L422Y.png","language":"TypeScript","readme":"# Nuxt Analytics Data Module\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![License][license-src]][license-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\nThis SSR-enabled Nuxt module allows running of reports via the Google Analytics Data API, and includes pre-defined\nreports and composables for trending and popular posts, as well as an AnalyticsWidget component for trending and popular\nposts.\n\nAPI responses are cached on the server side and expire\n\n## Features\n\n- Filtering of paths (exact strings or RegEx) from report data, filtering parameters are supplied to the API\n- String removal (exact string or RegEx)\n- Trending and Popular reports, composables and a `AnalyticeWidget` component.\n\n### TODO:\n\n- Ability to define your own reports: *this is partially implemented, need to figure out the best way to pass functions\n  to the module from the configuration.*\n\n## Quick Setup\n\n1. Add `nuxt-analytics-data` dependency to your project\n\n```bash\n# Using pnpm\npnpm add -D nuxt-analytics-data\n\n# Using yarn\nyarn add --dev nuxt-analytics-data\n\n# Using npm\nnpm install --save-dev nuxt-analytics-data\n```\n\n2. Add `nuxt-analytics-data` to the `modules` section of `nuxt.config.ts`\n\n```js\nexport default defineNuxtConfig({\n  modules: [\n    'nuxt-analytics-data'\n  ]\n})\n```\n\n3. Add configuration for the module:\n\n```ts\nexport default defineNuxtConfig({\n  // ...\n  analyticsData: {\n    // Specify the path to your GA credentials file or use `credentials` with the data itself\n    credentialsFile: \"./playground/src/google-service-account.json\",\n    // The GA4 property ID you are accessing\n    propertyId: \"331054024\",\n    // Clear API response cache after 15 minutes (value is in seconds)\n    cacheTimeout: 15 * 60,\n    // Use `filteredPaths` to exclude paths from your query, i.e. if you\n    // don't want the homepage or contact page.\n    filteredPaths: {\n      // Exact path filters\n      exact: [\"/references\"],\n      // RegEx Path filters -- ex: filter any first-level paths (i.e. \"/blog\" \"/projects\")\n      regEx: [`^/(\\\\w+)?\\\\/?$`]\n    },\n\n    // removeStrings will remove any matching text from the pageTitles in results\n    removeStrings: {\n      // Exact matches, ex: removing trailing tags from the title\n      exact: [` - Larry Williamson`],\n      // and/or RegEx matches\n      regEx: [` - .* - Larry Williamson`]\n    }\n    // ...\n  }\n});\n```\n\nThat's it! You can now use Nuxt Analytics Data Module in your Nuxt app ✨\n\n## Usage\n\n### `$analyticsData`\n\nThe retrieved data is stored in `useState('analyticsData')` as well as provided in the Nuxt application\nas `$analyticsData`\n\n```ts\nconst {$analyticsData} = useNuxtApp()\n\nconst analyticsData = useState(\"analyticsData\")\n\n```\n\nData is formatted like this:\n\n```json\n\n{\n  \"popular\": {\n    \"/blog\": {\n      \"pageTitle\": \"Blog\",\n      \"screenPageViews\": \"129\"\n    },\n    \"/blog/countdown-for-vue-with-composables\": {\n      \"pageTitle\": \"Building a Countdown Component for Vue with Composables\",\n      \"screenPageViews\": \"96\"\n    }\n  },\n  \"trending\": {\n    \"/\": {\n      \"pageTitle\": \"Home\",\n      \"screenPageViews\": \"999999\"\n    }\n  }\n}\n\n```\n\n### `usePopular` and `useTrending` composables\n\nProvides the specific data from the analyticsData object\n\n```ts\nconst allPopular = await usePopular()\nconst allTrending = await useTrending()\n```\n\n### `usePagePopular` and `usePageTrending` composables\n\nReturns a boolean indicating whether a page is within popular or trending page lists.\nIf no argument is supplied it uses the current route path.\n\n```vue\n\u003ctemplate\u003e\n  \u003cnav\u003e\n    \u003cNuxtLink :to=\"/blog\"\u003eBlog\u003cspan v-if=\"trendingBlog\"\u003e 🔥\u003c/span\u003e\u003c/NuxtLink\u003e\n  \u003c/nav\u003e\n\u003c/template\u003e\n\u003cscript lang=\"ts\" setup\u003e\n  const popular = await usePagePopular()\n  const trending = await usePageTrending()\n\n  const popularBlog = await usePagePopular(\"/blog\")\n  const trendingBlog = await usePageTrending(\"/blog\")\n\u003c/script\u003e\n```\n\nThen\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Generate type stubs\nnpm run dev:prepare\n\n# Develop with the playground\nnpm run dev\n\n# Build the playground\nnpm run dev:build\n\n# Run ESLint\nnpm run lint\n\n# Run Vitest\nnpm run test\nnpm run test:watch\n\n# Release new version\nnpm run release\n```\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/nuxt-analytics-data/latest.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n\n[npm-version-href]: https://npmjs.com/package/nuxt-analytics-data\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-analytics-data.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n\n[npm-downloads-href]: https://npmjs.com/package/nuxt-analytics-data\n\n[license-src]: https://img.shields.io/npm/l/nuxt-analytics-data.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n\n[license-href]: https://npmjs.com/package/nuxt-analytics-data\n\n[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js\n\n[nuxt-href]: https://nuxt.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl422y%2Fnuxt-analytics-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl422y%2Fnuxt-analytics-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl422y%2Fnuxt-analytics-data/lists"}