All Projects → SocialGouv → matomo-next

SocialGouv / matomo-next

Licence: other
Matomo for Next.js applications

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to matomo-next

ip2location-piwik
Use IP2Location geolocation database to lookup for accurate visitor location in Matomo (Piwik) 3.x. It enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address o…
Stars: ✭ 26 (-70.11%)
Mutual labels:  matomo
matomo-mediawiki-extension
www.mediawiki.org/wiki/Extension:Piwik_Integration
Stars: ✭ 18 (-79.31%)
Mutual labels:  matomo
hugo-component-matomo
Matomo user tracking and optout scripts for Hugo
Stars: ✭ 38 (-56.32%)
Mutual labels:  matomo
gatsby-plugin-matomo
🥂 Gatsby plugin to add Matomo (formerly Piwik) onto a site.
Stars: ✭ 56 (-35.63%)
Mutual labels:  matomo
Matomo
Liberating Web Analytics. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. We love Pull Requests!
Stars: ✭ 15,711 (+17958.62%)
Mutual labels:  matomo
Matomo-PHP-API
PHP wrapper for the Matomo API.
Stars: ✭ 78 (-10.34%)
Mutual labels:  matomo
matomo-for-wordpress
Get a fully functioning Matomo Analytics for your WordPress. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Privacy is built-in. 100% data ownership, no one else can see your data. We love Pull Requests!
Stars: ✭ 90 (+3.45%)
Mutual labels:  matomo
nodejs-piwik
Access a Matomo (Piwik) API from node.js
Stars: ✭ 37 (-57.47%)
Mutual labels:  matomo
ngx-matomo
Matomo (aka. Piwik) web analytics for Angular applications
Stars: ✭ 83 (-4.6%)
Mutual labels:  matomo
matomo-tracker
Stand alone library for using matamo tracking in frontend projects
Stars: ✭ 138 (+58.62%)
Mutual labels:  matomo

Matomo Next

Matomo analytics for Next.js applications

Github Master CI Build Status License: Apache-2.0 GitHub release (latest SemVer) Npm version codecov





  • Basic SPA Matomo setup
  • Will track next/router route changes routeChangeComplete event

Usage

Add the init call in your _app.js :

If your App is a class:

import React 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;

class MyApp extends App {
  componentDidMount() {
    init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID });
  }
  render() {
    const { Component, pageProps } = this.props;
    return <Component {...pageProps} />;
  }
}

export default MyApp;

If you App is a functional component:

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.

Exclude tracking some routes :

This wont track /login.php or any url containing ?token=.

init({
  url: MATOMO_URL,
  siteId: MATOMO_SITE_ID,
  excludeUrlsPatterns: [/^\/login.php/, /\?token=.+/],
});

Track additional events :

import { push } from "@socialgouv/matomo-next";

// track some events
push(["trackEvent", "contact", "click phone"]);

Tests

init
  ✓ should create a js tag and initialize (16 ms)
  ✓ should NOT create events when url is not provided (19 ms)
push
  ✓ should append data to window._paq (2 ms)
router.routeChangeComplete event
  ✓ should trackPageView with correct title on route change (5 ms)
  ✓ should use previousPath as referer on consecutive route change (10 ms)
  ✓ should track route as search in /recherche (1 ms)
  ✓ should track route as search in /search (2 ms)
excludeUrlsPatterns
  ✓ should excluded login.php and token variables (7 ms)
  ✓ should exclude initial page tracking (4 ms)
  ✓ should track initial page if not excluded (3 ms)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].