This article introduces how to track Page Load Time in Google Analytics 4, there are two ways:
- One is to use a separate event to track the Page Load Time. For example, after the web page is loaded, send a separate event to track the Page Load Time.
- One is to incorporate the Page Load Time into Page View: use custom JavaScript to obtain the Page Load Time through the browser API, set it as an event parameter, and send it along with the Page View. This method will not increase the number of requests sent.
This introduction is the second method. There are two things to pay attention to when using this method:
- The trigger condition must be that the window is loaded, not Page View, because if you use Page View, the window may not be loaded yet, which will result in the Page Load Time not being obtained. If the window is loaded, it must be loaded and you can obtain it.
- Do not trigger the event before the window has been loaded. If the event is triggered faster than the PageView, it will affect attribution.
Next let’s see how to set it up:
Variables: Custom JavaScript
The purpose of this variable is to obtain the Page Load Time through the browser API
Source Code:
function(){ var timing = performance.getEntriesByType('navigation')[0] || performance.timing; var load_time = ((timing.loadEventStart-timing.fetchStart)/1000).toFixed(2); if(load_time>0){ return load_time; } }
Tag: Default PageView Tracking
Find the Tag of GA4‘s default pageview tracking and add it in Shared event settings:
Change the Trigger to window loaded:
Preview
After setting, preview and debug in GTM:
As you can see, the event parameter page_load_time accurately tracks Page Load Time.
Custom Definitions
In GA4, click 「Admin」——「Custom Definitions」——「Custom metrics」——「Create custom metrics」, and then make the following settings:
That’s it.
Explore:Data Verification
After collecting some data, you can use Free form to verify it in Explorations:
The Page Load Time here is the sum of multiple web pages. If you want to see the average, you can use the calculation metrics. The formula is {Page Load Time}/{Events count}. The report is as follows: