
Your users don't want to wait
Did you know that Google Analytics can track how long it takes your web pages to load?
Slow loading web pages frustrate users and provide a poor user experience. There are a bunch of different tools to help you measure the size of your web pages in kb but what you really want to know is on average how long it takes you user to load each of your pages (measured in milliseconds). Beyond that you want to know how the visitor's connection speed is influencing page load times.
To get Google Analytics to track page load times you will need to set up 'Event Tracking'. Currently, to enable this feature you need to submit a request to Google from the event tracking documentation page.
Update: We've included the newest scripts here:
timeTracker.js
The following code is based on the TimeTracker object written by Google. The original source code can be found here. We've updated the original source code to use the most current API calls (the original uses deprecated functions).
There are two objects used: TimeTracker which is the generic time tracking class (it can be used to time anything) and is also responsible for sending out the event tracking request to Google; and PageLoadTracker which is a wrapper for the TimeTracker class, and is specifically used to track page load times.
There are two snippets of code that need to be added to the page. The initialization code which should go as close to the opening
tag as possible, and the window load event listener code which should go as close to the closing tag as possible.Initialization Code
… ]]>
The PageLoadTracker constructor takes one required argument, and two optional arguments.
The first argument is the variable name of the Google Analytics page tracker object.
The second argument is the name of the index page. If you pass in 'index.html' as the second argument, visiting 'www.example.com' and 'www.example.com/index.html' will both show up as 'index.html' in the GA reports. This also works for subdirectories. So visiting 'www.example.com/dir/' and 'www.example.com/dir/index.html' will both show up as '/dir/index.html' in the GA reports.
The third argument is used to specify a start time. Without the third argument, timing is started when the PageLoadTracker object is created. If you want to track the load time including the time required to load the TimeTracker and PageLoadTracker Javascript files as well, you need to record the timestamp before including the scripts, and pass that timestamp in as the third argument to the constructor.
Event Listener Code
…