Skip to content

Commit

Permalink
refactor(ts): matomo
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 30, 2024
1 parent 031138c commit d70c880
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/scripts/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ declare module "rickshaw" {
const Rickshaw: any
export default Rickshaw
}

interface Window {
/** Matomo action queue */
_paq?: any[]
}

// Type of process.env
namespace NodeJS {
interface ProcessEnv {
ENVIRONMENT: "development" | "staging" | "production"
}
}
9 changes: 6 additions & 3 deletions app/scripts/matomo.js → app/scripts/matomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import settings from "@/settings"

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

if (matomoSettings?.["url"] && matomoSettings?.["site"]) {
if (matomoSettings.url && matomoSettings.site) {
/** Matomo message queue */
var _paq = (window._paq = window._paq || [])
_paq.push(["trackPageView"])
Expand All @@ -24,6 +27,6 @@ if (matomoSettings?.["url"] && matomoSettings?.["site"]) {
g.type = "text/javascript"
g.async = true
g.src = u + "matomo.js"
s.parentNode.insertBefore(g, s)
s.parentNode!.insertBefore(g, s)
})()
}

0 comments on commit d70c880

Please sign in to comment.