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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.0

### Features
- Add `Google Analytics` plugin.

## 2.1.0
### Features
- Add search plugin
Expand Down
3 changes: 1 addition & 2 deletions 3 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ These open-source projects are using docsify to generate their sites. Pull reque

## Development

### prepare
```bash
npm i && npm run dev
open http://localhost:3000
```

### More Language Highlight
## More Language Highlight

```html
<script src="//unpkg.com/docsify"></script>
Expand Down
11 changes: 11 additions & 0 deletions 11 build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ isProd && build({
moduleName: 'D.Search',
plugins: [uglify()]
})
build({
entry: 'plugins/ga.js',
output: 'plugins/ga.js',
moduleName: 'D.GA'
})
isProd && build({
entry: 'plugins/ga.js',
output: 'plugins/ga.min.js',
moduleName: 'D.GA',
plugins: [uglify()]
})
19 changes: 18 additions & 1 deletion 19 docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ If a document can have a search, can enhance some user experience. Installing th


```html
<script src="//unpkg.com/docsify/lib/docsify.js"></script>
<script src="//unpkg.com/docsify"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
```

Expand All @@ -495,3 +495,20 @@ window.$docsify = {
}
}
```

### Google Analytics

Install the plugin and configure the track id.

```html
<script src="//unpkg.com/docsify" data-ga="UA-XXXXX-Y"></script>
<script src="//unpkg.com/docsify/lib/plugins/ga.js"></script>
```

or

```js
window.$docsify = {
ga: 'UA-XXXXX-Y'
}
```
17 changes: 17 additions & 0 deletions 17 docs/zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,20 @@ window.$docsify = {
}
}
```

### Google Analytics

安装插件并且配置 track id。

```html
<script src="//unpkg.com/docsify" data-ga="UA-XXXXX-Y"></script>
<script src="//unpkg.com/docsify/lib/plugins/ga.js"></script>
```

或者

```js
window.$docsify = {
ga: 'UA-XXXXX-Y'
}
```
3 changes: 2 additions & 1 deletion 3 src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const OPTIONS = utils.merge({
auto2top: false,
name: '',
themeColor: '',
nameLink: window.location.pathname
nameLink: window.location.pathname,
ga: ''
}, window.$docsify)
const script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop()

Expand Down
42 changes: 42 additions & 0 deletions 42 src/plugins/ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// From https://github.com/egoist/vue-ga/blob/master/src/index.js

function appendScript () {
const script = document.createElement('script')
script.async = true
script.src = 'https://www.google-analytics.com/analytics.js'
document.body.appendChild(script)
}

function init (id) {
if (!window.ga) {
appendScript()
window.ga = window.ga || function () {
(window.ga.q = window.ga.q || []).push(arguments)
}
window.ga.l = Number(new Date())
window.ga('create', id, 'auto')
}
}

function collect () {
init(window.$docsify.ga)
window.ga('set', 'page', location.href)
window.ga('send', 'pageview')
}

const install = function () {
if (!window.Docsify || !window.Docsify.installed) {
console.error('[Docsify] Please load docsify.js first.')
return
}

if (!window.$docsify.ga) {
console.error('[Docsify] ga is required.')
return
}

collect()
window.$docsify.plugins = [].concat(window.$docsify.plugins, collect)
}

export default install()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.