react-tracking icon indicating copy to clipboard operation
react-tracking copied to clipboard

Compare data before dispatching

Open Nuhasami opened this issue 3 years ago • 1 comments

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. 😸

Nuhasami avatar Mar 09 '22 08:03 Nuhasami

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.

tizmagik avatar Mar 10 '22 15:03 tizmagik