Google Analytics is one of the most powerful marketing tools used in monitoring and analyzing a website’s traffic. This tool is very easy to add on your website, even if you have no technical skills. And the best part, Google Analytics is completely free.
There is a paid version available that will cost you around $150,000 USD annually. But don’t sweat! You don’t have to buy the premium version unless you have an international brand with millions of visitors. The free version will work just as fine for everyone else.
For creating a Google Analytics accounts you will need:
- Account Name
- Website Name
- Website URL
- Industry Category
- Reporting Time Zone
Also, you will need access to your WordPress Dashboard.
We have divided this article into 3 parts:
Note: Make sure that you have an active Google Account. Having a Gmail email address or YouTube account also qualifies.
Step 1: Creating An Account on Google Analytics
To create an account simply go to Google’s Analytics official website.
Now if you already have a Google account just fill in your Gmail address and password. In case you don’t have an account you can create one by clicking on “Create Account”.
I will show you by creating a new account. You will have a screen like this once you will click on create an account:
You will receive a welcome message of privacy and terms. Click on “I Agree” button.
You will be redirected to Google Analytics homepage. You will see a Sign-Up button on the right side, click on it.
You will be asked to fill in some details of your website.
Before starting to fill the information make sure you have selected “Website” on top. Then enter your account name, website name, website URL, industry category, and reporting time zone. Finally, click on “Get Tracking ID” button.
Once you accept the terms and condition, you will see the interface of your Google Analytics account. You will get your tracking ID in the form UA–XXXXXXXXX-X and your tracking code.
You will have to use this tracking code to add google analytics to WordPress.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
window.dataLayer = window.dataLayer || ;
gtag('js', new Date());
You can easily access this tracking code any time in your Analytics account from the Admin tab > Tracking Information > Tracking Code.
Step 2: Add Google Analytics to WordPress
Once you have your Google Analytics account set up and your Tracking code, we can move on to using this code on your WordPress.
To add Google Analytics to WordPress website, you have four methods:
Let’s see the complete process for each method in detail.
2.1 Manually Add to The Theme
If you want to add tracking code manually to the theme make sure you use WordPress child theme to avoid overwriting the code with every update. It may look a little complicated but it is very easy, just follow the below steps:
- In your WordPress Dashboard, go to Appearance > Editor.
- On the right side, in theme files, scroll down and click on “header.php” file.
All you need to do is copy the tracking code from Google Analytics and paste it here. Be careful about where you add the code, paste it right before the </head> tag in the Editor.
Lastly, click on “Update File” and your Google Analytics tracking code will now be active.
Note: This tracking code will be inserted only to your active theme. If you change the theme, you will have to add it again.
2.2 Use a Plugin
If you are not a pro at WordPress file structure and PHP, using a plugin is a safe option for you. There are many plugins available that will allow you to add Google Analytics to WordPress. The process remains the same, after installing the plugin you just have to add your tracking code.
One of the best plugins that we have used is Google Analytics for WordPress by MonsterInsights. It has over 2 million active installs and is rated #1 most popular Google Analytics plugin for WordPress.
Follow the below steps to setup MonsterInsights plugin:
- Go to WordPress Dashboard > Plugins > Add New.
- Search for MonsterInsight. This is how it will look:
- Install and activate the plugin. You will see a new insight button on the left side panel of your WordPress Dashboard.
- This is how your insight screen will look:
- Simply click on the “Authenticate with your Google account” button.
- You will be asked to sign in to your Google account. Choose the account you want to connect your site.
- From the drop-down menu choose “All Web Site Data”, then click on “Complete Authentication”.
That’s it! You have successfully added tracking to your site.
Note: It might take 12-24 Hours to start tracking data. The data will appear under “Reports” section of MonsterInsights.
2.3 Use Google Tag Manager
If you have a lot of scripts, not just Analytics, you should use Google Tag Manager. It is a tag management system that allows users to update tags and code snippets.
To start using Google Tag Manager website you will have to sign up using the same account you used with Google Analytics. Add a new account page by providing a name for your account and click on the continue button.
Now add a Container. Use your site’s domain name and select web.
You will have an account, and you will see your container dashboard. This is how it would look like:
Now you will have to create a new tag, simply click on Add New Tag > Tag Configuration > Select Google Analytics.
Then select the track type and check the box next to “enable overriding settings”. Next, you will be asked for your Google Analytics Tracking ID.
Google Tag Manager will now give you a tracking code that you will have to add to your WordPress site. In case you don’t get this code simply go to Admin section on the top navigation bar > Container > Install Google Tag Manager. You will have your code, it will look like this:
Once you have this code you will have to add this to your WordPress site.
In your WordPress Dashboard, go to Appearance > Editor > Header.php.
You will have two codes from Google tag manager, add one to <head> section and the second snippet immediately after the opening <body> tag.
Note: These tags won’t go live until you publish the container. To do this go to your Google Tag Manager dashboard and click on the publish button.
2.4 Host Google Analytics Locally
Even though this method is not recommended by Google but doing so can help you in avoiding warnings like ‘leverage browser caching’. It helps you reduce your external HTTP. To integrate this you will need to install a plugin called Complete Analytics Optimization Suite by Daan van den Bergh.
Install and activate the plugin. Go to setting, click on the button of optimize analytics. This is how the dashboard will look like:
Enter your Google Analytics Tracking ID, and the plugin downloads and saves the analytics.js file to your server. Also, we recommend setting it to load in the footer.
Note: This plugin doesn’t work with any other Google Analytics Plugin. Make sure to uninstall/deactivate all other Analytic plugins.
Step 3: Check if the Google Analytics is Working
Once you are done adding the code to your site, the next step would be to check that Google Analytics is installed on the WordPress website and works well. The easiest way to do this is to go to Google Analytics > Real-Time > Overview.
Now open a page of your website, if the code is working properly you will see a bar and 1 active user right now.
Note: Sometimes it takes a few minutes or even hours before the data tracking begins.
If in case your Google Analytics data is not showing up, it’s not something to panic about. It can be fixed easily, just follow the below steps:
3.1 Review your Analytics code
It is important that you copy and paste your Google Analytics code directly from your accounts property settings. If you copy the code in another doc file and then paste it to your website from there, it might break your code. Check carefully that the code you have posted is correct, there is no extra spaces or change in punctuation.
3.2 Check for penalty warnings
Google is paying a lot of attention to websites that might be using some black-hat SEO techniques to rank on SERP. If you have some malicious code or virus on your website or you are not using HTTPS, there is a chance Google has penalized your website.
This will lead to a huge drop in traffic which you might be confusing with Google Analytics is not tracking your traffic.
Google Analytics is an extremely useful tool for your WordPress site. In the above article, you saw 4 methods to add the code to your site. You can add it to your site by simply using a plugin, Google Tag Manager, add it to your current theme or you can also host it locally.
And once, you have successfully added Google Analytics to your site, you can go ahead and create different profiles, create objectives or set up events tracking. It will help you analyze your traffic and improve your conversion rate.
Although be sure to make your Google Analytics compliance to GDPR. You can check out our article on making your WordPress GDPR Compliance.
If you face any problem with your Google Analytics account, you can always talk to our WordPress experts.