Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Suggestion] return the underlying fetch Promise in trackEvent/trackView #98

Closed
valsinats42 opened this issue Apr 25, 2024 · 3 comments · Fixed by #99
Closed

[Suggestion] return the underlying fetch Promise in trackEvent/trackView #98

valsinats42 opened this issue Apr 25, 2024 · 3 comments · Fixed by #99

Comments

@valsinats42
Copy link

Currently, the trackEvent and trackView functions fire off the collect fetch request, but there's no way for the client to track its progress. As a suggestion, the library could return the underlying fetch Promise, so it could be await-ed by the client code.

I'd find this useful, for example, if I want to track a click on an a tag with a href attribute. In the current situation, if I add a custom @click handler and call { umTrackEvent(..); window.location.href = ...}, I can't think of a clean way to guarantee that the event has been sent before the browser loads the new page and aborts the tracking request (of course, one can use a setTimeout, but that's not pretty).

@ijkml
Copy link
Owner

ijkml commented Apr 26, 2024

That is a great idea and use case, @valsinats42. I'll work on that. Thank you!

@ijkml
Copy link
Owner

ijkml commented Apr 28, 2024

Hey, @valsinats42, this is now available in the latest version 👍 .

@valsinats42
Copy link
Author

Awesome, I'll integrate it in my codebase right now, thank you! :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants