User Timings - Web Tracking (analytics.js)

This guide describes how to measure periods of time using analytics.js.


Studies have shown that reducing page load time improves the overall user experience of a site. Google Analytics has a number of powerful reports that automatically measure and report on page load times. However, it is also possible to track custom timing information to measure performance information specific to your site. For example to measure the time it takes for a particular JavaScript library to load.

User Timings allow developers to measure periods of time using the analytics.js library. This is particularly useful for developers to measure the latency, or time spent, making AJAX requests and loading web resources.

User timings are measured using the following four fields::

Value Type Required Description
timingCategory String Yes A string for categorizing all user timing variables into logical groups (e.g jQuery).
timingVar String Yes A string to identify the variable being recorded (e.g. JavaScript Load).
timingValue Number Yes The number of milliseconds in elapsed time to report to Google Analytics (e.g. 20). If you set timingValue to a negative value (e.g. -20), the user timing hit will not be processed.
timingLabel String No A string that can be used to add flexibility in visualizing user timings in the reports (e.g. Google CDN).


To send user timing data, you pass the ga function the send command with the timing hit type

ga('send', 'timing', 'jQuery', 'Load Library', 20, 'Google CDN');


  • jQuery is the timingCategory
  • Load Library is the timingVar
  • 20 is the timingValue
  • Google CDN is the timingLabel

As the timingLabel is optional, it can be omitted from the send command:

ga('send', 'timing', 'timingCategory', 'timingVar', timingValue);

The send command also accepts an optional field object as the last parameter for any of these commands. The field object is a standard JavaScript object, but defines specific field names and values accepted by analytics.js.

For example, you might want to set the page field for a particular user timing. You do this using:

ga('send', 'timing', 'timingCategory', 'timingVar', timingValue, 'timingLabel', {'page': '/my-new-page'});

Finally, all the parameters of the send command have their own field names. So you can send a user timing by passing only a field object to the send command:

ga('send', {
  'hitType': 'timing',
  'timingCategory': 'jQuery',
  'timingVar': 'Load Library',
  'timingValue': 20,
  'timingLabel': 'Google CDN',
  'page': '/my-new-page'

Read the Field Reference document for a complete list of all the fields that can be used in the configuration field object.


When sending user timing data, you specify the amount of milliseconds spent in the timingValue parameter. It’s up to you, the developer, to write code to capture this period of time. The easiest way to do this is to create a timestamp at the beginning of a period of time and create another timestamp at the end of the period. Then you can take the difference between both timestamps to get time spent.

Here’s a great example:

Today, many sites include 3rd party JavaScript libraries or request data through JSON objects. While your site might load these resources quickly at home, the same resources might load very slowly for users in other countries. These slow loading resources can degrade the site experience for international users.

The site speed user timing feature can help you collect and report how long these resources take to load.

Here’s a simple example demonstrating how to track the time spent of a function that asynchronously loads JavaScript resources:

var startTime;

function loadJs(url, callback) {
  var js = document.createElement('script');
  js.async = true;
  js.src = url;
  var s = document.getElementsByTagName('script')[0];

  js.onload = callback;
  startTime = new Date().getTime();

  s.parentNode.insertBefore(js, s);

function trackTimingCallback(event) {
  var endTime = new Date().getTime();
  var timeSpent = endTime - startTime;
  ga('send', 'timing', 'jQuery', 'Load Library', timeSpent, 'Google CDN');

  // Library has loaded. Now you can use it.

In this example, loadJs is a utility function that loads JavaScript resources by dynamically creating a script element and attaching it to the browser’s DOM. The function accepts two parameters: a URL as a string, and a callback function named trackTimingCallback that will be executed once the script has loaded.

Inside loadJs, a beginning timestamp is stored in startTime. Once the resource has been loaded, the callback function is executed. In the callback function, the end timestamp is retrieved and used to calculate the time it took to load the JavaScript resource. Finally, the time spent is sent to Google Analytics using the send command.

So by calling:

loadJs('//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', trackTimingCallback);

You will asynchronously load the jQuery library from the Google Content Delivery network, and once complete, execute the callback function, that in turns sends the load time of the resource to Google Analytics.

Sampling considerations

Google Analytics will sample timing hits during processing in order to ensure an equitable distribution of system resources for this feature.

The rate at which timing hits are sampled is determined by the total number of pageview hits received during the previous day for the property. The following table outlines how the timing sampling rate is determined:

Total pageview hit count (previous day) Maximum number of timing hits that will be processed
0 - 1,000 100
1,000 - 100,000 10% of total pageview hit count
100,000 - 1,000,000 10,000
1,000,000+ 1% of total pageview hit count

Limiting the number of hits sent

To avoid sending Google Analytics hits that will not be processed, analytics.js allows you to control the percentage of hits that are sent via the sampleRate and siteSpeedSampleRate configuration options. By default these fields are set to 100% and 1%, respectively. You can adjust these values to more closely approximate the number of timing hits Google Analytics will process based on your average daily pageview counts.