For further actions, you may consider blocking this person and/or reporting abuse
Read next
The Fastest Way to Build a React Project in 2025 (with the Latest Tools)
gitter4coding -
Best Version Control Practices Every React Development Team Needs To Know
Joseph Abraham -
How I Fixed a Circular Dependency Bug in Redux Using dpdm
Akshay S -
Building a Custom Audio Player in React: A Step-by-Step Guide
Nilesh Kumar -
Top comments (1)
I struggled my way to find a good approach to track site events in my react application.
Here's what I was thinking,
Huh! there started the stomach cramps. How can I do this without affecting or changing my existing apps and at same time considering any new react app to do this?
The first approach is naive. Second, seems a better solution than first but it's still embedded within the presentational logic. What if I plan to ship ui-components separately in future? Ah! I can still pass an analytics boolean flag to run the logic but I would avoid that marriage.
So, how about capturing events on every or any or some redux dispatch calls automatically. What if I can setup an event listener once, just once in my codebase to handle all dispatch calls app wide.
How about this code below
Now, what if this function fires on every redux action call? That would be helpful right. A universal tracker for all our needs.
Let's take a few more cases.
Second, how about a situation where I need to fire
trackListener
only on certain events.Third, what about a situation where I need to exclude the events.
Well, we can imagine doing a conditional check for the existence of an event in our event dictionary
Now, how do we achieve all this simplicity?
I created a small library to do enable this event tracking with this @ github.com/turtlemint/redux-analytics
There is a one-time small set up before we could enable this. Readme got it covered.
It requires a lot of improvement in the demonstration, code clean up, react hooks improvement, removing HOC pattern. But hey it works. So thought of sharing this meanwhile if it helps existing apps and getting community feedback at the same time.
Oh! almost forgot, do you guys know that redux also dispatch events on route changes when using
connected-react-router
package. Can you also imagine that your second type of events ispage views
which are handled automatically by just one or maybe two (as per your needs) listener functions? :)It's my first open-source push. Hope you guys like it!