Skip to content

Commit

Permalink
feat: add js error tracking to Matomo and enable it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Sep 19, 2024
1 parent 3528668 commit 6541f0d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/integration-matomo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface MatomoTrackerConfig extends IntegrationConfigOptions {
siteID?: string // @todo this should be required
enableLinkTracking?: boolean
enableHeartBeatTimer?: boolean
enableJSErrorTracking?: boolean
}

let wasInitialized = false
Expand All @@ -38,11 +39,17 @@ interface TrackedPageData {
interface TrackPageViewSPA {
location: Location
prevLocation?: Location
enableLinkTracking?: boolean
enableHeartBeatTimer?: boolean
enableJSErrorTracking?: boolean
}

const trackPageViewSPA = ({
location,
prevLocation,
enableLinkTracking = true,
enableHeartBeatTimer = true,
enableJSErrorTracking = true,
}: TrackPageViewSPA): TrackedPageData | null => {
const paq = window._paq
if (!paq) {
Expand All @@ -58,7 +65,11 @@ const trackPageViewSPA = ({
paq.push(['setCustomUrl', url])
paq.push(['setDocumentTitle', title])
paq.push(['trackPageView'])
paq.push(['enableLinkTracking'])

enableLinkTracking && paq.push(['enableLinkTracking'])
enableHeartBeatTimer && paq.push(['enableHeartBeatTimer'])
enableJSErrorTracking && paq.push(['enableJSErrorTracking'])

paq.push(['trackAllContentImpressions'])

return { url, title }
Expand All @@ -85,6 +96,7 @@ export const useMatomoTracker = ({
// @todo these might need to be in config, but outside of react due to route update hooks
enableLinkTracking = true,
enableHeartBeatTimer = true,
enableJSErrorTracking = true,
}: MatomoTrackerConfig): Tracker => {
const [isEnabled] = useDecision('matomo')

Expand All @@ -93,6 +105,8 @@ export const useMatomoTracker = ({

enableLinkTracking && _paq.push(['enableLinkTracking'])
enableHeartBeatTimer && _paq.push(['enableHeartBeatTimer'])
enableJSErrorTracking && _paq.push(['enableJSErrorTracking'])

_paq.push(['setTrackerUrl', `${matomoURL}matomo.php`])
_paq.push(['setSiteId', siteID])

Expand Down

0 comments on commit 6541f0d

Please sign in to comment.