1.0.0 • Published 7 years ago
react-ga-method-decorator v1.0.0
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 --saveExample
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'})
}
}1.0.0
7 years ago