swup-gtag-plugin

0.0.0 • Public • Published

Swup Gtag Plugin

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
})

Installation

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>

Usage

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

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

Options

gaMeasurementId

gaMeasurementId defines your GA_MEASUREMENT_ID and is required.

new SwupGtagPlugin({
  gaMeasurementId: "GA_MEASUREMENT_ID"
});

Dependents (0)

Package Sidebar

Install

npm i swup-gtag-plugin

Weekly Downloads

5

Version

0.0.0

License

MIT

Unpacked Size

20.1 kB

Total Files

6

Last publish

Collaborators

  • jthallee