Skip to content

Commit b93a667

Browse files
committed
provide plugin for matomo
1 parent e8d850c commit b93a667

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
maxLevel: 4,
4545
subMaxLevel: 2,
4646
ga: 'UA-106147152-1',
47+
matomo: {
48+
host: '//matomo.thunderwave.de',
49+
id: 6
50+
},
4751
name: 'docsify',
4852
search: {
4953
noData: {
@@ -84,6 +88,7 @@
8488
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
8589
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
8690
<script src="//unpkg.com/docsify/lib/plugins/ga.min.js"></script>
91+
<script src="//unpkg.com/docsify/lib/plugins/matomo.min.js"></script>
8792
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
8893
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
8994
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>

src/plugins/matomo.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function appendScript(options) {
2+
const script = document.createElement('script')
3+
script.async = true
4+
script.src = options.host + '/matomo.js'
5+
document.body.appendChild(script)
6+
}
7+
8+
function init(options) {
9+
window._paq = window._paq || []
10+
window._paq.push(['trackPageView'])
11+
window._paq.push(['enableLinkTracking'])
12+
setTimeout(function() {
13+
appendScript(options)
14+
window._paq.push(['setTrackerUrl', options.host + '/matomo.php'])
15+
window._paq.push(['setSiteId', options.id + ''])
16+
}, 0)
17+
}
18+
19+
function collect() {
20+
if (!window._paq) {
21+
init($docsify.matomo)
22+
}
23+
window._paq.push(['setCustomUrl', window.location.hash.substr(1)])
24+
window._paq.push(['setDocumentTitle', document.title])
25+
window._paq.push(['trackPageView'])
26+
}
27+
28+
const install = function (hook) {
29+
if (!$docsify.matomo) {
30+
console.error('[Docsify] matomo is required.')
31+
return
32+
}
33+
34+
hook.beforeEach(collect)
35+
}
36+
37+
$docsify.plugins = [].concat(install, $docsify.plugins)

0 commit comments

Comments
 (0)