If you’re building – or have just built – a website then there’s a good chance you’ve done so using WordPress. As of July 2017, 28% of websites used WordPress as their content management system and with around 500 new WordPress sites being built every day, no other CMS even comes close to rivalling its popularity.
WordPress owes its success to the platform’s inherent versatility, which even novice users can take full advantage of through the application of plugins. Site owners can use plugins to achieve a wide range of things, from aesthetic changes on the frontend to backend tasks that would otherwise require a specialist web developer.
Plugins offer flexibility but they can also cause issues if they are not properly maintained or the function of one active plugin conflicts with the function of another. Because of this, many WordPress users avoid installing plugins unnecessarily and will look for alternative methods of achieving what they want before falling back on a plugin.
Google Analytics integration is a great example of a task that is often left for plugins to resolve but can be carried out safely, quickly and easily without one. Installing the Universal Tracking code on a WordPress site without a plugin requires editing the header.php file, which can be done simply by logging into your site’s admin panel.
Any exercise involving this level of code can be intimidating to someone unfamiliar with HTML or PHP, and we’d be lying if we said there was absolutely no risk of something going wrong. This is why we always recommend backing the site up before directly making any changes. However, just because something seems daunting doesn’t mean it’s not also straight forward, and we’re certain you’ll see what we mean if you stick closely to the following steps.
Finding Your Google Analytics Universal Tracking Code
Google Analytics provides site owners with a wealth of data that can be used to monitor a website’s performance and help guide it toward success. To take full advantage of what it has to offer, all you have to do is add a few lines of code to your site. Best of all, it is completely free so you have nothing to lose.
If you have not already got a Google Analytics account setup, here’s how you go about getting one. You’ll be surprised by how quick and painless it is:
Step 1: Visit analytics.google.com and click “Sign Up” to start using Google Analytics.
Step 2: Fill in the New Account form as accurately as possible. If your website does not have an SSL and is currently using HTTP encryption but you intend to HTTPS encrypt it later on, don’t worry. This can be changed at any time.
Step 3: Opt in or out of the four Data Sharing options presented. These include:
- Sharing your site data with Google to help improve its products and services
- Contributing your site data anonymously to assist with benchmarking and publication
- Allowing Google tech support to access your analytics when they deem it necessary
- Enabling Google marketing & sales specialists to access your analytics when they deem it necessary
Your data sharing settings can also be changed at any time.
Step 4: Click ‘Get Tracking ID’
Step 5: Accept Google Analytics Terms of Service Agreement by clicking ‘I Accept’.
At this point, you shall be taken to a page with a Tracking ID number. The Tracking ID will look a little something like ‘UA- XXXXXXXXX-1’ and below it shall be some script in a box. This is the script that you will need to add to the code on your site.
Step 1: Login to Google Analytics
Step 3: Select ‘Tracking Info’ under the middle column titled ‘Property’ and then click on ‘Tracking code’. This will take you to the area with your Tracking ID number and all you have to do is copy the script in the aforementioned box below the ‘Website Tracking” subheading.
Integrating Google Analytics On WordPress Without A Plugin
Once you have everything in the box copied, applying it to the site is all that is left. As stated earlier, this process is easy, not foolproof, and we do strongly recommend taking a backup of the site just in case you accidentally make a mistake.
Before we begin, please note that there is no need to delete any bit of script at any stage in this process. If you do happen to remove some text or even suspect that you might have done without noticing, refresh the page without saving and begin again. It should not take more than a few minutes, so having to start over again is a mild inconvenience.
Step 2: Click ‘Appearance’ on the left-hand menu and then select ‘Editor’
Step 3: Under the ‘Templates’ subheading on the right-hand side of the page will be numerous .php files and you only need one: ‘header.php’. The easiest way to find the template is to press CTRL + F and type ‘header.php’ into the search bar that appears. This will locate the correct file on the page for you.
‘header.php’ is often the anchor text you need to click on in order to edit the template, but it isn’t always. When it’s not, ‘header.php’ will appear in brackets directly underneath the template file you need to edit. This all depends on the theme that the site is using.
Step 4: You should now be presented with a wall of text, but don’t let it put you off. You’re on the home stretch. Pressing CTRL + F once again, type </head> into the search bar click on either of the two arrows next to it.
Step 5: The script you have copied from Google analytics needs to go above </head>, so the best and safest thing to do is to simply paste the Universal Tracking Code in so that </script> sits on the line directly above </head>.
Step 6: Scroll to the bottom of the box and click ‘Update File’.
That’s it. Your job is done and Google Analytics has been safely integrated to your WordPress site without the help of any plugin. Google Analytics should start to receive data from the site instantly and you’ll be able to see it by logging after waiting 24 hours.
If your WordPress site is an e-commerce website, then you’ll probably want to enable Google Analytics e-commerce tracking. Applying a tracking code in the way we have just covered will not allow Google to collect e-commerce data from a site, as there are other, more complicated steps that need to be carried out. In this instance, we would recommend using a WordPress plugin such as ‘Enhanced Ecommerce Google Analytics Plugin for WooCommerce’ to ensure Google Analytics is properly integrated.