Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-vercel-analytics): add new vercel analytics plugin #9687

Merged
merged 23 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-vercel-analytics/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `@docusaurus/plugin-vercel-analytics`

Vercel analytics plugin for Docusaurus. [Official documentation](https://vercel.com/docs/analytics)
[Vercel analytics](https://vercel.com/docs/analytics) plugin for Docusaurus.

## Usage

Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-vercel-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@docusaurus/core": "3.0.0",
"@docusaurus/types": "3.0.0",
"@docusaurus/utils-validation": "3.0.0",
"@docusaurus/utils": "3.0.0",
"@vercel/analytics": "^1.1.1",
"tslib": "^2.6.0"
},
Expand Down
12 changes: 9 additions & 3 deletions packages/docusaurus-plugin-vercel-analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {Joi} from '@docusaurus/utils-validation';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import type {
LoadContext,
Plugin,
Expand All @@ -17,17 +18,22 @@ export default function pluginVercelAnalytics(
context: LoadContext,
options: PluginOptions,
): Plugin {
// const isProd = process.env.NODE_ENV === 'production';
const isProd = process.env.NODE_ENV === 'production';

return {
name: 'docusaurus-plugin-vercel-analytics',

getClientModules() {
// return isProd ? ['./analytics'] : [];
return ['./analytics'];
return isProd ? ['./analytics'] : [];
},

contentLoaded({actions}) {
console.log('options:', options);
if (options.id !== DEFAULT_PLUGIN_ID) {
throw new Error(
`You cannot use a custom plugin id option with the Vercel Analytics plugin`,
);
}
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
actions.setGlobalData(options);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

export type PluginOptions = {
id: string;
mode: 'auto' | 'production' | 'development';
debug: boolean;
};
Expand Down