Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mr-gtag

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mr-gtag

Easy, strong typed, and a modern way to use google analytics gtag lib.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mr-gtag

npm License

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 mr-gtag

Usage

First, calling installGtag injects the lib:

import { installGtag } from 'mr-gtag';

installGtag(trackingId);

This injects the lib and then calls what is equivalent to gtag('config', trackingId, ...);.

Some options are available here:

import { installGtag } from 'mr-gtag';

installGtag(trackingId, {
  send_page_view: false, // If set to false, tells gtag to not send the default pageview event. Default is true.
  user_id: 'USER_ID', // You can set the user_id like this
  // Or any other option supported by the google gtag lib
});

From here on, use any of the gtag functions available.

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.

Release notes

2.0.0

  • BREAKING CHANGE: Options that installGtag accepts were renamed to be the exact same as the gtag ones. Be sure to update those.
  • We now correctly handle registering more than one tracking id.

Keywords

FAQs

Package last updated on 24 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc