Skip to content

yousleepwhen/react-ga-method-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'})
  }
}

Releases

No releases published

Packages

No packages published