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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-tag-manager

v3.0.0

Published

Google Tag Manager for React

Downloads

222

Readme


Installation

$ npm install --save react-tag-manager
$ yarn add react-tag-manager

Examples

Enabling and loading the Google Tag Manager

import GTM from 'react-tag-manager'

export const AppContainer = () => (
  <div>
    <GTM 
      gtm={{
        id: 'GTM-12345',
        auth: '',      // Optional
        preview: '',   // Optional 
      }} 
      settings={{
        sendPageView: true,     // default false
        pageView: {             // default null
          event: 'pageview',    // default
          data : {},            // default
          
          settings: { 
            locationProp: 'pathname', // default
            sendAs      : 'url',      // default
          },
        }
      }}>
    	...
    </GTM>
  </div>
)

Updating / Adding data to the data layer

import DataLayer from 'react-tag-manager/DataLayer'

export const Component = () => (
  <div>
    // All props will be added to the data layer
    <DataLayer 
      foo={'bar'}
    />
        
    <DataLayer 
      foo={'bar'}
      settings={{
        passProps: true, 	// default false, will pas all the given props to the child components
        withGTM: true, 		// default false, will add GTM to the child components
      }}>
      ...
    </DataLayer>

    ...
  </div>
)

Trigger a event

import React from 'react'
import { withGTM } from 'react-tag-manager'

@withGTM
export default class extends from React.Component {

  handleButtonClick = () => {
    const { GTM } = this.props
    
    GTM.api.trigger({
      event: 'my-button-click',
      bar: 'foo'
    })
  }
  
  render() {
    return (
      <div>
        <button onClick={this.handleButtonClick} />
      </div>
    )
  }
  
}

Trigger a pageview event

import React from 'react'
import { PageView } from 'react-tag-manager'

export default class extends from React.Component {

  render() {
    return (
      <div>
      	<PageView />
        ...
      </div>
    )
  }
  
}

Trigger a onClick event

import React from 'react'
import { Click } from 'react-tag-manager'

export default class extends from React.Component {

  render() {
    return (
      <div>
      	<Click
      	  event={'click'}
      	  data={{
      	    event: 'click',
      		...
      	  }}>
      	  <button>CLICK ME</button>
      	</Click>
        ...
      </div>
    )
  }
  
}

Development

If you'd like to contribute to this project, all you need to do is clone this project and run:

$ npm install
$ npm run build
$ npm run build:watch // To recompile files on file change

Using development version in local project

You can use npm link / yarn link to use your development version in your own project:

  • Go to react-tag-manager directory and execute command npm link / yarn link
  • Go to your project directory and execute command npm link react-tag-manager / yarn link react-tag-manager

License

React Tag Manager is MIT licensed.

Collaboration

If you have questions or issues, please open an issue!