From b68fae82b01b0517409ea89e6ed416e8a2978b03 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Fri, 29 Nov 2024 12:28:11 +0100 Subject: [PATCH 1/4] fix matomo analytics --- docusaurus.config.js | 5 ++++- static/js/matomo.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 static/js/matomo.js diff --git a/docusaurus.config.js b/docusaurus.config.js index 09cb7bff..24b42676 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -229,7 +229,10 @@ const config = { }, }, themes: ["docusaurus-json-schema-plugin", "mdx-v2"], - scripts: ["/js/store-query-parameter.js"], + scripts: ["/js/store-query-parameter.js", { + src: 'js/matomo.js', + async: false, + }], }; module.exports = config; diff --git a/static/js/matomo.js b/static/js/matomo.js new file mode 100644 index 00000000..32f6e4e5 --- /dev/null +++ b/static/js/matomo.js @@ -0,0 +1,17 @@ + +var _paq = window._paq = window._paq || []; +/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ +_paq.push(["setDocumentTitle", document.domain + "/" + document.title]); +_paq.push(["setCookieDomain", "*.restate.dev"]); +_paq.push(["setDoNotTrack", true]); +_paq.push(["disableCookies"]); +_paq.push(['trackPageView']); +_paq.push(['enableLinkTracking']); +(function() { + var u="https://restatedev.matomo.cloud/"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', '1']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.async=true; g.src='https://cdn.matomo.cloud/restatedev.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s); +})(); + From a7511d223034d16dbb70d2a4f3366f338c3dde45 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Fri, 29 Nov 2024 12:42:39 +0100 Subject: [PATCH 2/4] add subdomains outlink tracking across website and docs --- static/js/matomo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/js/matomo.js b/static/js/matomo.js index 32f6e4e5..2d4c22fd 100644 --- a/static/js/matomo.js +++ b/static/js/matomo.js @@ -3,6 +3,7 @@ var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDocumentTitle", document.domain + "/" + document.title]); _paq.push(["setCookieDomain", "*.restate.dev"]); +_paq.push(["setDomains", "*.restate.dev"]); _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); From 74f921b689780fcceebe46a309fb8b2362710993 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Fri, 29 Nov 2024 13:10:14 +0100 Subject: [PATCH 3/4] Add client module for matomo --- docusaurus.config.js | 6 ++---- matomo.js | 30 ++++++++++++++++++++++++++++++ static/js/matomo.js | 18 ------------------ 3 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 matomo.js delete mode 100644 static/js/matomo.js diff --git a/docusaurus.config.js b/docusaurus.config.js index 24b42676..bfa522ff 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -56,6 +56,8 @@ const config = { locales: ["en"], }, + clientModules: ['./matomo.js'], + presets: [ [ "classic", @@ -229,10 +231,6 @@ const config = { }, }, themes: ["docusaurus-json-schema-plugin", "mdx-v2"], - scripts: ["/js/store-query-parameter.js", { - src: 'js/matomo.js', - async: false, - }], }; module.exports = config; diff --git a/matomo.js b/matomo.js new file mode 100644 index 00000000..17247415 --- /dev/null +++ b/matomo.js @@ -0,0 +1,30 @@ +import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; + +export default (function () { + if (!ExecutionEnvironment.canUseDOM) { + return null; + } + + return { + onRouteUpdate({ location }) { + // ----- + var _paq = window._paq = window._paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(["setCustomUrl", location.pathname]); + _paq.push(["setDocumentTitle", document.domain + "/" + document.title]); + _paq.push(["setCookieDomain", "*.restate.dev"]); + _paq.push(["setDomains", "*.restate.dev"]); + _paq.push(["setDoNotTrack", true]); + _paq.push(["disableCookies"]); + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="https://restatedev.matomo.cloud/"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', '1']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.async=true; g.src='https://cdn.matomo.cloud/restatedev.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s); + })(); + }, + }; +})(); \ No newline at end of file diff --git a/static/js/matomo.js b/static/js/matomo.js deleted file mode 100644 index 2d4c22fd..00000000 --- a/static/js/matomo.js +++ /dev/null @@ -1,18 +0,0 @@ - -var _paq = window._paq = window._paq || []; -/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ -_paq.push(["setDocumentTitle", document.domain + "/" + document.title]); -_paq.push(["setCookieDomain", "*.restate.dev"]); -_paq.push(["setDomains", "*.restate.dev"]); -_paq.push(["setDoNotTrack", true]); -_paq.push(["disableCookies"]); -_paq.push(['trackPageView']); -_paq.push(['enableLinkTracking']); -(function() { - var u="https://restatedev.matomo.cloud/"; - _paq.push(['setTrackerUrl', u+'matomo.php']); - _paq.push(['setSiteId', '1']); - var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.async=true; g.src='https://cdn.matomo.cloud/restatedev.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s); -})(); - From 096fb41994b3615b5edbc98d4f8ff29ce47659e5 Mon Sep 17 00:00:00 2001 From: Giselle van Dongen Date: Fri, 29 Nov 2024 13:11:56 +0100 Subject: [PATCH 4/4] Revert removing script query parameters --- docusaurus.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/docusaurus.config.js b/docusaurus.config.js index bfa522ff..2d795564 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -231,6 +231,7 @@ const config = { }, }, themes: ["docusaurus-json-schema-plugin", "mdx-v2"], + scripts: ["/js/store-query-parameter.js"], }; module.exports = config;