npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-gtm-module-overide

v1.0.0

Published

React Google Tag Manager Module

Downloads

31

Readme

react-gtm-module-overide

React Google Tag Manager Module

A JS module for React-based apps that implements Google Tag Manager (GTM). It is designed so that the GTM snippet can be injected and used with minimal effort.

Features:

  • Support for Content Security Policy (nonce)
  • Custom GTM script URL for server-side tagging
  • URL parameter renaming via paramMapping to mask GTM fingerprints
  • TypeScript definitions included

Getting Started

npm install react-gtm-module-overide
# OR
yarn add react-gtm-module-overide

In your React application's entry file (src/index.js or src/index.ts):

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import TagManager from 'react-gtm-module-overide'

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
})

const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
    <React.StrictMode>
        <App />
    </React.StrictMode>,
)

Interact with the dataLayer

import TagManager from 'react-gtm-module-overide'

TagManager.dataLayer({
    dataLayer: {
        event: 'home_viewed',
    },
})

If you are using multiple dataLayers you can specify which one to use:

TagManager.dataLayer({
    dataLayer: {
        event: 'identified',
        userId: 'dc26b3de-5186-4fa5-a89a-60762111a5b4',
    },
    dataLayerName: 'personalInformation',
})

Configuration

| Value | Type | Required | Notes | | ------------------------------------------ | ------------------ | -------- | ----------------------------------------------------------------------------- | | gtmId | String | Yes | The ID of your GTM Container. | | dataLayer | Object | No | Information added to the dataLayer before initialization. | | dataLayerName | String | No | Customize the name of the dataLayer object. | | events | Array of Objects | No | Additional events added to the dataLayer during initialization. | | auth | String | No | The gtm_auth query parameter for GTM environments. | | preview | String | No | The gtm_preview query parameter for GTM environments. | | nonce | String | No | Set the nonce for Content Security Policy. | | source | String | No | Custom GTM script URL for server-side tagging. | | paramMapping | Object | No | Rename URL query parameters to mask GTM fingerprints. |

dataLayer

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    dataLayer: {
        currency: 'USD',
        language: 'en',
    },
})

dataLayerName

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    dataLayerName: 'personalInformation',
})

events

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    events: [
        {
            event: 'consent_loaded',
            consentAnalytics: true,
            consentAds: false,
        },
    ],
})

auth & preview (Environments)

Both properties must be set together. Extract the values from your GTM container: Admin -> Environments -> Actions -> Get Snippet.

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    auth: '6sBOnZx1hqPcO01xPOytLK',
    preview: 'env-staging',
})

nonce

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    nonce: 'KCenr5lELncZ6JJlHmerd9aIjddJfBEZ',
})

source

Overwrite the default GTM script URL (https://googletagmanager.com/gtm.js) with a custom one, typically for server-side tagging.

TagManager.initialize({
    gtmId: 'GTM-xxxxxx',
    source: 'https://gtm.example.com/gtm.js',
})

paramMapping

Rename the URL query parameters used in the GTM script and iframe URLs. Only specify the keys you want to rename — others keep their defaults.

Available keys: id, gtm_auth, gtm_preview, gtm_cookies_win, l, noscriptPath.

TagManager.initialize({
    gtmId: '544PSS2',
    source: 'https://acq.example.com/script.js',
    paramMapping: {
        id: 'awl',
        gtm_auth: 'a',
        gtm_preview: 'p',
        gtm_cookies_win: 'c',
        l: 'dl',
        noscriptPath: '/collect',
    },
})

This generates URLs like https://acq.example.com/script.js?awl=544PSS2 instead of the default ?id=GTM-xxxxxx, helping to mask GTM fingerprints.

License

MIT