How To Add Google Analytics To WordPress

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.

  1. To find this code, log into your Google Analytics account and click on the Admin (located in the bottom left corner).
    Google Analytics Menu for Admin
  2. Under Properties, locate Tracking Info and click Tracking Code.
    Locate your tracking code under Google Analytics Properties
  3. You will see your Tracking ID displayed at the top and Global Site Tag available in the text area.
    Google Analytics Tracking ID and code snippet
  4. 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.

Spoiler alert.

In this article, I have done just that.

We will use Visual Composer Website Builder which, apart from helping you to design a site, allows you to add custom CSS and JavaScript to your WordPress site globally.

Install Visual Composer and with the plugin activated, follow these steps:

  1. In your WordPress Admin navigate to Visual Composer Dashboard.
    WordPress Admin panel and Visual Composer Dashboard
  2. Once in the dashboard, use a sidebar menu to open CSS, HTML & JavaScript.
  3. Scroll down to the Custom HTML and JavaScript section and paste your Google Analytics code in the head text area.
    Google Analytics code in Visual Composer Custom JS
  4. 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:

  1. To start modifying your theme, in your WordPress Admin navigate to Appearance - Theme Editor.
    WordPress Appearance Theme Editor
  2. There you will have an option to modify different theme files.
  3. 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.
  4. Once located, copy your Google Analytics tracking code right before the </head> in the Editor.
    WordPress theme header.php in Theme Editor
  5. Make sure to click Update File to save your changes.

That's it - you're done!

Conclusions

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.

Want To Get More Articles Like This?

Be the first to know more news, updates & web design tips from Visual Composer.