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

Conversation

OzakIOne
Copy link
Contributor

@OzakIOne OzakIOne commented Jan 2, 2024

Motivation

This plugin adds support for Vercel Web Analytics.

You should only use this plugin if you use Vercel to host Docusaurus (which is a good option).

You are only supposed to use this plugin at most once per Docusaurus site, so it is not allowed to use multiple instances of this plugin. We reject the usage of a custom plugin id.

Plugin documentation: https://deploy-preview-9687--docusaurus-2.netlify.app/docs/api/plugins/@docusaurus/plugin-vercel-analytics/

This plugin only exposes the mode and debug options.

Building your site with docusaurus build --dev will turn on development env and debug mode automatically.

Other options are not supported for now, but we'll consider adding support for them.

Please let us know if you need them and we'll try to add support later.

Test Plan

Unit tests

The Docusaurus website does not use Vercel, so we cannot dogfood this on our own website.

However, maintainer @slorber uses it on his newsletter website ThisWeekInReact.com and it works fine:

CleanShot 2024-02-14 at 13 21 42

Test links

https://deploy-preview-9687--docusaurus-2.netlify.app/

Related issues/PRs

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 2, 2024
Copy link

github-actions bot commented Jan 2, 2024

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 74 🟢 98 🟢 96 🟢 100 🟠 88 Report
/docs/installation 🟠 69 🟢 96 🟢 100 🟢 100 🟠 88 Report
/docs/category/getting-started 🟠 75 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog 🟠 71 🟢 100 🟢 100 🟢 90 🟠 88 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 64 🟢 96 🟢 100 🟢 100 🟠 88 Report
/blog/tags/release 🟠 71 🟢 100 🟢 100 🟠 80 🟠 88 Report
/blog/tags 🟠 76 🟢 100 🟢 100 🟢 90 🟠 88 Report

Copy link

netlify bot commented Jan 4, 2024

[V2]

Name Link
🔨 Latest commit 42bb53b
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/65cca8ca61820300087be646
😎 Deploy Preview https://deploy-preview-9687--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

packages/docusaurus-preset-classic/package.json Outdated Show resolved Hide resolved
packages/docusaurus-preset-classic/src/index.ts Outdated Show resolved Hide resolved
packages/docusaurus-preset-classic/src/index.ts Outdated Show resolved Hide resolved
packages/docusaurus-preset-classic/src/options.ts Outdated Show resolved Hide resolved
packages/docusaurus-plugin-vercel-analytics/README.md Outdated Show resolved Hide resolved
Comment on lines 7 to 9
TODO: add documentation

See [plugin-vercel-analytics documentation]().
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need plugin docs

@OzakIOne OzakIOne requested a review from slorber January 5, 2024 15:32
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed before merge:

  • little refactors, see inline comments
  • docs
  • options validation + unit tests
  • forbid usage of pluginId !== "default" with clear error message

@slorber slorber added pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 5, 2024
@OzakIOne OzakIOne requested a review from slorber January 5, 2024 17:52
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That almost looks good to merge

export type Options = Partial<PluginOptions>;

export const DEFAULT_OPTIONS: Partial<PluginOptions> = {
mode: 'production',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think undefined ("auto") makes more sense as a default

For example docusaurus build --dev builds the site with node env "development" and we probably want it to impact the vercel plugin env in that case.

See also:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean with undefined ("auto") but I changed the default value to auto which makes more sense


export const DEFAULT_OPTIONS: Partial<PluginOptions> = {
mode: 'production',
debug: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also use undefined?

https://vercel.com/docs/analytics/package#debug

This option is automatically enabled if the NODE_ENV environment variable is available and either development or test.

Similarly I think using docusaurus build --dev should turn this plugin to debug mode

Copy link
Contributor Author

@OzakIOne OzakIOne Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, didn't understand the use of undefined however modified according to your comment

website/docs/api/plugins/plugin-vercel-analytics.mdx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior. to backport This PR is planned to be backported to a stable version of Docusaurus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants