Page Tracking in Google Analytics

This article is in conjunction with the article Introduction to Google Analytics Library – analytics.js’ and ‘Introduction to Google Analytics Commands

Technically speaking, Google Analytics is a JavaScript library called ‘analytics.js’ and Google Analytics commands are used for setting up Google Analytics implementations like ecommerce tracking.

Therefore it is important, that you understand both analytics.js and GA commands before implementing page tracking on your website.

In page tracking, a page represents a web page.

The page can be a static or dynamic (dynamically created) web page.

Through page tracking you can measure the number of times a page was shown to your website visitors in GA.

This can be done by sending a pageview hit, each time a page is shown.

The command method named ‘send’ is used to send pageview hit to Google Analytics:

For example:

 ga(‘send’, {‘hitType’: ‘pageview’});  // send a page view hit

You can also write this line of code without using hitType field as:

 ga(‘send’, ‘pageview’); // send a page view hit

This line of code is already included in your Google Analytics tracking code:

ga tracking code

However by default, GA tracking code is executed only on a page load.

If a page does not load in your web browser, then the tracking code is not executed and hence no pageview data is sent to GA server.

Get the E-Book (37 Pages)

Learn to read e-commerce reports book banner

Get the E-Book (104 Pages)


There could be situations, in which you need to send a pageview hit manually because:

#1 The event (user’s interaction/activity) that you want to track does not generate a pageview when it occurs.

For example loading of Flash/Ajax content, downloading a file, clicking on an external link etc.

#2 You want to rewrite request URIs for advanced segmentation.

For example you may want to rewrite the request URI: /men/shop/sales/shirts to say /men/shop/sales2015/shirts in order to segment the 2015 sales data in GA without actually rewriting the URLs on the website.

For pageview hit, you can set only one field called ‘page’. However you can set many field objects like: ‘title’ and ‘location’.


ga(‘send’, ‘pageview’, [page], [fieldsObject]);

If you are not sure, what is the difference between a field and field object, then read this article: Introduction to Google Analytics Commands

Here, page is the path portion of the url. Its value should start with forward slash ‘/’. Its default value is document.location.pathname.

If you want to supply your own URI (or better say rewrite URI in your GA reports), then you can do that by supplying a custom value to the ‘page’ field. For example:


‘hitType’: ‘pageview’,

‘page’: ‘/wommen/bags/sales2015/’


You can also write the above code as:


The page field is also used to send virtual pageviews.

Syntax for sending virtual pageview:

ga(‘send’, {

‘hitType’: ‘pageview’,

‘page’: ‘name of your virtual page’,


For example:

<a href=”” onClick=”ga(‘send’, ‘pageview’, ‘/virtual/guides/download/CRO-beginners-guide.pdf’);”> Download CRO Beginners Guide</a>

Here I am sending a virtual pageview when a user clicks on the ‘Download CRO Beginners Guide’ link.


Following are the field objects relevant to tracking pageviews:

#1 title – it is the title of the web page being tracked. Its default value is document.title.

If you want to supply your own title (or better say rewrite titles in your GA reports), then you can do that by supplying a custom value to the ‘title’ field object:


‘hitType’: ‘pageview’,

‘title’: ‘new york’



#2 location – it is the full URL (excluding anchor) of the web page being tracked. Its default value is document.location.

If you want to supply your own URL (or better say rewrite URL in your GA reports), then you can do that by supplying a custom value to the ‘location’ field object:


‘hitType’: ‘pageview’,

‘location’: ‘’


Here is how you can set all of the pageview fields in one go:


‘hitType’: ‘pageview’,

‘title’: ‘new york’,


‘page’: ‘/wommen/bags/sales2015/’


The complete code can look like the one below:



 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),



 ga(‘create’, ‘UA-1445352-16’, ‘auto’);


‘hitType’: ‘pageview’,

‘title’: ‘new york’,


‘page’: ‘/wommen/bags/sales2015/’



You can verify whether these new pageview fields’ values, are being sent to GA server, through Google developer console.

Before any changes to the pageview fields:




Note: The default tracker does not set the ‘page’ field by default. The value of the ‘page’ field is extracted from ‘document.location’. So when you set the value of ‘page’ field manually, that value is used (and reported by developer console), instead of the ‘document.location.pathname’


The following code will change the URL path but won’t change the title and location field of the tracked web page:

ga(‘send’,’pageview’,’/wommen/bags/sales2015/’,’’,’new york’);

still the same

The location and title are not changed because, ‘location’ and ‘title’ can’t be used as fields while sending the pageview hit.

However they can be used as field objects while sending the pageview hit. For example:

ga (‘send’,’pageview’,’/wommen/bags/sales2015/’,{

‘title’:’new york’,



If you are not sure, what is the difference between a field and field object, then read this article: Introduction to Google Analytics Commands

If you want to use ‘title’ and ‘location’ as fields instead of field objects while sending the ‘pageview’ hit, you can do that by using the ‘set command method. For example:

ga(‘set’, ‘title’, ‘new york’);

ga(‘set’, ‘location’, ‘’);

ga (‘send’,’pageview’,’/wommen/bags/sales2015/’);

Learn about the Google Analytics Usage Trends Tool

The Google Analytics usage trend is a new tool which is used to visualise trends in your Google Analytics data and to perform trend analysis.

Do you want to Learn Web Analytics in 8 Weeks?

  • Learn and Master Web Analytics, Conversion Optimization & Google Analytics from Industry Expert in 8 weeks.
  • Lifetime access to the course + Lifelong FREE course updates.
  • New study material added every few months (lifelong learning).
  • Up to date training material.
  • Most exhaustive course on Google Analytics on the internet.
  • Hundreds of Assessments to test your learning.
  • Your 24/7, 365 days a year reference source.
  • Learn at your own pace and from any place.

Take your Analytics knowledge to the next level. Checkout my Best Selling Books on Amazon

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over eleven years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of and

I am also the author of three books:

error: Alert: Content is protected !!