You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently, there is no straightforward way to add Google Analytics meta tags to the <head> section in VitePress projects. Manually adding these tags requires additional boilerplate code, which could be automated for better developer experience.
A function like generateGoogleAnalyticsMeta that returns the necessary Google Analytics <script> tags to be included in the config.js head configuration. This function would make it easy to integrate Google Analytics by simply providing the googleAnalyticsID.
Example:
functiongenerateGoogleAnalyticsMeta(googleAnalyticsID){return[['script',{async: '',src: `https://www.googletagmanager.com/gtag/js?id=${googleAnalyticsID}`}],['script',{},`window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${googleAnalyticsID}');`,],];}
Manually adding the Google Analytics meta tags in the config.js file as part of the head configuration. However, this approach is repetitive and error-prone, especially for projects with multiple environments or contributors.
Additional context
This feature would improve developer productivity by simplifying the integration of Google Analytics into VitePress projects. It aligns with the philosophy of VitePress being a lightweight and easy-to-use documentation framework.
Is your feature request related to a problem? Please describe.
Currently, there is no straightforward way to add Google Analytics meta tags to the
<head>
section in VitePress projects. Manually adding these tags requires additional boilerplate code, which could be automated for better developer experience.Important
Additionally, This approach is already used in Next.js: https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#google-analytics
Describe the solution you'd like
A function like
generateGoogleAnalyticsMeta
that returns the necessary Google Analytics<script>
tags to be included in theconfig.js
head configuration. This function would make it easy to integrate Google Analytics by simply providing thegoogleAnalyticsID
.Example:
We can use it like this using spread operator:
Describe alternatives you've considered
Manually adding the Google Analytics meta tags in the
config.js
file as part of thehead
configuration. However, this approach is repetitive and error-prone, especially for projects with multiple environments or contributors.Additional context
This feature would improve developer productivity by simplifying the integration of Google Analytics into VitePress projects. It aligns with the philosophy of VitePress being a lightweight and easy-to-use documentation framework.
Validations
The text was updated successfully, but these errors were encountered: