Knowing how visitors interact with your website helps you to constantly optimize and determine how well your traffic generation efforts go. On one hand, WordPress has an in-built stats tracking feature which provides statistics at a glance such as new posts, likes, and comments.
Table of Contents
On the other hand, the need to know how many people are browsing your website or which are your most popular pages makes you feel that there`s room for more. Luckily, Google Analytics includes far more advanced features. Some of them helps you keep track of:
- Who visits your website
This gives you insights about the geographical location of your audience, which browser they used to access your website, their screen resolutions, and more. Having this information will influence the design process of your site with speed and usability factors in mind.
- What they do on your website
You can track the pages your visitors land on your website, how long they stay on it, and how frequently they come and leave the website. By using this information, you can optimize your pages and content to reduce the bounce rate by increasing page views, which is a breath of fresh air to your SEO efforts.
- When they visit your website
You can choose the time of the day you want to publish your posts after analyzing the peak hours in the day for your website. You can even schedule your posts to meet that time if the time zone isn’t compatible with yours.
- Where they arrive on your website from
It’s important to understand what sources are sending the traffic most. Were they referred from a social media website, a referral link from another site, or from a search engine? Your information about specific sources users are coming from will help you maximize the potential of the traffic that you get.
In this article, we will look at a few different ways you can install Google Analytics on your WordPress website, by using various WordPress plugins, manually installing the tracking code into the WordPress theme, or inserting the code by using different methods.
But before that, check out the video below which explains pretty much what Google Analytics is all about and how you could use it not only to gather data about your website visitors but to also take action to convert those visitors into your customers:
Getting Started
Now that you know what Google Analytics is and the importance of having it run in the background, it’s time to set it up. You need to have a Google account in order to use this tool, so if you don’t have one, sign up here.
Step 1: Visit https://analytics.google.com. Once you are signed in, you will be prompted to sign up for Google Analytics with your Google account.
Step 2: On the next screen, you will be asked to choose between a website or a mobile app. Make sure Website is selected. Enter the rest of the information required on the page. These includes your Account Name (Use any name you like), Website Name, Country, Time Zone, etc. Also, review the data sharing options in order to properly decide what to let Google have access to.
Once you’ve entered all the required information, click on the Get Tracking ID button. You will be provided with the terms and conditions of the service which you must agree too, so click the I agree button.
Step 3: On the next page you will be presented with your Google Analytics tracking code and ID. Save them, as you will need to enter them in your WordPress website later. Leave the Analytics browser tab opened till you’ve installed the code on your website.
Implementing Google Analytics Into a WordPress Website
We’ll look at 3 different ways to add the Google Analytics tracking code to your website. Whichever method you choose, the objective is adding some lines of code to your website’s header.
Method 1: Google Analytics Tracking Code via your WordPress Theme
Many of you are probably using premium WordPress themes for your website. You should know that many of them have built-in places for adding JavaScript or CSS code. They’re usually located inside the theme options panel. Let’s take the themes that we build here, at DeliciousThemes. In the Dazzle theme, for example, you`ll find a spot at Appearance->Delicious Options->Custom JS & CSS: Footer Custom JS. What you have to do is to simply copy and paste your GA tracking code inside the field. So before checking out the next methods, verify that your theme has such a built-in feature.
Things could be even easier for you. Another example is from the Patti theme, where you just have to place your UA tracking ID inside the theme options panel(Appearance->Theme Options->General):
Method 2: Google Analytics Tracking Code via a WordPress plugin
Using a WordPress plugin is one of the right ways to add Google Analytics to a WordPress website. There is a myriad of plugins you can use here like GA by MonsterInsights (Formerly known as Yoast Google Analytics), GoogleAnalytics, Google Analyticator, and more.
For this method, we’ll assume you’ve installed GoogleAnalytics by MonsterInsights. This plugin is one of the most powerful analytics WordPress plugins which is also very easy to configure and use.
Step 1: Navigate to the Settings section under the Analytics menu.
Step 2: Authenticate your Analytics Account by either signing in with Google or manually entering your user account code (Tracking ID) under the General Settings.
To authenticate with your Google Account, click on Authenticate with your Google Account button, go through the prompts so that your account can be linked to. If you prefer to manually enter your user account number, just check the Manually enter your UA code box and paste your Tracking ID (begins with UA-).
Method 3: Google Analytics Tracking Code via Injection WordPress Plugins
There are several plugins that add code to the header and footer sections of your website, like Header and Footer, Header and Footer Scripts or Ad Injection. These injection plugins insert your code snippets in the right places. This way, they’re preventing any data loss if there’s a theme update or a change of theme. You can also insert different codes and scripts from other services using this method. For this method, we`ll be exemplifying the Header and Footer plugin.
Step 1: Go to Settings >Header and Footer.
Step 2: Copy and paste your Google Analytics code in the Scripts in Header(Every Page) box.
Step 3: Click on the Save button at the bottom of the page. And that`s all!
Method 4: Manually Implementing GA via a WordPress Child Theme
Using a child theme follows WordPress best practices related to customizing WordPress themes. Child themes eliminate the need to edit core WordPress files making your life easier when updating the main theme. There are two different ways you can add the tracking code:
- By adding the GA tracking code to the header.php file
Step 1: Copy the header.php from the parent theme directory into your child theme directory.
Step 2: Edit the header.php file from the child theme to include the tracking code before the closing </head> tag and save the changes you made to it. And that should be all!
- via functions.php file
This one is a bit tricky but it’s a way to do it. Into the child theme, create a file called googleanalytics.js and paste inside it the tracking code, without the <script></script>
tags.
(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','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-00000000-1', 'auto'); ga('send', 'pageview');
Now create a new file called functions.php and add inside it the next code:
&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;?php // Function to add googleanalytics.js to the site function themeslug_add_google_analytics() { // Register googleanalytics.js file wp_register_script( 'themeslug-ga', get_stylesheet_directory_uri() . '/googleanalytics.js', false, '1.0', true ); // Enqueue the registered script file wp_enqueue_script('themeslug-ga'); } add_action('wp_enqueue_scripts', 'themeslug_add_google_analytics');
What does the code mean? So we create a file in which we place the GA tracking code, then enqueue the file via wp_enqueue_script();
in the child theme`s functions.php file.
If you successfully followed any of the above methods, you should immediately see data appearing in your Insights Dashboard. If not, give it a few minutes or check again in a few hours after you’ve reinstalled the tracking code. When you head back into Google Analytics, click on the Reporting tab to see the data display. The Audience Overview section will load by default on subsequent logins to Google Analytics.
To help you better understand the metrics, you can hover over any of the metric names and a pop up will appear explaining what the metric is.
Further reading and resources
- GoogleAnalytics Udemy Training Course For Beginners
- GoogleAnalytics Help Center
- 6 Advanced GA Tricks That All Site Owners Should Know
- Troubleshoot common GA tracking setup mistakes
Summing Up
Setting up Google Analytics on your WordPress site doesn’t have to be difficult if you followed any of the above methods. Google Analytics is currently the most powerful free analytics tool available. Whether you are a newbie or a WordPress power user, using Google Analytics for tracking your website will provide you the data for taking action and getting the most out of it.