Implement automatic event tracking for common user interactions (e.g. buttons, links, CTAs) using Matomo’s JavaScript tracking API—without requiring any manual input from content authors.
The matomo script is for now, implemented manually from the script section. We may add a dedicated options page, where this function may be controlled instead. Fields for entering a matomo id etc.
Scope
Implementation Requirements
-
Event Binding Strategy
- Use delegated event listeners (e.g.
document.addEventListener('click', ...))
- Avoid per-component JS initialization
- Ensure compatibility with dynamically injected DOM (AJAX, React, etc.)
-
Matomo Tracking Integration
- Use
_paq.push(['trackEvent', category, action, name, value])
- Follow Matomo’s event tracking model:
- Category:
UI Interaction
- Action:
Click
- Name: Derived from:
aria-label, title, or
innerText fallback
- Value: Optional (omit unless meaningful)
-
Automatic Attribute Injection (Optional Enhancement)
- On DOM ready, normalize elements by adding:
data-matomo-category
data-matomo-action
data-matomo-name
- These should be overridable if explicitly set
-
Component-Level Support
- Integrate into base components in the design system:
- Button component
- Link component
- Ensure consistency across server-rendered and JS-rendered elements
-
Accessibility Considerations
- Ensure labels derived for tracking do not conflict with accessibility
- Prefer
aria-label over visual text when available
Implement automatic event tracking for common user interactions (e.g. buttons, links, CTAs) using Matomo’s JavaScript tracking API—without requiring any manual input from content authors.
The matomo script is for now, implemented manually from the script section. We may add a dedicated options page, where this function may be controlled instead. Fields for entering a matomo id etc.
Scope
Add automatic tracking to:
<button>elements<a>elements styled as buttons (e.g..btn,.c-button)Tracking should:
Implementation Requirements
Event Binding Strategy
document.addEventListener('click', ...))Matomo Tracking Integration
_paq.push(['trackEvent', category, action, name, value])UI InteractionClickaria-label,title, orinnerTextfallbackAutomatic Attribute Injection (Optional Enhancement)
data-matomo-categorydata-matomo-actiondata-matomo-nameComponent-Level Support
Accessibility Considerations
aria-labelover visual text when available