Whenever someone loads a page of your website or their browser history state is
changed by the active site, an enhanced measurement
event called
page_view
is sent from your website to Google Analytics. Since the event is
sent automatically, you don't need to send pageview data to Analytics manually.
However, when you want to manually control how pageviews are sent (e.g. single-page applications or infinite scrolling), you can disable pageviews and then manually send them from your website. Learn how to Measure single-page applications.
This document describes the default pageview behavior and then how to send your own pageviews manually.
For information about how to measure screenviews on a mobile app, see Measure screenviews instead.
Before you begin
This guide assumes that you've done the following:
- Create a Google Analytics account and property. This step automatically creates a Google tag for you.
- Create a web data stream for your website
- Place the Google tag snippet on your website
It also assumes that you have the following:
- Access to your website source code
- The Editor (or above) role to the Google Analytics account
Default behavior
When you add the Google tag (gtag.js) to your site, the snippet includes a
config
command that sends a pageview by default. You can include additional
<parameters>
with information about the pageview in order to specify how
Google Analytics is initialized:
gtag('config', 'TAG_ID', <parameters>);
When customizing the pageview behavior, the following keys may be used:
Name | Type | Required | Default value | Description |
---|---|---|---|---|
page_ |
string |
No | document.title | The title of the page. |
page_ |
string |
No | location.href |
The URL of the page.
If you override |
send_ |
boolean |
No | true |
Whether or not a pageview should be sent. |
For example, the following overrides the page_title values:
gtag('config', 'TAG_ID', {
'page_title' : 'homepage'
});
Manual pageviews
When you want to manually control how pageviews are sent (e.g. single-page applications or infinite scrolling), do the following:
Disable pageview measurement
To disable the default page_view
event, set the send_page_view
parameter to
false
in the Google tag snippet.
gtag('config', 'TAG_ID', {
send_page_view: false
});
The send_page_view
setting does not persist across pages. This setting must be
repeated on every page of your website where you want to disable automatic
pageviews.
Manually send page_view
events
Where appropriate, make the following gtag
call, replacing placeholder values
as necessary:
gtag('event', 'page_view', {
page_title: '<Page Title>',
page_location: '<Page Location>'
});