提交 397d01a5 编写于 作者: U ULIVZ

feat: init @vuepress/plugin-google-analytics

上级 1c170c22
......@@ -11,31 +11,6 @@ window.__VUEPRESS_VERSION__ = {
hash: LAST_COMMIT_HASH
}
// TODO Separate it into a plugin ('vuepress-plugin-ga')
// Google analytics integration
if (process.env.NODE_ENV === 'production' && GA_ID) {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}
i[r].l = 1 * new Date()
a = s.createElement(o)
m = s.getElementsByTagName(o)[0]
a.async = 1
a.src = g
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
ga('create', GA_ID, 'auto')
ga('send', 'pageview')
router.afterEach(function (to) {
ga('set', 'page', to.fullPath)
ga('send', 'pageview')
})
}
router.onReady(() => {
app.$mount('#app')
......
......@@ -278,7 +278,6 @@ module.exports = function createBaseConfig ({
.plugin('injections')
.use(require('webpack/lib/DefinePlugin'), [{
BASE_URL: JSON.stringify(siteConfig.base || '/'),
GA_ID: siteConfig.ga ? JSON.stringify(siteConfig.ga) : false,
SW_ENABLED: !!siteConfig.serviceWorker,
VUEPRESS_VERSION: JSON.stringify(require('../../package.json').version),
LAST_COMMIT_HASH: JSON.stringify(getLastCommitHash())
......
__tests__
__mocks__
\ No newline at end of file
# @vuepress/plugin-google-analytics
> google-analytics plugin for vuepress
## Options
const path = require('path')
module.exports = (options = {}, context) => ({
name: 'google-analytics',
ready () {
const { siteConfig = {}} = context
const ga = options.ga || siteConfig.ga
context.GA_ID = ga ? JSON.stringify(ga) : false
},
chainWebpack (config) {
config.plugin('injections').tap(([options]) => [
Object.assign(options, {
GA_ID: context.GA_ID
})
])
},
enhanceAppFiles: [
path.resolve(__dirname, 'inject.js')
]
})
/* global GA_ID, ga */
export default ({ router }) => {
// Google analytics integration
if (process.env.NODE_ENV === 'production' && GA_ID) {
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}
i[r].l = 1 * new Date()
a = s.createElement(o)
m = s.getElementsByTagName(o)[0]
a.async = 1
a.src = g
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
ga('create', GA_ID, 'auto')
ga('send', 'pageview')
router.afterEach(function (to) {
ga('set', 'page', to.fullPath)
ga('send', 'pageview')
})
}
}
{
"name": "@vuepress/plugin-google-analytics",
"version": "1.0.0",
"description": "google-analytics plugin for vuepress",
"main": "index.js",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/vuepress.git"
},
"keywords": [
"documentation",
"vue",
"vuepress",
"generator"
],
"author": "Evan You",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/vuepress/issues"
},
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-google-analytics#readme"
}
\ No newline at end of file
const path = require('path')
const themePlugin = require('./plugin')
const activeHeaderLinksPlugin = require('@vuepress/plugin-active-header-links')
const googleAnalyticsPlugin = require('@vuepress/plugin-google-analytics')
// Theme API.
module.exports = {
......@@ -8,6 +9,7 @@ module.exports = {
notFound: path.resolve(__dirname, 'src/NotFound.vue'),
plugins: [
themePlugin,
activeHeaderLinksPlugin
activeHeaderLinksPlugin,
googleAnalyticsPlugin
]
}
......@@ -24,6 +24,7 @@
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/theme-default#readme",
"dependencies": {
"@vuepress/plugin-active-header-links": "1.0.0",
"@vuepress/plugin-google-analytics": "1.0.0",
"docsearch.js": "^2.5.2",
"nprogress": "^0.2.0",
"stylus": "^0.54.5",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册