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

Compare data before dispatching #199

Open Nuhasami opened 2 years ago

Nuhasami commented 2 years ago

First of all, thank you for this really neat work!

Secondly, I simply want to make sure I don't send duplicates. I was thinking maybe I can check prevData and currentData before dispatching in useTracking. Is there a way to do that? I hope my question is clear, apologies if it's not. 😸

tizmagik commented 2 years ago

Thanks for the kind words!

Hmm I don't think we have anything out of the box to do this but I think you should be able to push to some persistent array during your dispatch() call and then compare with the previously dispatched event. If it is a dupe you can just return early and not push to your dataLayer.

Happy to look at an example if you have a more concrete use case you'd like to discuss.