Page tracking with gtag.js

Page tracking allows you to measure the number of views of a particular page on your website. This guide explains how to use gtag.js to implement page tracking for Google Analytics.

Implementation

The following code in the global tracking snippet automatically sends a pageview to the Google Analytics property with tracking ID GA_TRACKING_ID:

gtag('config', 'GA_TRACKING_ID');

If you don't want gtag.js to send the pageview automatically, set send_page_view to false:

gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });

To send a pageview to multiple Google Analytics properties, specify a config for each property:

gtag('config', 'GA_TRACKING_ID_1');
gtag('config', 'GA_TRACKING_ID_2');

Pageview parameters

The following table lists the pageview parameters:

Parameter name Value type Required Description
page_title string No The page's title.
page_location string No The page's URL.
page_path string No The path portion of location. This value must start with a slash (/) character.

You can set these parameters by updating the config for your property and setting values for the parameters you want to manually override:

gtag('config', 'GA_TRACKING_ID', {
  'page_title': 'homepage',
  'page_location': 'http://foo.com/home',
  'page_path': '/home'
});

Next step

Learn how to track events.