Skip to content

Commit 3be5528

Browse files
committed
#3414 webpage: fix matomo code in client.js
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent f484e0f commit 3be5528

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

webpage/src/.vuepress/client.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ 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-
3431
export default defineClientConfig({
3532
enhance({ app, router, siteData }) {
3633
// Create Vuetify instance with only the components we use
@@ -69,7 +66,43 @@ export default defineClientConfig({
6966
app.component("ProfileCard", ProfileCard);
7067

7168
// Initialize Matomo Analytics (replaces vuepress-plugin-matomo)
72-
initMatomo(router);
69+
// Only run in browser environment
70+
if (typeof window !== "undefined") {
71+
// Configuration
72+
const matomoConfig = {
73+
siteId: 7,
74+
trackerUrl: "https://p.bekerle.com/",
75+
trackerJsFile: "matomo.js",
76+
};
77+
78+
// Initialize Matomo
79+
window._paq = window._paq || [];
80+
window._paq.push(["trackPageView"]);
81+
window._paq.push(["enableLinkTracking"]);
82+
83+
// Load Matomo script
84+
(function () {
85+
const u = matomoConfig.trackerUrl;
86+
window._paq.push(["setTrackerUrl", u + "matomo.php"]);
87+
window._paq.push(["setSiteId", matomoConfig.siteId.toString()]);
88+
89+
const d = document;
90+
const g = d.createElement("script");
91+
const s = d.getElementsByTagName("script")[0];
92+
g.async = true;
93+
g.src = u + matomoConfig.trackerJsFile;
94+
s.parentNode.insertBefore(g, s);
95+
})();
96+
97+
// Track page changes on route navigation (SPA support)
98+
router.afterEach((to) => {
99+
if (window._paq) {
100+
window._paq.push(["setCustomUrl", window.location.href]);
101+
window._paq.push(["setDocumentTitle", document.title]);
102+
window._paq.push(["trackPageView"]);
103+
}
104+
});
105+
}
73106
},
74107
setup() {},
75108
rootComponents: [],

0 commit comments

Comments
 (0)