swup swup Matomo Plugin
GitHub swup on GitHub

Matomo Plugin

by jdraserschieb

Matomo plugin triggers pageview event on contentReplaced (on each page change). Note that this event is not triggered at the first load, so the first page view must be triggered elsewhere. However, page view event is by default triggered in Javascripts tracking snippet used for embedding Matomo. Simplified code run by this plugin on contentReplaced event:

_paq.push(['setDocumentTitle', document.title]);
_paq.push(['setCustomUrl', window.location.pathname + window.location.search]);


Install the plugin from npm and import it into your bundle.

npm install @swup/matomo-plugin
import SwupMatomoPlugin from '@swup/matomo-plugin';

Or include the minified production file from a CDN:

<script src="https://unpkg.com/@swup/matomo-plugin@2"></script>


To run this plugin, include an instance in the swup options.

const swup = new Swup({
  plugins: [new SwupMatomoPlugin()]