Skip to content

Commit a6bc0ea

Browse files
committed
#3414 webpage: try new matomo integration
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent c55c6de commit a6bc0ea

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

webpage/src/.vuepress/client.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import BlogDate from "./components/BlogDate.vue";
2828
import BlogIndex from "./components/BlogIndex.vue";
2929
import ProfileCard from "./components/ProfileCard.vue";
3030

31+
// Import Matomo analytics (replaces vuepress-plugin-matomo)
32+
import { initMatomo } from "./utils/matomo.js";
33+
3134
export default defineClientConfig({
3235
enhance({ app, router, siteData }) {
3336
// Create Vuetify instance with only the components we use
@@ -65,35 +68,8 @@ export default defineClientConfig({
6568
app.component("BlogIndex", BlogIndex);
6669
app.component("ProfileCard", ProfileCard);
6770

68-
// Initialize Matomo Analytics (client-side only)
69-
if (typeof window !== "undefined") {
70-
// Matomo tracking code
71-
window._paq = window._paq || [];
72-
window._paq.push(["trackPageView"]);
73-
window._paq.push(["enableLinkTracking"]);
74-
75-
(function () {
76-
var u = "https://p.bekerle.com/";
77-
window._paq.push(["setTrackerUrl", u + "matomo.php"]);
78-
window._paq.push(["setSiteId", "7"]);
79-
80-
var d = document;
81-
var g = d.createElement("script");
82-
var s = d.getElementsByTagName("script")[0];
83-
g.async = true;
84-
g.src = u + "matomo.js";
85-
s.parentNode.insertBefore(g, s);
86-
})();
87-
88-
// Track page changes on route navigation
89-
router.afterEach((to) => {
90-
if (window._paq) {
91-
window._paq.push(["setCustomUrl", window.location.href]);
92-
window._paq.push(["setDocumentTitle", document.title]);
93-
window._paq.push(["trackPageView"]);
94-
}
95-
});
96-
}
71+
// Initialize Matomo Analytics (replaces vuepress-plugin-matomo)
72+
initMatomo(router);
9773
},
9874
setup() {},
9975
rootComponents: [],
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Matomo Analytics Integration for VuePress 2
3+
*
4+
* This replaces the old vuepress-plugin-matomo plugin.
5+
* Configuration equivalent to:
6+
* {
7+
* siteId: 7,
8+
* trackerUrl: "https://p.bekerle.com/",
9+
* trackerJsFile: "matomo.js"
10+
* }
11+
*/
12+
13+
export const initMatomo = (router) => {
14+
// Only run in browser
15+
if (typeof window === "undefined") return;
16+
17+
// Configuration
18+
const config = {
19+
siteId: 7,
20+
trackerUrl: "https://p.bekerle.com/",
21+
trackerJsFile: "matomo.js",
22+
};
23+
24+
// Initialize Matomo
25+
window._paq = window._paq || [];
26+
window._paq.push(["trackPageView"]);
27+
window._paq.push(["enableLinkTracking"]);
28+
29+
(function () {
30+
const u = config.trackerUrl;
31+
window._paq.push(["setTrackerUrl", u + "matomo.php"]);
32+
window._paq.push(["setSiteId", config.siteId.toString()]);
33+
34+
const d = document;
35+
const g = d.createElement("script");
36+
const s = d.getElementsByTagName("script")[0];
37+
g.async = true;
38+
g.src = u + config.trackerJsFile;
39+
s.parentNode.insertBefore(g, s);
40+
})();
41+
42+
// Track page changes on route navigation (SPA support)
43+
router.afterEach((to) => {
44+
if (window._paq) {
45+
window._paq.push(["setCustomUrl", window.location.href]);
46+
window._paq.push(["setDocumentTitle", document.title]);
47+
window._paq.push(["trackPageView"]);
48+
}
49+
});
50+
};

0 commit comments

Comments
 (0)