This blog here recommends using react-ga and just adding react events every, eg on event clicks, like:

export default class SomeComponent extends React.Component {

    handleClick() {
            category: 'Navigation',
            action: 'Clicked Link',

    render() {

        return (
                <a onClick={()=>{this.handleClick()}}>Link</a>

Is this the best way to add google analytics?

It's straightforward - but I hate the idea of cludging up all my code with that kind of boiler plate.

I would prefer an entirely separate area to declare my the events I want to track, and define them by element id or something like that.

  • This blog here gives a hint a better solution - use middleware on your redux actions - which might work for a lot of cases - but not for, say, a drop down menu: medium.com/@GildasQ/… – dwjohnston Nov 8 '18 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.