There's now a single decorator ( #6 ) that's a default export of this library that you can use instead of the two named exports, withTracking
and trackEvent
. Those two methods are still named exports so this version is backwards compatible with previous versions, but the single decorator is now the preferred method and we may deprecate the named exports in the future.
This single decorator works on Classes, class methods and stateless functional components in the same way.
So, instead of:
import React, { Component } from 'react';
import { withTracking, trackEvent } from 'nyt-react-tracking';
@withTracking({ page: 'FooPage' })
export default class FooPage extends Component {
@trackEvent({ action: 'click' })
handleClick = () => {
// ...
}
// ...
}
You can now just do:
import React, { Component } from 'react';
import track from 'nyt-react-tracking';
@track({ page: 'FooPage' })
export default class FooPage extends Component {
@track({ action: 'click' })
handleClick = () => {
// ...
}
// ...
}
Note that since it's the default export, you can call it anything you want.