How to Add Google Analytics to a WordPress Website

Whether it is a blog, simple personal website or business portfolio that you are building with WordPress, you are doing it for a reason. You want people to be able to get to the content that you have presented online. Without the audience, your web project doesn’t serve its purpose. So one way or another, you need to start understanding people that visit your domain.


Who are the individuals that opened your site? How many of them visit your site in a month? Do they come back and how long do they keep your site opened? Did they originate from a search engine, social networking site or maybe they manually entered the address? These are just a few important questions that every website owner should ask themselves on a regular basis.

Asking the questions is the easy part; but how do you answer them?

What is Google Analytics?


Google Analytics is a very powerful online web analytics tool that can track the behavior of a website and all visitors that are part of it. Although not the only of a kind, Google Analytics is definitely the most popular tool for the job. People use it worldwide to get stats about sites ranging from simple blogs to corporate portals that generate millions of monthly users.

The service was introduced in 2005. It offers numberless reporting tools; from showing real-time visitors, locations, and technology to eCommerce data that can track the number of sales.

How does it work?

Google Analytics requires everyone to open a free account that gets a unique tracking ID code. After putting the code on a site, Google Analytics runs every time that a visitor loads any of the associated pages.

This tracking code then runs in the clients’ browsers and tracks the behavior. Although this wasn’t possible a few years ago, the data is usually sent in real time to the service which quickly interprets all the signals. It allows you to immediately see how many users are loading your site and all the details about their visit

How to add Google Analytics to your site manually


Before you get to place the tracking code to your site, you will need to create a Google Analytics account:

  • Navigate to Google Analytics
  • Sign in with your Gmail account
  • Click the “Sign up” button
  • Choose the “website” option
  • Enter the information like the name of your account, website name, URL, country, and the time zone
  • Agree to the terms and conditions

After completing the steps, the account should be ready, and you can now start connecting it to your website. Just like with anything in WordPress, you can get the job done in several different ways.

If all you want is to connect the service to your site, the manual way will be more than enough. You will always have to navigate away to Google Analytics pages to start analyzing.

Method  #1

Google Analytics code needs to be placed in the header.php file which is loaded on every page of your site. So it makes sense to edit the file and paste the code on the right spot:

  1. Go to Google Analytics
  2. Click on Admin -> Tracking Info -> Tracking Code
  3. Copy the entire code starting and ending with <script></script> tag
  4. Go to Appearance -> Editor
  5. Find header.php file and edit it
  6. Paste the tracking code right after the <body> tag
  7. Save changes

Method #2

The other method allows you to add the same code to the header of your website via the functions.php file:

  1. Go to Appearance -> Editor
  2. Edit functions.php file
  3. Copy and paste the following code: 
<?php
add_action('wp_head', 'googleanalytics');
function googleanalytics() {

// Paste your Google Analytics tracking code here (the one that starts and ends with the <script> tag)

} ?>

Conclusion


You can run a blog, shop or any site without a Google Analytics account. But if you choose to ignore the popular analytics tool, it’s like you are admitting that you don’t care about the project. Without knowing statistics about the site, you can just take guesses which probably won’t be even close to what’s actually happening on your site.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!