New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-gtm-ts

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-gtm-ts

This is a library to facilitate the implementation of Google Tag Manager.

  • 1.0.45
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4K
increased by29.46%
Maintainers
1
Weekly downloads
 
Created
Source

🚀 react-gtm-ts

This is a library to facilitate the implementation of Google Tag Manager.

Installation

npm install react-gtm-ts
or
yarn add react-gtm-ts

Usage

Add ReactTagManager.init passing GTM code in app or _app (nextjs):

import { ReactTagManager } from 'react-gtm-ts';

import { NextPageWithLayout } from '@Core/types/next';
import type { AppProps } from 'next/app';

type AppPropsWithLayout = AppProps & {
  Component: NextPageWithLayout;
};

ReactTagManager.init({
  code: 'GTM-XXXX', // GTM Code
  debug: false, // debug mode (default false)
  performance: false, // starts GTM only after user interaction (improve initial page load)
});

function MyApp({ Component, pageProps }: AppPropsWithLayout) {
  return <Component {...pageProps} />;
}

export default MyApp;

Now just use the ReactTagManager.action for the actions passing the event and the variables (optional)

import { ReactTagManager } from 'react-gtm-ts';

import { NextPageWithLayout } from '@Core/types/next';

const Home: NextPageWithLayout = () => {
  return (
    <div>
      <button
        type="button"
        onClick={() => {
          ReactTagManager.action({
            event: 'click_all_button',
            clickText: 'login',
          });
        }}
      >
        login
      </button>
    </div>
  );
};

export default Home;

Learn More

To learn more about Google Tag Manager, take a look at the following resource documentation.

Keywords

FAQs

Package last updated on 22 Aug 2023

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