Sub topic 7
Enhanced measurement: automatic events
This chapter assumes you have already created a web data stream and installed the Google tag, as covered in earlier chapters. It also assumes you know the basics of the DOM, such as links, forms, and embedded iframes. Enhanced measurement is a set of switches on the web data stream. Each switch tells the Google tag to watch for a common interaction and send an event when it happens. You write no extra code for these events.
What enhanced measurement does
The Google tag already sends page_view, session_start, and first_visit without any configuration. Enhanced measurement adds listeners for interactions that most sites care about. Because the settings live on the stream, you change them in the Admin interface and the tag picks them up. You don't edit or redeploy the page.
You find the settings under Admin > Data collection and modification > Data streams. Select the web stream and look at the Enhanced measurement card. The toggle on that card turns the whole feature on or off. The gear icon opens the individual switches.
The events and their parameters
The table lists each enhanced measurement event, what triggers it, and the main parameters it carries.
| Setting | Event name | Trigger | Key parameters |
|---|---|---|---|
| Page views | `page_view` | Each page load, and optionally history changes | `page_location`, `page_referrer`, `page_title` |
| Scrolls | `scroll` | First time a visitor reaches 90% of page depth | `percent_scrolled` |
| Outbound clicks | `click` | A click on a link that leads away from your domain | `link_url`, `link_domain`, `link_classes`, `link_id`, `outbound` |
| Site search | `view_search_results` | A page URL containing a search query parameter | `search_term` |
| Video engagement | `video_start`, `video_progress`, `video_complete` | Embedded YouTube playback | `video_title`, `video_url`, `video_percent`, `video_provider` |
| File downloads | `file_download` | A click on a link to a common file type | `file_name`, `file_extension`, `link_url`, `link_text` |
| Form interactions | `form_start`, `form_submit` | First interaction with a form, and form submission | `form_id`, `form_name`, `form_destination` |
Treat the exact parameter lists as a guide and compare them with DebugView on your own site. Google adds and renames parameters over time.
How each event works and where it breaks
Page views and history changes
page_view is the one event you can't turn off while the feature is on. Under Advanced settings there is an option called Page changes based on browser history events. When it is on, the tag sends an extra page_view whenever the page calls history.pushState or history.replaceState. This is how single-page applications (SPAs) get a page view for each route change.
The common failure is a duplicate. If the history option is on and your router code or a Tag Manager trigger also sends page_view, each navigation is counted twice. Pick one source. To send page views yourself, disable the history option. Then stop the tag's initial automatic page view, as follows.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Manual page views: stop the automatic one, then send your own.
gtag('config', 'G-XXXXXXXXXX', { 'send_page_view': false });
function sendPageView() {
gtag('event', 'page_view', {
page_location: location.href,
page_title: document.title
});
}
sendPageView();
// Call sendPageView() from your router after each route change.
</script>Scrolls
scroll fires once per page, at 90% depth. It doesn't tell you about 25%, 50%, or 75%. If you need finer thresholds, you must build them with Tag Manager scroll triggers or custom code. A short page can fire scroll almost immediately, because 90% is reached on load. Don't read a high scroll count as strong engagement without looking at page length.
Outbound clicks
The tag sends click with outbound set to true when a link points to a different domain. The tag compares the link's domain with the current domain. It also treats domains listed in your cross-domain configuration as internal, so those links don't fire click. If a partner site is part of your measurement, expect no outbound click for it once cross-domain is set up.
Site search
By default, the tag looks for the query parameters q, s, search, query, and keyword. If your search page uses another parameter, such as ?term=shoes, add it in the site search settings. You can add several names, separated by commas. The event fires on page load of the results URL. A site that handles search with JavaScript and doesn't change the URL produces no view_search_results event.
Video engagement
This event only covers YouTube embeds that have the JavaScript API enabled. That means the iframe URL includes enablejsapi=1. Vimeo, self-hosted <video> elements, and YouTube players without the parameter are not tracked. Progress events fire at 10%, 25%, 50%, and 75%.
File downloads
The tag matches the link's file extension against a built-in list that includes pdf, doc, docx, xls, xlsx, ppt, pptx, csv, zip, mp3, mp4, and other common types. A download that is served from a URL without an extension, such as /download?id=42, is not detected. For those links, send a custom event.
Form interactions
form_start fires the first time a visitor interacts with a form field in a session. form_submit fires on a submit event. Forms submitted with JavaScript, with no real browser submit, may never fire form_submit. Pages with several forms, such as a newsletter box in the footer, will produce form_start events you didn't expect. Check form_id and form_destination to separate them.
Sending events enhanced measurement does not cover
Enhanced measurement doesn't know your business actions. A sign-up, a purchase, or a click on a particular button needs a manual event. The sign_up event below is one of Google's recommended events, and method is its parameter.
gtag('event', 'sign_up', {
method: 'email'
});Don't recreate an automatic event under the same name. If you send your own file_download while that switch is on, each download is counted twice. Either turn off the switch or choose a different event name.
Reading the data
Event names appear in Reports > Engagement > Events within a day or so of collection, and immediately in Realtime. Parameter values such as percent_scrolled or file_extension are not always shown as dimensions by default. To break down an event by a parameter you may need to register it as an event-scoped custom dimension, which you do in Admin > Data display > Custom definitions. Registered dimensions only apply to data collected after registration.
If a click or download matters to your goals, mark the event as a key event. Do this in Admin > Data display > Events. You can also choose a stricter definition, such as a file_download where file_extension equals pdf, by creating a new event from the existing one.
Choosing which switches to keep on
The defaults are on for all of them, and that suits most sites. Turn a switch off when it adds noise or duplicates something you already send. A site with its own scroll-depth tracking should turn off Scrolls. A site that sends form events through Tag Manager should turn off Form interactions. Before you decide, look at the event counts. Events that fire constantly and that nobody uses count toward your property's event volume. They also make reports harder to read.
Exercise
Your single-page app already calls gtag('event', 'page_view', ...) on every route change. After enabling enhanced measurement, your page view counts roughly double. What is the likely cause and what are two ways to fix it?
Show answer
The "Page changes based on browser history events" option is on, so the tag sends its own pageview on every history change, and your code sends a second one. Fix it by turning off the history option and keeping your manual calls (with sendpage_view set to false in the config), or by removing the manual calls and relying on the history option.
Exercise
A visitor on your site clicks a link to https://example.org/download?id=42 that serves a PDF. No file_download event appears in DebugView. Why, and what should you do?
Show answer
Enhanced measurement matches the file extension in the link URL, and this URL has no .pdf extension, so it isn't detected. Send a custom event with gtag('event', 'filedownload', {...}) only if the automatic switch can't match this link, or use a different event name such as pdfdownload to avoid double counting. Then verify it in DebugView.
Exercise
Your search results page uses the URL /results?term=boots. Site search reports show no search terms. What setting do you change?
Show answer
Open the Enhanced measurement gear icon, edit the Site search settings, and add term to the list of query parameters. The tag will then send viewsearchresults with search_term set to boots.