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 5b1fac9
Showing 1 changed file with 16 additions and 0 deletions.
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 5b1fac9

Please sign in to comment.