mr-gtag
![License](https://img.shields.io/badge/license-MIT-blue.svg)
Easy, strong typed, and a modern way to use google analytics gtag lib.
Both umd and es bundles are produced, along with type definitions.
Install
npm i --save mr-gtag
Usage
First, installing gtag injects the lib:
import { installGtag } from 'mr-gtag';
installGtag(trackingId);
This is equivalent to gtag('config', trackingId, ...);
.
Some options are available here:
import { installGtag } from 'mr-gtag';
installGtag(trackingId, {
sendDefaultPageView: false,
});
From here on, use any of the gtag functions available.
Set a value:
import { gtag } from 'mr-gtag';
gtag('set', { ... })
Send an event:
import { gtag } from 'mr-gtag';
gtag('event', 'page_view', { ... });
Refer to the google docs for more info and to see the different kinds of events you can send.
Development
npm i -g rollup
npm i