🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

swup-gtag-plugin

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swup-gtag-plugin

Swup Google Analytics plugin. Updated for Global Site Tag (gtag.js).

0.0.0
latest
Source
npm
Version published
Weekly downloads
130
584.21%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 07 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts