Skip to content

swup/matomo-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swup Matomo Plugin

A swup plugin for integrating Matomo analytics.

  • Trigger pageview events after each page change
  • This event is not triggered on intial load, so the first page view must be triggered elsewhere
  • However, the page view event is by default triggered in the Javascripts tracking snippet used for embedding Matomo

Simplified code run by this plugin on the page:view hook:

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

Installation

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>

Usage

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

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