1.0.0 • Published 6 years ago

react-ga-method-decorator v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

react-ga-method-decorator

This module is helps you use the event method of react-ga as decorator pattern.
GA initialize should be called first.

react-ga ReactGA.initialize must be called first or GoogleAnalytics should be loaded manually.

Install

npm install react-ga-method-decorator --save

Example

import { gaEvent } from 'react-ga-method-decorator'

class TestComponent extends React.Component<TestProps, TestState> {
  constructor(props){
    super(props)
    this.onClickSayHello = this.onClickSayHello.bind(this)
  }

  @gaEvent({ category: 'Test', action: 'Click SayHello'})
  onClickSayHello() {
    console.log('Hello')
  }
}

It behaves similar to the following:

import * as ReactGA from 'react-ga'

class TestComponent extends React.Component<TestProps, TestState> {
  constructor(props){
    super(props)
    this.onClickSayHello = this.onClickSayHello.bind(this)
  }

  onClickSayHello() {
    console.log('Hello')
    ReactGA.event({ category: 'Test', action: 'Click SayHello'})
  }
}