ES module for the Google Analytics Global Site Tag.
$ npm install --save ga-gtag
Pick your favorite:
const { gtag, install } = require("ga-gtag");
import gtag, { install } from 'ga-gtag';
... then:
install('UA-#########-#'); // Substitute your tracking ID
install()
adds the Global Site Tag script element into <head>
. It only needs to be called once, but can safely be called multiple times (the script won't be re-added).
From there gtag()
can be used as specified in Google's doc:
gtag('event', 'login', { 'method': 'Google' });