Having Google Analytics code added to your WordPress site is crucial. Do doubt about it!
With Google Analytics installed, you are able to track your site visitors, analyze their behavior, and see what content they value most. All this - available for free.
When it comes to WordPress, connecting Google Analytics to your site can be tricky.
To help you out, I will cover two ways on how to install Google Analytics.
You can add Google Analytics code to your WordPress site by either using a plugin or by adding code manually. We will look into both ways.
But before we begin - we need to get Google Analytics code.
How to get Google Analytics code snippet?
First things first.
Before adding Google Analytics code snippet to your site you will need to get one.
If you don't know what a code snippet is, it's a small piece of code that you add to your site. By doing so, Google Analytics can actually receive data about your site visitors.
- To find this code, log into your Google Analytics account and click on the Admin (located in the bottom left corner).
- Under Properties, locate Tracking Info and click Tracking Code.
- You will see your Tracking ID displayed at the top and Global Site Tag available in the text area.
- Make sure to select all of the code in the text area and copy it.
Now, you are ready to add your Google Analytics code snippet to your site.
How to add Google Analytics to WordPress With Plugin
Before we start, let me clarify one thing.
Most WordPress experts are against using additional plugins to add Google Analytics. Why? Because you don't want an additional plugin to be loaded just for your tracking code to be added.
This is why I suggest you looking into multipurpose plugins that can do more than just adding a code snippet.
In this article, I have done just that.
Install Visual Composer and with the plugin activated, follow these steps:
- In your WordPress Admin navigate to Visual Composer Dashboard.
- Make sure to save your changes.
And that's it - you have added your Google Analytics code to WordPress.
How to add Google Analytics to WordPress Without Plugin
If you are not that much into plugins, there is a way to add Google Analytics code to WordPress via code.
Before you do that, make sure to have your Google Analytics code ready. You can learn how to retrieve the Google Analytics code snippet above.
To add the Google Analytics tracking code, you will need to modify your theme files. Not to mess up things, I highly recommend you to create a child theme for that.
To proceed, follow these steps:
- To start modifying your theme, in your WordPress Admin navigate to Appearance - Theme Editor.
- There you will have an option to modify different theme files.
- The Google Analytics tracking code should be inserted in the header part. For that, we will need to locate your Theme Header file called header.php.
- Once located, copy your Google Analytics tracking code right before the </head> in the Editor.
- Make sure to click Update File to save your changes.
That's it - you're done!
There are two ways how to add Google Analytics to WordPress which may be confusing at the very beginning and very straightforward as you know them. We have looked into both.
Whatever you choose is up to you.
The most important part is that you need Google Analytics connected to your site to gather, analyze, and understand your traffic.
This can give you valuable insights. And, as you proceed, you can look into more WordPress content analysis tools to get insights.