-
Notifications
You must be signed in to change notification settings - Fork 17
First draft of Matomo analytics #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for elaborate-kangaroo-25e1ee ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Signed-off-by: Jess Chitas <[email protected]>
- Replace page-specific Matomo component with global client module - Analytics runs on all pages automatically via clientModules - Restrict analytics to localhost and Netlify preview deployments only - Use site ID 6 for all environments - Support SPA navigation tracking for page views Signed-off-by: Pete Cheslock <[email protected]>
- Simplified the analytics initialization process by consolidating logic into `resolveMatomoSiteId` and `ensureMatomoInitialized` functions. - Updated site ID resolution to support different environments (localhost, Netlify, production). - Enhanced SPA navigation tracking by ensuring page views are tracked on route updates. - Removed unnecessary checks and streamlined the code for better readability and maintainability. Signed-off-by: Pete Cheslock <[email protected]>
Signed-off-by: Pete Cheslock <[email protected]>
1bb3bf5
to
38678a7
Compare
…ance analytics tracking - Enhanced analytics tracking for same-page anchor clicks to improve user interaction insights. - Updated footer social links to use a new structure with improved accessibility and styling. - Move footer image links to existing images in repo - Cleaned up unused code and comments in the configuration file. Signed-off-by: Pete Cheslock <[email protected]>
- Enhanced analytics tracking for same-page anchor clicks to prevent double-counting. - Improved the initialization of analytics and anchor tracking on page load. - Added new dependencies for Babel and Jest to improve testing and build processes. Signed-off-by: Pete Cheslock <[email protected]>
38678a7
to
de6bcc4
Compare
This one looks a little complex, but mostly its the challenge of capturing analytics from "single page sites". Hopefully the AI assisted PR description explains why this is, and how the code works. I've confirmed on the Matomo instance that we are only capturing anonymous page views counts, and most importantly we can see links to the anchor pages which is helpful to know where on a page folks are being directed to. ![]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Here’s how the global
analytics.js
client module tracks pageviews and anchors reliably across the site.NOTE: An SPA (Single Page Application) loads once and swaps content with JavaScript, so URL changes don’t reload the page. Because there are no full reloads, analytics won’t auto-record pageviews or anchor jumps—you must send them manually. Our client module does exactly that for route changes and same-page anchors, and dedupes them so each action counts once.
1. Registration in Docusaurus config
2. Client-side only
3. Environment-aware site selection
6
7
4. One-time Matomo initialization
disableCookies
alwaysUseSendBeacon
enableLinkTracking
setTrackerUrl('//analytics.ossupstream.org/matomo.php')
setSiteId(siteId)
matomo.js
asynchronously5. SPA navigation tracking (Docusaurus lifecycle)
onRouteDidUpdate({ location, previousLocation })
to track:setReferrerUrl
(when available)setCustomUrl
(includes hash if present)setDocumentTitle
(anchor-enhanced title)trackPageView
6. Same-page anchor tracking (virtual pageviews)
pathname#hash
Base Title - anchor
7. Title stability
getBaseTitle()
trims a single trailing" - section"
to avoid compounding titles across multiple anchor clicks.8. Robustness
9. Tests (Jest + jsdom)