Since my web application using many AJAX request so categorize as Single Page Application. what i want is to track AJAX technical performance using Google Analytics.
Regarding to GA document, it suggest to implement Virtual Pageviews Tracking as detail in this link
I tried these 3 senario to implement Virtual Page Tracking but non of them is working.
- do i miss something ? or it's GA limitation so we can not collect Timing stats of Virtual Page just like Real Pageview ?
- any others Tools suggestion to track AJAX performance ?
CodePudding user response:
GA is not meant to be used to track page performance and the Value
in ga implies monetary value.
When it says "tracking pageviews" it's not about measuring performance, it's about tracking user activity. As in, how many pages per session, what pages, what led to conversions, where they have troubles going through and so forth. Not a technical tool, but an analytics/marketing tool.
Technically, you still could use it to track page performance and people do it. But not as you've done it. You have to remove any network influence on your timestamps since normal fluctuation there would exceed the useful timing of page performance.
I think the most elegant way of doing it would be creating a custom metric in GA interface and then populate it with performance measuring events (or pageviews). So:
- You take a
new Date()
timestamp (or whatever you do in jquery to get current timestamp) right before the post request - You get another
new Date()
in the post callback - You calculate the difference in milliseconds and send that as the value of the custom metric with the pageview
- You wait for two days for the new data to get processed and build a custom report using your custom metric.
Now when you improve performance of your endpoint, you will be able to see statistical improvements in that report.
This is usually done on the backend though, with the datadog or a similar tool with endpoint monitoring functionality.
When performance is measured on the front-end, we usually use the native performance API, so the window.performance object. Or whatever your front-end rendering library suggests using for that. Here's a bit more on this: https://developer.mozilla.org/en-US/docs/Web/API/performance_property That way you're taking into account a bit more data, not just one endpoint response time.