GA plugin

Google Analytics 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 GA.

Simplified code run by this plugin on contentReplaced event:'set', 'title', document.title);'set', 'page', window.location.pathname +;'send', 'pageview');

Note: It has been reported that the plugin stopped working in some cases. It probably depends on the method used to load GA as well. If you encounter a problem, consider switching to Gtag plugin.


This plugin can be installed with npm

npm install @swup/ga-plugin

and included with import

import SwupGaPlugin from '@swup/ga-plugin';

or included from the dist folder

<script src="./dist/SwupGaPlugin.js"></script>


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

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