Use Google Analytics with your site
Docusaurus support Google Analytics with tow plugin plugin-google-analytics
and plugin-google-gtag
(recommend!).It can measure how users interact with your website
note
plugin-google-analytics
is deprecated, and will become useless on July 1, 2023.
UA-*
tracking id will also be removed and change to G-*
id.
step1: install plugin
yarn add @docusaurus/plugin-google-analytics @docusaurus/plugin-google-gtag
make sure the version is the same as your Docusaurus
and add the following code to your docusaurus.config.js
file.
docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
googleAnalytics: {
trackingID: '**********',
anonymizeIP: true,
},
gtag: {
trackingID: 'G-**********',
anonymizeIP: true,
},
},
],
],
};
step2: create a new Google Analytics
Go to Google Analytics and select Go to stream setup
. Then create a new property for collecting data.
Entre your sites URL and the name, google will automatically generate the id.
step3: find your tracking id
The measurement id is for gtag
plugin and the property id is for analytics
.
Finally, you can view your site analysis results on the page!