Redux-saga: analytics with sagas?

Created on 6 Feb 2017  路  3Comments  路  Source: redux-saga/redux-saga

wanted to inquire if anyone else has considered creating an analytics saga that can listen to and respond to specific actions.

right now, the consensus seems to be around either middleware

https://github.com/markdalgleish/redux-analytics

or making a higher-order 'reactive' component like this

http://blog.reactandbethankful.com/posts/2016/09/27/redux-analytics-without-middleware/

any thoughts as to whether or not sagas would be a candidate to fill this role?

question

Most helpful comment

Definitely a good use case for sagas. We do that at ProductReview.com.au because it becomes easy to:

  • Send the event to multiple analytics platforms (Google, Mixpanel, our own API, etc)
  • Debounce the requests or even group them into one if possible
  • Enrich events with data from our Redux stores. For example, user ID
  • Combine multiple sequential events into one. This is really powerful! Example: in order to know whether an user actually read the page content, we can use a stream of events: entered page P + scrolled to position Y + clicked on button "Read more" + stayed for at least 10s and only then fire an analytics event read_page_P

The options are endless and redux-saga makes them a breeze to implement.

All 3 comments

Sure you can use sagas for this. Just take what you are interested in and call what you need ;)

Definitely a good use case for sagas. We do that at ProductReview.com.au because it becomes easy to:

  • Send the event to multiple analytics platforms (Google, Mixpanel, our own API, etc)
  • Debounce the requests or even group them into one if possible
  • Enrich events with data from our Redux stores. For example, user ID
  • Combine multiple sequential events into one. This is really powerful! Example: in order to know whether an user actually read the page content, we can use a stream of events: entered page P + scrolled to position Y + clicked on button "Read more" + stayed for at least 10s and only then fire an analytics event read_page_P

The options are endless and redux-saga makes them a breeze to implement.

Going to close this, if you have any further questions - please just ask :)

Was this page helpful?
0 / 5 - 0 ratings