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

Consider sending analytics with requestIdleCallback #86

Open
leonardodino opened this issue Nov 13, 2024 · 1 comment
Open

Consider sending analytics with requestIdleCallback #86

leonardodino opened this issue Nov 13, 2024 · 1 comment

Comments

@leonardodino
Copy link

Hey there,

I added the <SpeedInsight /> component to a next.js app and noticed most visits weren't appearing on the dashboard.

Dissecting the script that sends this metrics to vercel I noticed it is geared towards sending this data upon navigations/page visibility changes:

  • addEventListener("visibilitychange",c)
  • addEventListener("pagehide",c)
  • addEventListener("popstate",c)
let e=history.pushState.bind(history);
history.pushState = function(...t){
  e(...t);
  try {
    c()
  } catch(n) {
  }
}

the problem we are facing is that the application is a single page checkout, state is mostly client-side and the "happy path" doesn't include any client-side navigation. I believe adding the same listener to requestIdleCallback makes sense here.

(ensures the data is sent during idle periods, so won't disrupt the user, use CPU during busy periods or congest a limited network upload while the page is using them)

@tobiaslins
Copy link
Collaborator

Hi @leonardodino

We're flushing also on client-side navigations and also on page unload.
It could be that you don't see some datapoints coming in due to content-blockers disabling the script!

We can think about also flushing on requestIdleCallback - good input!

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

No branches or pull requests

2 participants