We’ve come up with a great way to use Google Analytics to automatically track the loading time of individual pages on a web site using Google Analytics and a bit of JavaScript. After following the steps below, you’ll be able to track the very same page load times each and every one of your trackable users are encountering and you’ll also be able to determine which of your pages are the worst offenders.

Note: Since, for one reason or another, the traditional non-asynchronous Google Analytics code is still in use across a majority of websites, that is what will be covered in this post. Accordingly, the code examples shown below are based on the traditional Google Analytics tracking code.

Update: We’ve just published an update to this article dealing with the new asynchronous version of the Google Analytics code! Go ahead and read it!

The problem many have encountered in trying to implement this sort of solution was that once the load time tracking script had been added and Event Tracking enabled, Google Analytics would stop tracking the website’s bounce rate, which would eventually be reported as 0.00%. This is a highly sub-optimal state of affairs.

The trick to solving this problem is to use a separate tracking profile to handle the Event Tracking. Once isolated from the Event Tracking, the primary account will continue reporting bounce rates and the page load times will be reported in a secondary account.

A great thing about this approach to page-load time tracking is that you can let your visitors do all the work, instead of feverishly refreshing your Firefox and checking YSlow for Firebug each time you want to know how long your webpage has taken to load. No, just follow these steps and check Google Analytics in a few hours; you’ll be able to get a much better handle on your load times once you’re done.

  1. Create a new website profile in Google Analytics. To do this, go to ‘Analytics Settings’ and select ‘+ Add new profile’ in the ‘Actions’ column. Under ‘Choose Website Profile Type’, select ‘Add a Profile for a new domain’. This step will allow you to track load times per visitor in a way that will not impact your bounce rate tracking on your pre-existing tracking profile. Be sure to name the profile in a way that will allow you to identify it as the load-time tracking profile as opposed to your pre-existing tracking profile. Take note of the number that begins with “UA” and contains two dashes.
  2. Ensure that Event Tracking is turned ‘on’ in this new account. Event Tracking is the linchpin of this whole operation. Without it, you get nothing.
  3. Insert the following (bold) code into the Google Analytics Tracking Code currently residing in your CMS’s footer template. The greyed-out code is there to give you a sense of where the new code should go. Ensure that you replace the “UA-XXXXXXX-Y” code with the new website profile number you noted in the previous step.
    • try{
              var pageTracker = _gat._getTracker("UA-XXXXXXX-X")
                       pageTracker._setDomainName("none");
                       pageTracker._setAllowLinker(true);
                       pageTracker._setAllowHash(false);
                       pageTracker._link();
                       pageTracker._linkByPost();
                       pageTracker._trackPageview();
              var secondTracker = _gat._getTracker("UA-XXXXXXX-Y")
                       secondTracker._trackPageview();
      }
      catch(err) {}

    If your site has an e-commerce component which you are tracking with Google Analytics’ e-commerce functions, you will want to ignore the previous box and instead insert the same code into the area greyed-out in the box below:

    • pageTracker._trackTrans();
              var secondTracker = _gat._getTracker("UA-XXXXXXX-Y");
                      secondTracker._trackPageview();
      }
      catch(err) {}

    You will want to have your technical services department or web development contractor ensure that this will not interfere with your e-commerce tracking.

  4. Upload ‘time-tracker.js’ to the root of the folder in which your header and footer templates reside. Download the file from Google Code here. For a non-CMS-based site, put ‘time-tracker.js’ instead into the folder where you keep your html files.
  5. Insert the following (bold) code to your header template, just before the tag.
    As before, the greyed-out code is there to give you a sense of where the new code should go.
    Be sure to replace yoursite.com/folder marked in bold with the URL of the folder where your header and footer templates (or html files) are located.
    •   
  6. Go back into Google Analytics and click ‘Content’ and then ‘Event Tracking’. Under the heading ‘Top Events’, you should see a new section entitled ‘Page load time’. This is a good thing.

Enjoy your page load stats!

Jordan Louis
Web Developer
PublicInsite Web Analytics Inc.

Contact us to learn more about what PublicInsite can do for you.

Message Sent

Thank you for registering.

Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Thank you for submitting the form.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.

Message Sent

Thank you for registering.

Thank you for your submission.

Your request has been submitted and a rep will reach out to you shortly.

Message Sent

Thank you for your interest.

Thank you for registering.

You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.

Thank you for subscribing!

You're now looped into the world's largest GMP resource hub!

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Success! Thank you
for reaching out.