Having created and run many websites, I found myself becoming a pretty decent programmer. Along the way I developed some neat tricks when working with Google Analytics. Based on my experience I thought I’d write this helpful article for you to explain whether you need to put Google Analytics code on every page.
So, do you need to put Google Analytics code on every page? You technically do need to put your Google Analytics code on every page. But, there are some easy ways to do this depending on how you are making your website. For example there is a plugin for WordPress, and you can use functions for hand coded websites.
What is Google Analytics and how does it work?
Google Analytics is a software tool created by Google that uses code to store the actions of users that come to your website. They also record what country the person is in. Interestingly Google will store historical data for you, and also show it to you in real time.
When you install a Google Analytics code snippet onto your website. It gives them access to implement code that can identify where a person’s mouse clicks and scrolls, as well as any words they type onto their keyboard. This data is sent to Google and they store it on their databases.
When you log in to Google Analytics, the Google analytics website accesses the stored information in their database and presents in easy to understand diagrams for you to view. You can customize the data to show what specifically you would like to know about people who went and are on your website.
Such as, what country they went to it from, and what their age range is. Google finds this data through internet service providers (ISPs), that have various agreements with companies to provide data to them. Additionally, almost everyone has a Gmail account. A Gmail account asks and stores various information about you such as your age, whether you are male or female.
Google Analytics is installed so that you can see how many visitors you get to your website, as well as, how long they spent on each page, and what they clicked on.
You can use this information to change the layout of your website, and to see how well the different parts of your website are doing. That way you change things around, and experiment to present the best solution for your customers.
Where to put your Google Analytics tracking code
I’ll assume you’ve already got your Google Analytics tracking code. There’s a few places to put it. But, overall you want it in the header html tag of your website. If you haven’t used html before html segments the page into blocks using elements.
An element is used interchangeably with tag in html terminology. To create the element you write one tag and then another tag. Anything within that opening and closing tag is within that element.
So, you need to place the code snippet that Google gives you within the header tag. That way it starts collecting data from the visitor straight away. If you put it further down the page or in the footer it wont start collecting data immediately and it wont collect everything the user does.
So that the website code is easy to update and edit. It is a standard across all websites so that it is easy for developers and programmers to communicate and work with each other. Otherwise, they would have looked through the entire HTML document to find it.
This is generally only an issue if the website has errors on it. But, beyond the scope of this article. The other main reason is that HTML is layout in such a way that the scripts are best placed in the header
There is a good testing tool that Google provides once you have added the code snippet to your website. If you run into any issues with getting it to work, make sure you have saved after you have added it. You might not have saved it. It’s a common problem.
The other issue might be harder to get to the bottom of. It will likely save you a lot of time to ask a developer on Youtube who does livestreams, or ask a friend who knows about programming to help you. You can also do a Google search for how to install a Google Analytics code on the particular web builder you are using for your website.
Best ways to install Google Analytics on all pages
The easiest way to install Google Analytics on all pages is using the web builders feature. In recent times web builders have improved to the point where almost all of them include a place to put your Google Analytics code.
In the settings it is usually fairly easy to find. Or, just do a Google search. You still need to check it installed across the whole website using Google Analytics tool.
Some web builders such as Clickfunnels [affiliate link] have a place to put each of your Google Analytics code. But, you have to install it on each page.
WordPress and all it’s themes
With WordPress this is much easier because you can add it across your whole website by only putting it in one place. Go to your plugins menu in WordPress and search for Google Analytics. Then just follow their instructions from there it’s pretty easy.
Advanced Beginner Web Developers
If you’re building your website yourself using PHP you can make use of PHP functions to make it easier. This helps save time later down the road, even though initially it does take some time to set up.
To do this create a separate file called for example analytics.php. Then paste the code snippet that Google gives you into that PHP file. Then, use:
<?php include_once(“analytics.php”); ?> in a header() function. This does get a bit fiddly but you can work it out. This will simplify your code so that each new page only has one header function and not multiple lines of scripts. Such as, Google fonts, icon sets, etc.
Reasons why you might not want Google Analytics on all pages
You might want to avoid putting Google Analytics on pages that you aren’t interested in tracking. This is because the code snippet does add a little bit of load time to your website. That slows it down, and you want your website to run as fast as possible.
You do need to put Google Analytics on every page that you are interested in tracking. Depending on what website builder you are using, it is done automatically for you. As a result of inbuilt code. For example, with WordPress you can put the code in one place, and then code that you don’t see puts it on each page for you.
This is also the case for web builders like Wix, and Squarespace. If you built the website yourself you should add to each page, or use some functions to add it dynamically to each page.
Steven Johnson, a WP Hosting Reviews senior editor, works from Atlanta and covers all things related to WordPress and Hosting.
He graduated from Georgia Tech in Chemical Engineering, has managed hosting companies and now builds WordPress and Joomla Websites for small to medium companies full time.