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

Support for react-router4 and multiple analytics accounts #69

Open vijayyadav06 opened 6 years ago

vijayyadav06 commented 6 years ago

Thanks for providing the module. Have two questions -

  1. Wondering if react-tracking supports react-router4? We wish to track page view events.
  2. Can module support use of multiple simultaneous analytics accounts (say different google analytics accounts)? Useful for sites that has multi-tenants each tracking their own analytics.
tizmagik commented 6 years ago

Hi @vijayyadav06 thanks for the question! Sorry for the late response here :)

  1. Yes, I don't see why RRv4 wouldn't be supported. Page View events can be triggered on "page components" componentDidMount() lifecycle method either via using the dispatchOnMount behavior, or by defining a top-level process function that can achieve the same result. More details on this in the main README.

If you've tried it out and are having any issues with RRv4 would love to hear about them. Feel free to follow-up to this issue or create a new one with some more details.

  1. Yes, since you ultimately have control over what happens to the tracking data you can opt to have it go anywhere, even running your own logic to control what happens depending on what the data looks like.

For example, your dispatch function could look something like this:

export default function dispatch(data) {
  const dataLayer = data.analyticAccount || 'dataLayer';
  (window[dataLayer] = window[dataLayer] || []).push(data);
}

And then you can define which analytic account to use wherever appropriate in your tree:

@track({ analyticAccount: 'dataLayer-2' })
class Foo extends Component { ... }

Hope that helps!