Add SEARCH_RESPONSE_TIME
analytics event
#2471
Labels
💻 aspect: code
Concerns the software code in the repository
🌟 goal: addition
Addition of new feature
help wanted
Open to participation from the community
🟨 priority: medium
Not blocking but should be addressed soon
🧱 stack: frontend
Related to the Nuxt frontend
⌨️ tech: typescript
Involves TypeScript
🔧 tech: vue
Involves Vue.js
Problem
While we know how long our server takes to respond to a request, we don't know how long it takes for clients to receive the response. It would be nice if we could implement this in our analytics code by adding an event
SEARCH_RESPONSE_TIME
to run client-side only that sends the time it took for the response. It should only do so for queries that aren't cached in the local browser cache.To help visualise the part we don't have information on, here is a diagram:
The only timing we have visibility into is
Cloudflare -> ... -> Cloudflare
and any self-to-self timing in between (nginx to nginx, ELB to ELB). We never know theclient -> ... -> client
timings with our current measurement tools. Client timings have two manifestations as well: Cloudflare cache hits and misses. Therefore, we also need to record whether the Cloudflare cache header records a hit or miss so we can disambiguate and see which part is taking the longest (is it Cloudflare's response or everything after Cloudflare?).This is motivated by a discovery that many search requests in our frontend can take longer than 1 second to respond for me locally, but this isn't apparent from the metrics we have for the nodes after Cloudflare in the diagram above.
Description
Refer to the frontend analytics guide for more information on how to use and set up analytics for development.
When making a search request, create a date object before sending the request. If the
Date
header on the response is after the request start date, then the response is not cached in the local client. This is because theDate
header does not change if the response is retrieved from local cache (which we don't care about the timings for). It does change, however, on any outbound request, even ones that hit the Cloudflare cache.When the request comes back, if the
Date
header is after the time we started making the request, then get the elapsed time between the request start and when the response was received. Also pull out the Cloudflare cache status headercf-cache-status
. Send the following analytics payload:Alternatives
We could implement a bona fide RUM library that measures this stuff more generally, including client-side render timings, etc. But those can often cost a tremendous amount of money and I think we can get the information we need for this using Plausible. We might even be able to implement deeper analysis like client side render timings in Plausible as well to get RUM-level data about site performance, but we're a ways from being able to use that information anyway, I think.
The text was updated successfully, but these errors were encountered: