{"id":6100,"date":"2024-06-03T11:49:41","date_gmt":"2024-06-03T03:49:41","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6100"},"modified":"2024-06-03T11:49:44","modified_gmt":"2024-06-03T03:49:44","slug":"docusaurus-%e4%b8%ad%e4%bd%bf%e7%94%a8-google-analytics-%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6100","title":{"rendered":"Docusaurus \u4e2d\u4f7f\u7528 Google Analytics \u63d2\u4ef6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Docusaurus \u4e2d\u4f7f\u7528 Google Analytics \u63d2\u4ef6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8ddf\u8e2a\u7f51\u7ad9\u7684\u8bbf\u95ee\u60c5\u51b5\u548c\u7528\u6237\u884c\u4e3a\u3002\u4ee5\u4e0b\u662f\u914d\u7f6e\u548c\u4f7f\u7528 Google Analytics \u63d2\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u83b7\u53d6 Google Analytics \u8ffd\u8e2a ID<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u4f60\u9700\u8981\u6709\u4e00\u4e2a Google Analytics \u8d26\u53f7\uff0c\u5e76\u4e3a\u4f60\u7684\u7f51\u7ad9\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5c5e\u6027\u6765\u83b7\u53d6\u8ffd\u8e2a ID\uff08\u901a\u5e38\u5f62\u5f0f\u4e3a <code>UA-XXXXXXXXX-X<\/code> \u6216 <code>G-XXXXXXXXXX<\/code>\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b89\u88c5 Docusaurus Google Analytics \u63d2\u4ef6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Docusaurus \u63d0\u4f9b\u4e86\u5b98\u65b9\u7684 Google Analytics \u63d2\u4ef6\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7 npm \u6216 yarn \u5b89\u88c5\u8fd9\u4e2a\u63d2\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install @docusaurus\/plugin-google-gtag\n# \u6216\u8005\nyarn add @docusaurus\/plugin-google-gtag<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u914d\u7f6e\u63d2\u4ef6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f60\u7684 Docusaurus \u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u627e\u5230 <code>docusaurus.config.js<\/code> \u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0 Google Analytics \u63d2\u4ef6\u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module.exports = {\n  \/\/ \u5176\u4ed6\u914d\u7f6e\n  plugins: &#91;\n    &#91;\n      '@docusaurus\/plugin-google-gtag',\n      {\n        trackingID: '\u4f60\u7684\u8ffd\u8e2aID', \/\/ \u66ff\u6362\u4e3a\u4f60\u7684 Google Analytics \u8ffd\u8e2a ID\n        anonymizeIP: true, \/\/ \u53ef\u9009\uff0c\u662f\u5426\u533f\u540d\u5316 IP\n      },\n    ],\n  ],\n  \/\/ \u5176\u4ed6\u914d\u7f6e\n};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u9a8c\u8bc1\u914d\u7f6e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u786e\u4fdd\u6240\u6709\u914d\u7f6e\u5df2\u6b63\u786e\u5b8c\u6210\uff0c\u7136\u540e\u91cd\u65b0\u542f\u52a8\u4f60\u7684 Docusaurus \u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm start\n# \u6216\u8005\nyarn start<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff0c\u786e\u4fdd Google Analytics \u811a\u672c\u5df2\u7ecf\u52a0\u8f7d\u5e76\u53d1\u9001\u4e86\u6570\u636e\u8bf7\u6c42\u3002\u4f60\u53ef\u4ee5\u5728 Google Analytics \u5b9e\u65f6\u62a5\u544a\u4e2d\u67e5\u770b\u662f\u5426\u6709\u6570\u636e\u6d41\u5165\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b8c\u6574\u793a\u4f8b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 <code>docusaurus.config.js<\/code> \u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u62ec\u4e86\u57fa\u672c\u914d\u7f6e\u548c Google Analytics \u63d2\u4ef6\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ docusaurus.config.js\nmodule.exports = {\n  title: '\u6211\u7684\u7f51\u7ad9',\n  tagline: '\u6211\u7684\u9879\u76ee\u63cf\u8ff0',\n  url: 'https:\/\/\u4f60\u7684\u57df\u540d.com',\n  baseUrl: '\/',\n  onBrokenLinks: 'throw',\n  onBrokenMarkdownLinks: 'warn',\n  favicon: 'img\/favicon.ico',\n  organizationName: '\u4f60\u7684GitHub\u7528\u6237\u540d\u6216\u7ec4\u7ec7\u540d', \/\/ \u901a\u5e38\u662fGitHub\u7528\u6237\u540d\n  projectName: '\u4f60\u7684\u9879\u76ee\u540d', \/\/ \u901a\u5e38\u662frepo\u540d\n\n  presets: &#91;\n    &#91;\n      '@docusaurus\/preset-classic',\n      {\n        docs: {\n          sidebarPath: require.resolve('.\/sidebars.js'),\n          editUrl: 'https:\/\/github.com\/\u4f60\u7684GitHub\u7528\u6237\u540d\/\u4f60\u7684\u9879\u76ee\u540d\/edit\/main\/docs\/',\n        },\n        blog: {\n          showReadingTime: true,\n          editUrl: 'https:\/\/github.com\/\u4f60\u7684GitHub\u7528\u6237\u540d\/\u4f60\u7684\u9879\u76ee\u540d\/edit\/main\/blog\/',\n        },\n        theme: {\n          customCss: require.resolve('.\/src\/css\/custom.css'),\n        },\n      },\n    ],\n  ],\n\n  plugins: &#91;\n    &#91;\n      '@docusaurus\/plugin-google-gtag',\n      {\n        trackingID: '\u4f60\u7684\u8ffd\u8e2aID', \/\/ \u66ff\u6362\u4e3a\u4f60\u7684 Google Analytics \u8ffd\u8e2a ID\n        anonymizeIP: true, \/\/ \u53ef\u9009\uff0c\u662f\u5426\u533f\u540d\u5316 IP\n      },\n    ],\n  ],\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u6210\u529f\u5728 Docusaurus \u7f51\u7ad9\u4e2d\u96c6\u6210 Google Analytics \u63d2\u4ef6\uff0c\u5e76\u5f00\u59cb\u8ddf\u8e2a\u8bbf\u95ee\u6570\u636e\u548c\u7528\u6237\u884c\u4e3a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Docusaurus \u4e2d\u4f7f\u7528 Google Analytics \u63d2\u4ef6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8ddf\u8e2a\u7f51\u7ad9\u7684\u8bbf\u95ee\u60c5\u51b5\u548c\u7528\u6237\u884c&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6100\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6100","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6100"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6100\/revisions"}],"predecessor-version":[{"id":6101,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6100\/revisions\/6101"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}