Skip to content

Commit bf33b00

Browse files
authored
Merge pull request #433 from NLeSC/matomo_plugin
use the matomo plugin, but customized
2 parents 594b250 + 05b1c4b commit bf33b00

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

index.html

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<link rel="stylesheet" href="/styles.css" />
1717
<link rel="icon" type="image/png" href="images/favicon.png" />
1818
<!-- Matomo -->
19-
<script>
19+
<!-- <script>
2020
var _paq = (window._paq = window._paq || []);
2121
_paq.push(["disableCookies"]); // Call disableCookies before calling trackPageView
2222
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
@@ -38,7 +38,7 @@
3838
_paq.push(["setDocumentTitle", document.title]);
3939
_paq.push(["trackPageView"]);
4040
});
41-
</script>
41+
</script> -->
4242
<!-- End Matomo Code -->
4343
</head>
4444

@@ -54,11 +54,62 @@
5454
"/.*/_sidebar.md": "/_sidebar.md",
5555
},
5656
relativePath: true,
57+
matomo: {
58+
host: "//matomo.research.software",
59+
id: 5,
60+
disableCookies: true,
61+
},
5762
};
5863
</script>
5964
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
6065
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/external-script.min.js"></script>
6166
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
6267
<script src="https://cdn.jsdelivr.net/npm/prismjs/components/prism-bash.min.js"></script>
68+
<!-- custom version of Matomo plugin, modified from https://github.com/docsifyjs/docsify/blob/develop/src/plugins/matomo.js -->
69+
<script>
70+
function appendScript(options) {
71+
const script = document.createElement("script");
72+
script.async = true;
73+
script.src = options.host + "/matomo.js";
74+
document.body.appendChild(script);
75+
}
76+
77+
function init(options) {
78+
window._paq = window._paq || [];
79+
if (options.disableCookies) {
80+
window._paq.push(["disableCookies"]); // Call disableCookies before calling trackPageView
81+
}
82+
// window._paq.push(["trackPageView"]);
83+
window._paq.push(["enableLinkTracking"]);
84+
setTimeout(() => {
85+
appendScript(options);
86+
window._paq.push(["setTrackerUrl", options.host + "/matomo.php"]);
87+
window._paq.push(["setSiteId", String(options.id)]);
88+
}, 0);
89+
}
90+
91+
function collect() {
92+
if (!window._paq) {
93+
init($docsify.matomo);
94+
}
95+
96+
window._paq.push(["setCustomUrl", "/" + window.location.hash]);
97+
window._paq.push(["setDocumentTitle", document.title]);
98+
window._paq.push(["trackPageView"]);
99+
}
100+
101+
const install = function (hook) {
102+
if (!$docsify.matomo) {
103+
// eslint-disable-next-line no-console
104+
console.error("[Docsify] matomo is required.");
105+
return;
106+
}
107+
108+
hook.doneEach(collect);
109+
};
110+
111+
window.$docsify = window.$docsify || {};
112+
$docsify.plugins = [install, ...($docsify.plugins || [])];
113+
</script>
63114
</body>
64115
</html>

0 commit comments

Comments
 (0)