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
JS tracker calls callback too early #17780
Comments
One addition (to prove it's a timing issue): const justWait = () => {
return new Promise(resolve => {
setTimeout(resolve, 1000)
})
}
const redirect = async () => {
await trackEvent()
await justWait()
// all good when redirecting now
} |
@SassNinja Maybe you need to disable the usage of |
@SassNinja as @sgiehl this is currently expected behaviour as when using sendBeacon the requests are sent in the background by the browser and we can't know when the request is finished. The request will generally still finish and a callback is in many cases not needed (or it is not needed to wait for the request to finish) in most cases. I'll close this issue for now as there isn't really anything we can do. If it's important to wait for the request to finish before redirecting or so then you can disable send beacon using |
@sgiehl thanks for the hint! I was a bit confused that the following didn't work
However calling the method |
@tsteur thanks for the explanation!
yeah, seems my case is special due to the redirect immediately after the event is dispatched (what I cannot change)
oh I see, that looks better than my approach (which I did because
|
This issue has been mentioned on Matomo forums. There might be relevant details there: https://forum.matomo.org/t/wait-for-matomo-request-to-finish-callback-event/45875/9 |
Expected Behavior
I expect when I provide a callback to
trackEvent
, it's called AFTER the tracking is done meaning there's no pending request.Current Behavior
When I pass a callback to
trackEvent
and immediately redirect the user once it's called, the request to matomo is still pending and therefore never finished.Possible Solution
Not sure, where exactly the origin of that problem comes from.
After digging into the code I haven't found anything suspicious though the result is definitely wrong.
I assume it's related to this part in the code:
matomo/js/piwik.js
Line 2800 in fa66bc5
Steps to Reproduce (for Bugs)
Context
I'm redirecting the used to another website once he's done with a renewal. Therefore I cannot track anything on the target page but must track it right before redirecting him. This means I need to know when the matomo request is done to be sure everything is tracked before the current page is left.
Your Environment
The text was updated successfully, but these errors were encountered: