How to Setup Google Analytics on WordPress

Many WordPress users struggle and don’t know how to setup Google Analytics on WordPress websites. But Google Analytics is a very important tool for your website’s growth.

Google Analytics is probably the best tool for gathering data about your website traffic. When it comes to optimizing your website and increasing traffic, a tool like Google Analytics plays a vital role. By using this tool, you can gain insight into how your audience utilizes your website. This will help you make informed decisions.

However, many people struggle to integrate Google Analytics with their websites. But thanks to some amazing plugins, you can easily install Google Analytics to your WordPress site. It is also possible to install Google Analytics manually, which might take some time. But the overall steps are really easy.

In this article, we’ll to discuss the importance of Google Analytics and learn how to setup Google Analytics on a WordPress website. We will show you 3 different methods of installing Google Analytics, of which 2 are completely code-free. You can follow any method that you like. So, let’s get started!

What is Google Analytics?

Google Analytics is a powerful tool that lets you analyze your website traffic. You can use this tool to get information like where your traffic is coming from, how your SEO is working on which keywords, etc. The most interesting thing about Google Analytics is that it’s free!

The way Google Analytics works is that it adds a code snippet, usually to the site header so that it’s present on every page. This code then logs data about each visitor to your page. It can log details such as:

  • Where the traffic is coming from
  • Which page they landed on
  • The time spent on a page
  • Which country the traffic is coming from
  • Also other demographics such as age, gender, etc.

These data can be segmented for more accurate details. The Analytics tool is so powerful that it not only shows the volume of your traffic, it also shows you their behavior. With all this information you will be able to make smarter business decisions. For example, you can find out what type of posts gain more views and conversions. You can then invest more time in publishing such content.

Get Latest Post Notifications!

Subscribe to our newsletter

How Google Analytics helps webmasters

Google Analytics is useful for all categories of websites. It helps you make data-driven decisions by showing you information on your web traffic. Here are some examples:

Who is visiting your website?

This is the part where Analytics shows you the geographical location of the people who are visiting your website. It also shows other information such as which browser your audience is using, their screen resolution, language, etc.

This information can be really useful as you can produce more stuff that gets more interest in specific locations. The resolution details help you to best optimize your website for those specific screens.

If the location from which your website is getting more views has a native language, you can use multi-language support on your website. In that way, your audience will be happy to know that this site is available in their native language.

Audience interaction on your website

The analytics also track your audience interactions on your website. You can see which page they view more, how long they stay on a particular page, the bounce rate of your website, etc. You can also find the information on which of the posts on your blog are the most popular and find out which posts receive fewer views.

With all this information you will be able to understand what kind of content your audience is looking for. 

The time of your audience visits

You can also track at what time of the day your audience visits your website. This helps you know the time when your traffic is the highest. If your time zone is different, you can schedule to post your content at that time of the day.

By utilizing this data, you can give your audience more content and your articles will have more views as soon as you post those.

How did people find your website

You can also see how your audience came to your website. It could be via search engines, direct links, referrals etc. It precisely shows you what percentage of traffic came from which source. 

That’s not all, Google Analytics breaks the stats down for each of the categories. For example, if your visitors are coming to your website via search engines, it shows you which search engines they are using.

There’s so much you can do with this information. If you see that your visitors are arriving at your website through Facebook referrals, then that means you have interesting content for the Facebook users. If your top referrals are from another website, then we are looking at a great partnership opportunity.

Now that you know how Google Analytics can help you, let’s learn how to setup Google Analytics on WordPress websites.

3 ways to setup Google Analytics

Adding Google Analytics to your WordPress website is very easy. However, if you haven’t done much coding, or haven’t worked with the code of your website, it might look a bit difficult. But there are plugins that can simplify the installation process.

In this article, we’ll show you how you can install Google Analytics in 3 different methods. The 1st method is by using the Google Site Kit plugin (recommended), the 2nd method is by using the Insert Header and Footer plugin. And finally, the 3rd one is the manual process.

However, a thing to note, in order to add Google Analytics to your website you need the following:

  • Signed up to Google Analytics account
  • Set up a web property to add your site to Google Analytics

If you haven’t completed the steps shown above, head over to the Google Analytics site and complete these steps first.

Integrating Google Analytics through Google Site Kit (Recommended)

Google Site Kit is a great plugin from Google. It connects Google Analytics, Search Console, and AdSense together and brings you all the data right to your WordPress dashboard. You can download the plugin from your WordPress dashboard, or from wordpress.org.

installing google site kit

Once you activate the Google Site Kit plugin, it becomes available on your WordPress dashboard. It is generally placed right under the Dashboard option. To initialize it, make sure you sign in with a Google account that has Google Analytics and Google Search Console integrated with it.

Once you’ve connected with Google Analytics and activated Site Kit, you will be able to see the analytics right on your WordPress dashboard.

google site kit on wp dashboard

You can also connect AdSense to Site Kit. Once your site is properly set up and you meet all the Google Adsense requirements, you can integrate it with your Google Site Kit.

Installing Google Analytics using Insert Headers and Footers Plugin

There’s a plugin that you can use to insert the Google tracking code in your WordPress header. The plugin is called Insert Headers and Footers which is developed by WPBeginner. This won’t be as easy as setting up Google Site Kit. Because you have to manually insert the tracking code within your WordPress theme header.

One thing to keep in mind before starting, since you’ll be making changes to the core files of your WordPress, it is a good idea to do a backup of your WordPress website. So, if something goes wrong, you will always have a backup to rely on.

First, you need to access your Google Analytics admin dashboard. To add the code to your WordPress theme, you need to copy a code called “Google Site Tag”. To get that code, follow the steps given below:

  • Log into your Google Analytics admin dashboard
  • Select Data Streams
  • Click on Add Streams and select ‘Web’
creating a new data stream in google analytics

A new data stream will be added to your website. You can see the new stream URL (URL of your website), stream name (name of your website), and a tracking ID for the stream. Scroll down and find “Global site tag” or “gtag.js” under Tagging Instructions.

copying gtag from a new data stream

Copy the code shown in the image above.

Now go back to your WordPress dashboard and then install and activate the Insert Headers and Footers by WPBeginners. Once the plugin is activated, open it from the Settings option in your dashboard.

pasting gtag using headers and footers plugin

The plugin has a simple interface. It gives you 3 boxes, one for putting in codes in your header, the other one for putting scripts in the body, and, the other box for putting codes in your footer. Paste the Google Site Tag in the header section and click on Save.

That’s all you have to do. It’s a bit easier than the manual process as you don’t have to find the header.php file and put in the code manually. The plugin does that for you.

If you follow this step, you won’t be able to view your web analytics like Google Site Kit. To view the statistics and analytics, you have to log into your Google Analytics page.

How to setup Google Analytics on WordPress websites manually

You can also set up Google Analytics manually. However, this process might look a bit complicated, but the steps are really easy to follow. If you want to go for the manual approach we recommend using a WordPress child theme. Otherwise, your code will be overwritten every time you update your theme.

Installing Google Analytics on WordPress manually is almost identical to using the “Insert Headers and Footers” plugin. The only difference is, that you have to manually find your theme header file and paste the code.

First, you have to copy the “Global site tag” or “gtag.js” as you did in the previous method. We are going to use the Twenty-Twenty-One theme for this demonstration.

Once you copied the gtag.js code, go to your WordPress dashboard. From your WordPress dashboard, go to Appearance > Theme Editor. This is the codebase that creates your WordPress theme. Now, from Theme Editor, find Theme Header (header.php) from the side menu. 

Based on what theme you are using, the theme files might look different. But almost every theme has a header.php file. Once you find the file, click on it and it will open in the editor

Once the header.php is opened in the editor, find the head tag and paste your code right above the </head> tag. See the screenshot below:

adding gtag in header.php file

After you have pasted the code, click on Update File to save the changes. Congratulations, you have successfully added Google Analytics to your WordPress website manually. You can also add Google Tag Manager to simplify your site tracking system.

But in this step, you won’t be able to view your analytics on your WordPress dashboard. To view your web analytics, you have to log into your Google Analytics page. From there you can view many details of your web traffic.

👉 Video: How to Add Google Analytics in WordPress

Conclusion

If you want to create a successful website with a lot of traffic and conversions, Google Analytics can help you achieve that. This tool provides you with finer details about the traffic of your website. It helps you gain insight into the audience of your website. And the best thing about it is, it’s free!

There are a lot of premium analytics products like Google Analytics that you can use, but most of these might be expensive especially when you are starting out. So Google Analytics is perhaps the best option for many people out there.

We recommend you spend a little time with the statistics, get used to the interface, and then start tracking your audience interactions. Investigate the numbers and make data-driven decisions to boost your traffic.

We hope you understand how to setup Google Analytics on WordPress websites. If you are having any difficulties, let us know in the comments section.


Disclaimer: This post may contain affiliate links and we may receive a small commission if you purchase something by following them. However, we recommend services/products that we believe good to serve your purpose.

Staff Author

Staff Author

A team of WordPress enthusiasts led by Arafat Bin Sultan, a seasoned professional with over a decade of experience in tech blogging, content marketing, and video creation.

Articles: 252

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from WPGIZ

Subscribe now to keep reading and get access to the full archive.

Continue reading