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 (52 Pages)

Get the E-Book (37 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’.

Syntax:

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:

ga(‘send’,{

‘hitType’: ‘pageview’,

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

});

You can also write the above code as:

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

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=”https://www.conversions.com/CRO-beginners-guide.pdf” 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:

ga(‘send’,{

‘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:

ga(‘send’,{

‘hitType’: ‘pageview’,

‘location’: ‘https://www.vb.com/men/shop/sales2015/shirts’

});

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

 ga(‘send’,{

‘hitType’: ‘pageview’,

‘title’: ‘new york’,

‘location’:’https://www.vb.com/men/shop/sales2015/shirts’,

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

});

The complete code can look like the one below:

<script>

 (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){

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

 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

 })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

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

 ga(‘send’,{

‘hitType’: ‘pageview’,

‘title’: ‘new york’,

‘location’:’https://www.vb.com/men/shop/sales2015/shirts’,

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

});

</script>

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:

before

After:

after

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/’,’https://www.vb.com/men/shop/sales2015/shirts’,’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’,

‘location’:’https://www.vb.com/men/shop/sales2015/shirts’

});

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’, ‘https://www.vb.com/men/shop/sales2015/shirts’);

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

 

Do you know the difference between Digital Analytics and Google Analytics?


99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.


Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.


You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.


You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.


So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!


1) The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales.

2) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

3) The number 1 reason why conversion optimization is not working for your business.

4) How to advertise on any marketing platform for FREE with an unlimited budget.

5) How to learn and master digital analytics in record time.

 
 

My best selling books on Digital Analytics and Conversion Optimization

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.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!