nytimes / react-tracking

🎯 Declarative tracking for React apps.
https://open.nytimes.com/introducing-react-tracking-declarative-tracking-for-react-apps-2c76706bb79a
Other
1.88k stars 123 forks source link

Add some caveats to read me #92

Closed rickgaurav closed 6 years ago

rickgaurav commented 6 years ago

Add some points which are easy to be missed but are really required to be taken care of, in order for tracking to work correctly.

tizmagik commented 6 years ago

Thanks @rickgaurav ! This is noted early in the doc,

The decorator can be used on React Classes and on methods within those classes. If you use it on methods within these classes, make sure to decorate the class as well.

Maybe we can make that more obvious instead of adding this new "gotcha" section? Could add a comment to the code snippet perhaps. Something like:

import React from 'react';
import track from 'react-tracking';

@track({ page: 'FooPage' })
export default class FooPage extends React.Component {
  @track({ action: 'click' }) // be sure to have decorated the class for this to work
  handleClick = () => {
    // ... other stuff
  };

  render() {
    return <button onClick={this.handleClick}>Click Me!</button>;
  }
}
tizmagik commented 6 years ago

I think this might also be helpful for a future FAQ I'd like to put together, #86

rickgaurav commented 6 years ago

Ahhh, I missed it. I guess its emphasised enough then. Adding a comment in code is enough. I will close the PR.