2.1.0 • Published 7 years ago

ta-react-gtm v2.1.0

Weekly downloads
39
License
ISC
Repository
gitlab
Last release
7 years ago

GoogleTagManager

Component to use Google Tag Manager on the page. This component should only be mounted when the GMT ID has be defined.

Version: 2.0

module.exports ⇐ React.PureComponent

Set up the GTM tracking. Apart from a noscript fallback, this pretty much doesn't render anything, but sets up the GTM dataLayer in the constructor, loads the GTM.js script by Google while mounting and pushes a pageview event into the dataLayer, using the passed-in props.

Apart from props.gtmId, all props are part of the statistics object provided by the Newsnet API.

As this class extends PureComponent, it shouldn't be rerendered all the time.

Kind: Exported class
Extends: React.PureComponent

new module.exports()

ParamTypeDescription
props.gtmIdstringThe GTM ID to use.
props.pagetypestringThe pagetype (e.g. 'article').
props.categorystringThe category of the article.
props.subcategorystringThe subcategory of the article.
props.article_idnumberThe legacy article ID.
props.premiumboolWhether this is a premium article.

Installation

yarn add ta-react-gtm

Usage

import GoogleTagManager from 'ta-react-gtm';

// more code ...

class YourComponent extends React.Component {

  componentDidMount() {
    // Get the Webseismo statistics object from Newsnet API here
    // NOT ACTUAL IMPLEMENTATION!
    this.setState({
      gtmObject: data.statistics.gtm,
      gtmId: data.gtmId
    })
  }


  render() {

    return (
      <GoogleTagManager gtmId={this.state.gtmId} {...this.state.gtmObject} />
    )
  }
}
2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0-0

8 years ago