forked from docsifyjs/docsify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathga.js
39 lines (32 loc) · 819 Bytes
/
ga.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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) {
let ga = window.ga
if (!ga) {
appendScript()
ga = ga || function () {
(ga.q = ga.q || []).push(arguments)
}
ga.l = Number(new Date())
ga('create', id, 'auto')
}
return ga
}
function collect () {
const ga = init($docsify.ga)
ga('set', 'page', location.hash)
ga('send', 'pageview')
}
const install = function (hook) {
if (!$docsify.ga) {
console.error('[Docsify] ga is required.')
return
}
hook.beforeEach(collect)
}
$docsify.plugins = [].concat(install, $docsify.plugins)