🎯 Declarative tracking for React apps.
OTHER License
Bot releases are hidden (Show)
Published by tizmagik over 7 years ago
TrackingPropTypes
(#18) you can now import the PropTypes definition for the tracking
context object, if needed.options.dispatchOnMount
(#16) The "auto-dispatch" behavior is now opt-in. See Breaking Changes below for more info.We no longer "auto-dispatch" when seeing tracking data like { page: 'FooPage' }
. Instead you can opt-in to auto-dispatching by passing in options.dispatchOnMount
, which will dispatch the tracking data when the component mounts. Like so:
@track({ page: 'FooPage' }, { dispatchOnMount: true })
export default class FooPage extends Component { ... }
This also means the previous behavior of automatically including { event: 'pageDataReady' }
is no longer the case, and if this needs to be part of your tracking data you will have to manually include it where necessary.
See the README for more info.
Published by tizmagik over 7 years ago
You can now provide a custom dispatch()
function (#10) as the second argument to a top-level decorated component. If provided, this dispatch function will be called to dispatch tracking data instead of the default behavior of dispatching CustomEvent
s on document
.
See README for usage details.
The default "pageview" event changed (#11) from:
{ action: 'pageview' }
to
{ event: 'pageDataReady' }
Published by tizmagik over 7 years ago
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.
Published by ivankravchenko almost 8 years ago
Published by ivankravchenko almost 8 years ago