Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

A way to listen to event being sent #14

Closed
iipanda opened this issue Jul 22, 2024 · 2 comments · Fixed by #15
Closed

A way to listen to event being sent #14

iipanda opened this issue Jul 22, 2024 · 2 comments · Fixed by #15
Assignees

Comments

@iipanda
Copy link
Contributor

iipanda commented Jul 22, 2024

I'm trying to track link clicks:
Swetrix.track({ ev: 'cta_link_click' });
The issue with this is the navigation happens before the event finishes sending and thus the request fails with NS_BINDING_ABORTED status without being sent. The solution would be returning a promise from the Swetrix.track function or accepting a callback to know when the event has finished sending and proceed with the navigation then.

I can implement this functionality I just wanted to make sure this contribution would be welcome.

@iipanda
Copy link
Contributor Author

iipanda commented Jul 22, 2024

I'm also noticing you are using XMLHttpRequest to send requests instead of the fetch API. Is there any particular reason? If there is no need to keep this I would replace it with fetch since XHR would require me to wrestle with callbacks instead of simply returning a promise.

@Blaumaus Blaumaus self-assigned this Jul 22, 2024
@Blaumaus
Copy link
Member

Hi @iipanda, there's no reason to use XMLHttpRequest, feel free to rewrite it to Fetch and return a promise in the track method

@Blaumaus Blaumaus assigned iipanda and Blaumaus and unassigned Blaumaus Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants