For tracking different kinds of data on GOV.UK we have built several different trackers. Each type of tracking is handled by a separate script, but some code is shared between them as they often do similar things.
Most of the trackers work by adding a
data-module attribute to an element along with additional data attributes to provide specific tracking information. Some components have this already built into their code by default. These components should also include a
disable_ga4 option as a failsafe.
The auto tracker is used to cause an event to occur as soon as a page has finished loading (but after a page view). This is used to track significant moments in journeys, such as the successful completion of a smart answer, or an error.
The ecommerce tracker is used to track things like search results within a finder.
The event tracker handles tracking on buttons or other interactive elements, such as tabs and details elements.
The form tracker is designed to capture data about a form when it has been submitted.
There are several types of link tracking. To distinguish them and simplify the code, we define them as follows.
- the link tracker handles link clicks with data attributes added to specific links, or to parent elements of groups of links
- the specialist link trackerautomatically tracks clicks on 'special' links, such as external links, download links and mailto links
Print intent tracker
The print intent tracker tracks if the page has been requested to be printed.
The scroll tracker tracks how much of a page has been viewed.
Smart answer results tracker
The smart answer results tracker has been built specifically to track the Cost of Living smart answer.
The video tracker tracks video views.