Skip to content

Commit d70c880

Browse files
committed
refactor(ts): matomo
1 parent 031138c commit d70c880

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/scripts/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ declare module "rickshaw" {
1919
const Rickshaw: any
2020
export default Rickshaw
2121
}
22+
23+
interface Window {
24+
/** Matomo action queue */
25+
_paq?: any[]
26+
}
27+
28+
// Type of process.env
29+
namespace NodeJS {
30+
interface ProcessEnv {
31+
ENVIRONMENT: "development" | "staging" | "production"
32+
}
33+
}

app/scripts/matomo.js renamed to app/scripts/matomo.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import settings from "@/settings"
66

77
// Allow environment-specific (development/staging/production) settings or fallback to general settings
8-
const matomoSettings = { ...settings["matomo"], ...settings["matomo"]?.[process.env.ENVIRONMENT] }
8+
const matomoSettings = {
9+
...settings.matomo,
10+
...settings.matomo?.[process.env.ENVIRONMENT],
11+
}
912

10-
if (matomoSettings?.["url"] && matomoSettings?.["site"]) {
13+
if (matomoSettings.url && matomoSettings.site) {
1114
/** Matomo message queue */
1215
var _paq = (window._paq = window._paq || [])
1316
_paq.push(["trackPageView"])
@@ -24,6 +27,6 @@ if (matomoSettings?.["url"] && matomoSettings?.["site"]) {
2427
g.type = "text/javascript"
2528
g.async = true
2629
g.src = u + "matomo.js"
27-
s.parentNode.insertBefore(g, s)
30+
s.parentNode!.insertBefore(g, s)
2831
})()
2932
}

0 commit comments

Comments
 (0)