Google Analytic plugin for Global Site Tag (gtag.js). Gtag 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, it should be noted that pageview event is called when gtag.js is installed.
Simplified code run by this plugin on contentReplaced
event:
window.gtag("config", "GA_MEASUREMENT_ID", {
page_title: pageTitle,
page_path: pageUrl
})
This plugin can be installed with npm
npm install swup-gtag-plugin
and included with import
import SwupGtagPlugin from 'swup-gtag-plugin';
or included from the dist folder
<script src="./dist/SwupGtagPlugin.js"></script>
To run this plugin, include an instance in the swup options.
const swup = new Swup({
plugins: [new SwupGtagPlugin()]
});
gaMeasurementId
defines your GA_MEASUREMENT_ID and is required.
new SwupGtagPlugin({
gaMeasurementId: "GA_MEASUREMENT_ID"
});