Matomo (formerly Piwik) integration with router5.
matomo-router5-plugin
will send tracking data when router5 triggers onTransitionSuccess
. Custom tracking is also available when needed.
There are a lot of tracking features in matomo, here are the default ones for this package.
setDocumentTitle
- 'from' state name as document titlesetReferrerUrl
- 'from' state pathsetCustomUrl
- 'to' state path- outlinks and downloads
- page generation time
- matomo >= 3.0.2
- router5 ^7.0.0 || ^8.0.0
npm install --save matomo-router5-plugin
for additional tracking features, see matomo guide. These features will be tracked along with default tracking features.
import matomoPlugin from "matomo-router5-plugin";
const router = createRouter();
const matomoOptions = {
trackerUrl: "https://matomo.siteurl.com", // Required.
siteId: 1, // Required.
features: [], // Optional, default `[]`. Additional tracking features.
usePiwik: true, // Optional, default `true`. Set to `true` to use `piwik.js` and `piwik.php`; else use `matomo.js` and `matomo.php`.
};
router.usePlugin(matomoPlugin(matomoOptions));
You can pass in a function as tracking feature. The function will be evaluated at time of tracking.
features: [
["setUserId", () => user ? user.name : "Anonymous User"]
]
import { track } from "matomo-router5-plugin";
track({
customUrl: "custom url", // Optional.
referrerUrl: "custom referrer url", // Optional.
documentTitle: "custom doc title", // Optional.
features: [], // Optional. Additional tracking features.
});