Open rosesyrett opened 1 day ago
Both are saying your sendAnalyticsMetricEvent
callback function is not a function. Is it possible that it's not defined yet by the time the library is loaded?
Also, your sendAnalyticsMetricEvent()
function has a different signature than what's expected by the onXXX()
function in this library, so I think something's missing in the "how you use web-vitals" example above that would explain this issue.
Description and Background
Since implementing web-vitals into my website I've seen a significant amount of TypeError instances that seem to be originating from the transpiled web-vitals.js script on the browser.
This is probably an issue with my implementation of this library, however I would just like to see if there's any indication it could be a broader issue. I'm unsure how my implementation is incorrect, going from the useful instructions in the documentation.
How I've used web-vitals
I've recently added the web-vitals npm package to my website, and started monitoring a small percentage of my traffic with these event handlers. I have wrapped all of my react components with these, i.e. we have a
setup.ts
function that sets up e.g. connections to sentry, our analytics pipeline, and also sets up these event handlers (given the presence of an experimental flag, which is set to about 1% currently... so 1% of requests will go through this logic). Here is what the relevant part of that file looks like:So all we're doing is setting up callbacks for the event handlers, which will take the event, add an 'attribution' to it (for now, this is empty; later on, we will actually use event handlers for metrics from the web-vitals/attribution part of the library), and sanitize it, i.e. serialize and deserialize it before sending it through our analytics pipeline.
When I was testing this out, everything was fine, I was seeing the callbacks being fired correctly. However since releasing this feature on my website we have noticed some interesting sentry errors. Here is what it looks like when I visit any part of our website with the experimental flag enabled:
I'm not sure why the error is shown twice in the above screenshot. After this has surfaced, the website correctly calls the event handlers, and I can see data correctly being routed through our analytics pipeline. Presumably there are some initial metrics on page load which are not reported on because of this error.
Error details/ stack trace
TypeError: n is not a function
../node_modules/web-vitals/dist/web-vitals.js in c at line 1:2842
../node_modules/web-vitals/dist/web-vitals.js in at line 1:868
Environment details
We are on node v18.20.4, npm version 10.7.0. We are running a django application with a react frontend mostly written in typescript. Please let me know if you'd like to see more details, I can attach a package.lock or something similar but many of our libraries are internal (our repository is hosted on github enterprise).