Skip to content

Latest commit

 

History

History
30 lines (25 loc) · 836 Bytes

README.md

File metadata and controls

30 lines (25 loc) · 836 Bytes

Global site tag (gtag.js) - Google Analytics

npm npm bundle size (minified)

ES module for the Google Analytics Global Site Tag.

Install

$ npm install --save ga-gtag

Usage

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