How to Implement Google Analytics Code in WordPress?
Google Analytics can be a great tool for collecting interesting data about your website. However, some may find implementing it on a WordPress site a bit difficult.
Multi comes to the rescue! With a simple step-by-step tutorial, we will show you how to get to know your viewers better.
In this article, you’ll learn:
- Why is it super helpful to monitor your site’s activity
- How to set up a Google Analytics account
- How to install Google Analytics on your WordPress site without any plugins
- How to install Google Analytics on your WordPress site with two different plugins
Let’s get started!
Why Your Website Needs Google Analytics
What is Google Analytics, anyway?
It’s a free software that can provide useful data by monitoring the activity of your website or app. It gives you a variety of information regarding your audience demographics and behavior, real time reports, or acquired traffic.
Whether you own a personal blog or an e-commerce business, you’ll be able to better understand your audience needs. This will lead to increased conversion rates and improved usability.
But how does that work?
For a better understanding of Google Analytics, we’ll look into some of the benefits first:
Discover Who Are Visitors of Your Website
You can collect information about your visitors’ demographics, such as ages, genders, or locations. You can also check which browser, language or screen resolution they use. Do they have JavaScript and Flash support? Are they new or returning users? What are their interests?
You can use this data to make sure your website is compatible with popular screen resolutions and browsers.
How Visitors Find Your Website
This explains how your website gets traffic. It provides important data on how did your users know about your website. With Google Analytics, we can distinguish many different web traffic sources. Those include direct traffic, organic or paid search, social media or referral traffic.
If you know which medium is performing well, you can adjust your marketing campaigns for a well-balanced growth strategy.
How Visitors Browse Your Website
Google Analytics is showing the time spent on each site by your visitors. But more importantly, you could even track each independent event. Events are user interactions, such as content shares, file downloads, searching, or even button clicks. These kinds of insights are a must-have for improving your website’s User Experience (UX).
What Pages Are Most Popular
What amount of time do users spend on each of your pages, and why? If you own an e-commerce site, you are aware that it is vital for you to know that. If you use a service like Google Analytics, it can analyze bounce and click-through rates to pinpoint potential issues. This way you optimize your content and increase page performance.
The conversions are the ultimate goal, right? Remember that it is now a standard to know when and why your users choose to buy or subscribe.
How to Sign up for Google Analytics
To connect Google Analytics to your website, you need to have a Google account first. Once you have that, you can add your site to your Analytics panel. It requires adding an individual tracking code to all your website’s pages. The tracking code is responsible for collecting data. Log in to your account through www.google.com/analytics/ and finish the account setup.
After setting up the account, enter the Google Analytics dashboard and copy your tracking code. We plan to use it in our next steps.
How to Add Tracking Code From Google Analytics in WordPress
Now you’re ready for installing Google Analytics tracking code in your WordPress page.
There are many ways to do that. You can choose to use a plugin or install it directly in the WordPress theme. We’ll go over both of those methods in the next part of the article.
What Is Best: Add Google Analytics With or Without a Plugin?
Now you might wonder:
Is it better to install Google Analytics with a plugin or directly in my theme? Will the plugin slow down my site? Which way is easier?
Here’s the thing:
We believe it should be up to you to choose the solution that suits you best. This article will explain both ways and present the strengths of both plans. This way you can make an informed decision that is right for you.
So let’s jump right in.
Install Google Analytics Code Without a Plugin
This is the most straightforward solution, however, it requires some changes in code. This option needs some more advanced WordPress skills, as you’ll need to edit php files. We also strongly recommend creating a child theme first. If you would edit the parent theme code, your changes will be lost after an update.
Another good practice is to make a backup before you make any changes in your theme’s code. If you’re not sure how to do a backup, you can ask your hosting provider or look up tutorials online.
So how to install Google Analytics without a plugin?
You have two options:
Option A: Edit the header.php file
If you insert the tracking code into your header, it will be present on all your website’s pages.
After creating the child theme, copy the header.php file from the parent theme. Paste the file in the child theme and start editing it. Copy your Google Analytics tracking code and insert it into the header.php file, before the closing </head> bracket at the end of the code. Make sure that your code is wrapped in <script> brackets for it to work properly.
Then just save the file and upload it back to your server.
Option B: Edit the functions.php file
Similarly to the first option, this requires you to create a child theme and edit one of the files. Adding tracking code to functions.php file will install it on all of the pages at once as well.
Copy your tracking code from Google Analytics dashboard. Then add this code snippet into the functions.php file:
<?php
add_action('wp_head', 'multi_add_googleanalytics');
function multi_add_googleanalytics() { ?>
// Paste your Google Analytics tracking code here!
<?php } ?>
After that, replace our comment with your Google Analytics tracking code, save the file and upload it back to the server.
Alternatively, both of those files could be edited directly in the WordPress dashboard:
Go to Appearance menu and Theme Editor section. From the right column, open the header.php or functions.php file. Add one of the corresponding code snippets to the right file and save your changes.
Remember:
Always make sure you create a backup before applying any modifications to php files.
Either way, after saving the changed files, Google Analytics should start the tracking process instantly. From now on, you gain insight into your viewers’ activity through your Google Analytics panel.
Install Google Analytics Code With a Plugin
The other way to add Analytics tracking to your WordPress site is by using a plugin. We recommend it as an optimal solution. No manual code modifications are required, so it’s a beginner friendly approach. Apart from that, you don’t risk losing your changes after updating your theme or switching to another one.
Now we will zoom in on top two of the available plugins that automatically add the tracking code to your WordPress website.
Install Google Analytics Code With Insert Headers and Footers Plugin
The first step is to install and activate the Insert Headers and Footers plugin. After the activation, from your WordPress dashboard go to Settings, and then to Insert Header and Footers page. On this page, you’ll be asked to insert the Google Analytics tracking code. You will find it in your Google Analytics panel.
After that, just click save and you’re all set. The plugin will automatically add the scripts into the <head> section of your page.
Install Google Analytics With MonsterInsights Plugin
The setup of the plugin is just as easy, but with MonsterInsights, you’ll gain many additional features. Those include access to some advanced Analytics statistics, file download tracking, custom event tracking, and more. It is definitely the most popular Google Analytics WordPress plugin. It’s also considered to be very easy to use by beginners, and the most comprehensive. MonsterInsights plugin is offered in both free and premium version.
Install and activate the plugin through your WordPress dashboard. When the activation is complete, a new menu item will appear with a label “Insights”. Click on it to enter the MonsterInsights plugin setup.
Follow the setup wizard’s instructions step by step, as it will guide you through the process. The setup manager will offer some premium add-ons and tools, such as WPForms’ contact form plugin, but they are optional.
You will be then asked to connect to your Google account so the plugin can install Google Analytics on your website. Again, the plugin will insert any necessary code for you, and very soon you’ll have access to your Analytics stats.
But here comes the really good part:
With MonsterInsights plugin, it’s easy to directly access your stats through the WordPress dashboard. On the right menu panel, just click Insights, and then Reports.
Summary
As you can see, there are many different ways to install Google Analytics in WordPress. We hope that our step-by-step guide has showed you how simple it is, whether you use a plugin or not. Google Analytics can be a really powerful tool for gaining a lot of insight into your blog or page users.
Which method did you prefer and why? Be sure to let us know in the comments below.
Also don’t forget to share this article if you found it useful!
Leave a Comment