Skip to content

Commit

Permalink
feat: add push property to Matomo tracking to allow passing of any tr…
Browse files Browse the repository at this point in the history
…ackable thingy to matomo
  • Loading branch information
axe312ger committed Sep 19, 2024
1 parent 6541f0d commit 3edd595
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-donkeys-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@consent-manager/integration-matomo": minor
---

Enable JS error tracking in Matomo by default. Also adds a feature that lets devs enable any Matomo feature via Consent Manager"
16 changes: 16 additions & 0 deletions packages/integration-matomo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface MatomoTrackerConfig extends IntegrationConfigOptions {
enableLinkTracking?: boolean
enableHeartBeatTimer?: boolean
enableJSErrorTracking?: boolean
push?: string[][]
}

let wasInitialized = false
Expand All @@ -42,6 +43,7 @@ interface TrackPageViewSPA {
enableLinkTracking?: boolean
enableHeartBeatTimer?: boolean
enableJSErrorTracking?: boolean
push?: string[][]
}

const trackPageViewSPA = ({
Expand All @@ -50,6 +52,7 @@ const trackPageViewSPA = ({
enableLinkTracking = true,
enableHeartBeatTimer = true,
enableJSErrorTracking = true,
push = [],
}: TrackPageViewSPA): TrackedPageData | null => {
const paq = window._paq
if (!paq) {
Expand All @@ -72,6 +75,12 @@ const trackPageViewSPA = ({

paq.push(['trackAllContentImpressions'])

if (push.length) {
for (const pushValue of push) {
paq.push(pushValue)
}
}

return { url, title }
}

Expand All @@ -97,6 +106,7 @@ export const useMatomoTracker = ({
enableLinkTracking = true,
enableHeartBeatTimer = true,
enableJSErrorTracking = true,
push = [],
}: MatomoTrackerConfig): Tracker => {
const [isEnabled] = useDecision('matomo')

Expand All @@ -110,6 +120,12 @@ export const useMatomoTracker = ({
_paq.push(['setTrackerUrl', `${matomoURL}matomo.php`])
_paq.push(['setSiteId', siteID])

if (push.length) {
for (const pushValue of push) {
_paq.push(pushValue)
}
}

const script = document.createElement('script')

script.src = `${matomoURL}matomo.js`
Expand Down

0 comments on commit 3edd595

Please sign in to comment.