Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac61bb0

Browse filesBrowse files
authored
feat(plugins): add Google Analytics plugin (#66)
1 parent 9605c18 commit ac61bb0
Copy full SHA for ac61bb0

7 files changed

+96-4Lines changed: 96 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGELOG.md‎

Copy file name to clipboardExpand all lines: CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.0
2+
3+
### Features
4+
- Add `Google Analytics` plugin.
5+
16
## 2.1.0
27
### Features
38
- Add search plugin
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1-2Lines changed: 1 addition & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ These open-source projects are using docsify to generate their sites. Pull reque
7676

7777
## Development
7878

79-
### prepare
8079
```bash
8180
npm i && npm run dev
8281
open http://localhost:3000
8382
```
8483

85-
### More Language Highlight
84+
## More Language Highlight
8685

8786
```html
8887
<script src="//unpkg.com/docsify"></script>
Collapse file

‎build/build.js‎

Copy file name to clipboardExpand all lines: build/build.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ isProd && build({
4747
moduleName: 'D.Search',
4848
plugins: [uglify()]
4949
})
50+
build({
51+
entry: 'plugins/ga.js',
52+
output: 'plugins/ga.js',
53+
moduleName: 'D.GA'
54+
})
55+
isProd && build({
56+
entry: 'plugins/ga.js',
57+
output: 'plugins/ga.min.js',
58+
moduleName: 'D.GA',
59+
plugins: [uglify()]
60+
})
Collapse file

‎docs/README.md‎

Copy file name to clipboardExpand all lines: docs/README.md
+18-1Lines changed: 18 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ If a document can have a search, can enhance some user experience. Installing th
468468

469469

470470
```html
471-
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
471+
<script src="//unpkg.com/docsify"></script>
472472
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
473473
```
474474

@@ -495,3 +495,20 @@ window.$docsify = {
495495
}
496496
}
497497
```
498+
499+
### Google Analytics
500+
501+
Install the plugin and configure the track id.
502+
503+
```html
504+
<script src="//unpkg.com/docsify" data-ga="UA-XXXXX-Y"></script>
505+
<script src="//unpkg.com/docsify/lib/plugins/ga.js"></script>
506+
```
507+
508+
or
509+
510+
```js
511+
window.$docsify = {
512+
ga: 'UA-XXXXX-Y'
513+
}
514+
```
Collapse file

‎docs/zh-cn.md‎

Copy file name to clipboardExpand all lines: docs/zh-cn.md
+17Lines changed: 17 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,20 @@ window.$docsify = {
501501
}
502502
}
503503
```
504+
505+
### Google Analytics
506+
507+
安装插件并且配置 track id。
508+
509+
```html
510+
<script src="//unpkg.com/docsify" data-ga="UA-XXXXX-Y"></script>
511+
<script src="//unpkg.com/docsify/lib/plugins/ga.js"></script>
512+
```
513+
514+
或者
515+
516+
```js
517+
window.$docsify = {
518+
ga: 'UA-XXXXX-Y'
519+
}
520+
```
Collapse file

‎src/index.js‎

Copy file name to clipboardExpand all lines: src/index.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const OPTIONS = utils.merge({
1515
auto2top: false,
1616
name: '',
1717
themeColor: '',
18-
nameLink: window.location.pathname
18+
nameLink: window.location.pathname,
19+
ga: ''
1920
}, window.$docsify)
2021
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()
2122

Collapse file

‎src/plugins/ga.js‎

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// From https://github.com/egoist/vue-ga/blob/master/src/index.js
2+
3+
function appendScript () {
4+
const script = document.createElement('script')
5+
script.async = true
6+
script.src = 'https://www.google-analytics.com/analytics.js'
7+
document.body.appendChild(script)
8+
}
9+
10+
function init (id) {
11+
if (!window.ga) {
12+
appendScript()
13+
window.ga = window.ga || function () {
14+
(window.ga.q = window.ga.q || []).push(arguments)
15+
}
16+
window.ga.l = Number(new Date())
17+
window.ga('create', id, 'auto')
18+
}
19+
}
20+
21+
function collect () {
22+
init(window.$docsify.ga)
23+
window.ga('set', 'page', location.href)
24+
window.ga('send', 'pageview')
25+
}
26+
27+
const install = function () {
28+
if (!window.Docsify || !window.Docsify.installed) {
29+
console.error('[Docsify] Please load docsify.js first.')
30+
return
31+
}
32+
33+
if (!window.$docsify.ga) {
34+
console.error('[Docsify] ga is required.')
35+
return
36+
}
37+
38+
collect()
39+
window.$docsify.plugins = [].concat(window.$docsify.plugins, collect)
40+
}
41+
42+
export default install()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.