Skip to main content
Warning This document has not been updated for a while now. It may be out of date.
Last updated: 10 Jun 2020

Analytics on GOV.UK

GOV.UK uses Google Analytics to track user journeys through the site. The tracking data is available to anyone with Google Analytics Suite access for GOV.UK. You can request access to this by following the steps in the GDS wiki.

GOV.UK analytics code

The GOV.UK analytics codebase is a collection of JavaScript modules spread through a few different projects:

Tracking overview

User behaviours and journeys can be tracked in a variety of ways, the default method of tracking with Google Analytics is to record pageviews - This is data relating to a page the user has just requested (eg. URL, user-agent, referrer). Pageviews are typically recorded as the user visits the page.

Where a page offers the user multiple navigation choices it’s often desirable to track events, a typical example of this is recording when a user chooses an option in a group of radio buttons. Event data is usually comprised of a category, a label and a value.

Both pageviews and events can be augmented with custom dimensions, additional fragments of data describing the behaviour of the user, eg. which variant of an multivariate test they are assigned. The custom dimensions are documented on Confluence.

Cross domain tracking

Work has been done to implement cross domain tracking between GOV.UK and some government services. Tracking data for cross domain journeys is sent to a separate GA property from the existing GOV.UK GA property, and services can also maintain their own separate tracking.

Tracking a user journey across different services with different domains requires additional configuration so that the destination domain (eg. can receive analytics data for the portion of the user journey taking place on the source domain (eg. GOV.UK).

To some extent the referrer value in pageview data will contain some evidence of where the user has arrived from, often this isn’t enough information or may be misleading due to authentication redirects.

The javascript function'UA-43888888-1', 'someServiceTracker', [''])

registers a linked (cross domain) tracker and sends a pageview to the tracker. The current cross domain configuration on GOV.UK contains only those domains that have turned on cross domain tracking. More information is included in static’s analytics documentation.

Some cross domain tracking existed prior to this work to link 19 services to GOV.UK. It exists on some transaction start pages such as Change your driving test appointment, where the start button contains data attributes, such as:

<a href=""

Cross domain event tracking

Once the linked tracker is registered, it’s also possible to track events using the registered tracker name:'Radio button chosen', 'selected-service-option', { 'trackerName': 'someServiceTracker' })

Cross domain tracking and GOV.UK javascript module loading

The GOVUK.Modules library will attempt to initialise and start a module for every data-module data attribute it encounters. In the case of cross domain tracking this can be undesirable if more than one element contains the cross-domain-tracking data-module because the underlying ga.js library from Google will not accept multiple calls to register a linked tracker and will throw javascript errors. See this static commit for how we mitigate against this for multiple govspeak buttons with cross domain tracking enabled.

Developing and debugging Google Analytics tracking

Google provide an extension Google Analytics Debugger which logs all GA suite interactions to the console. This is useful for testing what is being sent to GA and when. Other GA debuggers are also available.

Google Analytics Debugger console output