{"id":14970788,"url":"https://github.com/yjl9903/unplugin-analytics","last_synced_at":"2025-10-26T13:31:21.071Z","repository":{"id":224759192,"uuid":"763925589","full_name":"yjl9903/unplugin-analytics","owner":"yjl9903","description":"Universal Analytics Engines Integration","archived":false,"fork":false,"pushed_at":"2025-09-25T16:57:36.000Z","size":2290,"stargazers_count":5,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-14T21:29:06.786Z","etag":null,"topics":["analytics","astro","astro-integration","google-analytics","plausible","umami","unplugin","vite","vite-plugin","webpack"],"latest_commit_sha":null,"homepage":"https://unplugin-analytics.pages.dev/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yjl9903.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null},"funding":{"github":["yjl9903"]}},"created_at":"2024-02-27T06:53:57.000Z","updated_at":"2025-04-21T16:43:23.000Z","dependencies_parsed_at":"2024-11-11T05:26:15.030Z","dependency_job_id":"d637f2c8-95e8-4491-a96a-c7237b93dcab","html_url":"https://github.com/yjl9903/unplugin-analytics","commit_stats":{"total_commits":357,"total_committers":3,"mean_commits":119.0,"dds":0.2184873949579832,"last_synced_commit":"05836be7e5aff3ef4dbefab80d8a20394e43c2b1"},"previous_names":["yjl9903/unplugin-analytics"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/yjl9903/unplugin-analytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjl9903%2Funplugin-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjl9903%2Funplugin-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjl9903%2Funplugin-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjl9903%2Funplugin-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjl9903","download_url":"https://codeload.github.com/yjl9903/unplugin-analytics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjl9903%2Funplugin-analytics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280776478,"owners_count":26388950,"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","status":"online","status_checked_at":"2025-10-24T02:00:06.418Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["analytics","astro","astro-integration","google-analytics","plausible","umami","unplugin","vite","vite-plugin","webpack"],"created_at":"2024-09-24T13:44:09.055Z","updated_at":"2025-10-26T13:31:20.519Z","avatar_url":"https://github.com/yjl9903.png","language":"TypeScript","readme":"# unplugin-analytics\n\n[![version](https://img.shields.io/npm/v/unplugin-analytics?label=unplugin-analytics)](https://www.npmjs.com/package/unplugin-analytics)\n[![GitHub License](https://img.shields.io/github/license/yjl9903/unplugin-analytics)](https://github.com/yjl9903/unplugin-analytics/blob/main/LICENSE)\n[![CI](https://github.com/yjl9903/unplugin-analytics/actions/workflows/ci.yml/badge.svg)](https://github.com/yjl9903/unplugin-analytics/actions/workflows/ci.yml)\n\n\u003e 👷‍♂️ Still work in progress.\n\u003e\n\u003e 🤩 PR Welcome! Hope more bundler / framework / analytics engines to be supported.\n\nUniversal Analytics Engines Integration.\n\nSupport analytics engines:\n\n- [Umami](https://umami.is/)\n- [Plausible](https://plausible.io/)\n- [Cloudflare Web Analytics](https://www.cloudflare.com/web-analytics/)\n- [Microsoft Clarity](https://clarity.microsoft.com/)\n\n## Installation\n\n```bash\nnpm i -D unplugin-analytics\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eVite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vite.config.ts\n\nimport Analytics from 'unplugin-analytics/vite';\n\nexport default defineConfig({\n  plugins: [\n    Analytics({\n      analytics: {\n        cloudflare: {\n          beacon: '...'\n        },\n        // Your unplugin-analytics options ...\n      }\n    })\n  ]\n});\n```\n\nFull example is located at [examples/vite](https://github.com/yjl9903/unplugin-analytics/blob/main/examples/vite).\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVitePress\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// .vitepress/config.ts\n\nimport { defineConfig } from 'vitepress';\n\nimport { injectScriptTags } from 'unplugin-analytics/vitepress';\n\nexport default defineConfig({\n  async transformHead(context) {\n    // Add the following code\n    injectScriptTags({\n      cloudflare: {\n        beacon: '...'\n      },\n      // Your unplugin-analytics options ...\n    })(context);\n  },\n});\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eAstro\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// astro.config.mjs\n\nimport Analytics from 'unplugin-analytics/astro';\n\nexport default defineConfig({\n  integrations: [\n    Analytics({\n      analytics: {\n        cloudflare: {\n          beacon: '...'\n        },\n        // Your unplugin-analytics options ...\n      }\n    })\n  ],\n});\n```\n\nThen add the astro component made of injected scripts to your layouts.\n\n```astro\n---\n// src/layouts/Layout.astro\n\nimport Analytics from '~analytics/scripts.astro'\n\n// ...\n---\n\n\u003c!doctype html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003cmeta name=\"description\" content=\"Astro description\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width\" /\u003e\n    \u003clink rel=\"icon\" type=\"image/svg+xml\" href=\"/favicon.svg\" /\u003e\n\n    \u003c!-- Inject the scripts begin --\u003e\n    \u003cAnalytics /\u003e\n    \u003c!-- Inject the scripts end --\u003e\n\n    \u003cmeta name=\"generator\" content={Astro.generator} /\u003e\n    \u003c!-- ... --\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c!-- ... --\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nTo make the TypeScript work, you can add `unplugin-analytics/client` to your corresponding `tsconfig.json`.\n\n```json5\n{\n  \"compilerOptions\": {\n    // ...\n    \"types\": [\n      \"unplugin-analytics/client\"\n    ],\n  },\n  // ...\n}\n```\n\nOr you can add TypeScript [triple-slash directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) to your `.d.ts` (i.e. for projects initialized by Vite, it may be `src/env.d.ts`).\n\n```ts\n// Your .d.ts file\n\n/// \u003creference types=\"unplugin-analytics/client\" /\u003e\n```\n\nFull example is located at [examples/astro](https://github.com/yjl9903/unplugin-analytics/blob/main/examples/astro).\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eNuxt\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// nuxt.config.ts\n\nexport default defineNuxtConfig({\n  modules: ['unplugin-analytics/nuxt'],\n  analytics: {\n    cloudflare: {\n      beacon: '...'\n    },\n    // Your unplugin-analytics options ...\n  }\n});\n```\n\nFull example is located at [examples/nuxt](https://github.com/yjl9903/unplugin-analytics/blob/main/examples/nuxt).\n\n\u003cbr\u003e\u003c/details\u003e\n\n## Usage\n\nTaking Vite as an example, you can config the analytics engines.\n\n```ts\n// vite.config.ts\n\nimport Analytics from 'unplugin-analytics/vite';\n\nexport default defineConfig({\n  plugins: [\n    Analytics({\n      analytics: {\n        umami: {\n          src: `...`,\n          id: `...`\n        },\n        plausible: {\n          domain: `...`\n        },\n        cloudflare: {\n          beacon: `...`\n        },\n        clarity: {\n          id: `...`\n        }\n      }\n    })\n  ]\n});\n```\n\n### Umami\n\n**Provider key**: `umami`\n\n**Parameters**:\n\n- `src`: Your umami script url or the host\n- `id`: Your umami website id\n\nGenerated script:\n\n```html\n\u003cscript defer data-website-id=\"...\" src=\"https://umami.is/script.js\"\u003e\u003c/script\u003e\n```\n\nYou can use umami tracker function like:\n\n```ts\nimport { umami } from '~analytics/umami';\n\ndocument.querySelector('.umami')?.addEventListener('click', () =\u003e {\n  // Track events\n  umami?.track('click umami button');\n});\n```\n\n### Plausible\n\n**Provider key**: `plausible`\n\n**Parameters**:\n\n- `src`: Your plausible script url or the host\n- `id`: Your website domain\n\nGenerated script:\n\n```html\n\u003cscript defer data-domain=\"...\" src=\"https://plausible.io/js/script.js\"\u003e\u003c/script\u003e\n```\n\n### Cloudflare Web Analytics\n\n**Provider key**: `cloudflare`\n\n**Parameters**:\n\n- `beacon`: Your cloudflare web analytics beacon\n\nGenerated script:\n\n```html\n\u003cscript defer data-cf-beacon=\"{\u0026quot;token\u0026quot;: \u0026quot;...\u0026quot;}\" src=\"https://static.cloudflareinsights.com/beacon.min.js\"\u003e\u003c/script\u003e\n```\n\n### Microsoft Clarity\n\n**Provider key**: `clarity`\n\n**Parameters**:\n\n- `id`: Your clarity project id\n\nGenerated script:\n\n```html\n\u003cscript\u003e(function(c,l,a,r,i,t,y){\n  c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};\n  t=l.createElement(r);t.async=1;t.src=\"https://www.clarity.ms/tag/\"+i;\n  y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);\n})(window, document, \"clarity\", \"script\", \"...\");\u003c/script\u003e\n```\n\n## License\n\nMIT License © 2024 [XLor](https://github.com/yjl9903)\n","funding_links":["https://github.com/sponsors/yjl9903"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjl9903%2Funplugin-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjl9903%2Funplugin-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjl9903%2Funplugin-analytics/lists"}