![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@socialgouv/matomo-next
Advanced tools
Matomo Next
Matomo analytics for Next.js applications
next/router
route changes routeChangeComplete
eventAdd the init
call in your _app.js
:
import React, { useEffect } from "react";
import App from "next/app";
import { init } from "@socialgouv/matomo-next";
const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;
function MyApp({ Component, pageProps }) {
useEffect(() => {
init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID });
}, []);
return <Component {...pageProps} />;
}
export default MyApp;
Will track routes changes by default.
This wont track /login.php
or any url containing ?token=
.
init({
url: MATOMO_URL,
siteId: MATOMO_SITE_ID,
excludeUrlsPatterns: [/^\/login.php/, /\?token=.+/],
});
To disable cookies (for better GDPR compliance) set the disableCookies
flag to true
.
init({
url: MATOMO_URL,
siteId: MATOMO_SITE_ID,
disableCookies: true,
});
import { push } from "@socialgouv/matomo-next";
// track some events
push(["trackEvent", "contact", "click phone"]);
The function has three optional callback properties that allow for custom behavior to be added:
onRouteChangeStart(path: string) => void
: This callback is triggered when the route is about to change with Next Router event routeChangeStart
. It receives the new path as a parameter.
onRouteChangeComplete
: This callback is triggered when the route change is complete with Next Router event routeChangeComplete
. It receives the new path as a parameter.
onInitialization
: This callback is triggered when the function is first initialized. It does not receive any parameters. It could be useful to use it if you want to add parameter to Matomo when the page is render the first time.
init
✓ should create a js tag and initialize (7 ms)
✓ should NOT create events when url is not provided (9 ms)
push
✓ should append data to window._paq (1 ms)
✓ should append dimensions data to window._paq (1 ms)
onInitialization
✓ should work if the surcharge of the operator (1 ms)
router.routeChangeStart event
✓ should setReferrerUrl and setCustomUrl on route change start (1 ms)
✓ should use previousPath as referer on consecutive route change (1 ms)
✓ should work if the surcharge of the operator (3 ms)
router.routeChangeComplete event
✓ should trackPageView with correct title on route change (3 ms)
✓ should use previousPath as referer on consecutive route change (2 ms)
✓ should track route as search in /recherche (1 ms)
✓ should track route as search in /search (2 ms)
✓ should work if the surcharge of the operator (2 ms)
excludeUrlsPatterns
✓ should excluded login.php and token variables (2 ms)
✓ should exclude initial page tracking (3 ms)
✓ should track initial page if not excluded (2 ms)
disableCookies
✓ should NOT append disableCookies to window._paq by default (1 ms)
✓ should append disableCookies to window._paq (1 ms)
FAQs
Matomo Next Matomo analytics for Next.js applications
We found that @socialgouv/matomo-next demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.