Add Google Analytics Tracking Code to WordPress Site: A Step-by-Step Guide

Attracting lot of visitors to your new website never going to be useful if they are not doing what you want them to do. Understanding more about website visitors will help you to produce relevant content and can know what is stopping them to do complete the goal.

With the help of web analytics tools, you can very well understand people’s behavior on your site and their gender, device, location, the page they have seen, etc.

These data and reports will help you to take smarter and efficient decision in optimizing your ad spends and marketing activities. You can also understand what is stopping your customers from buying your product or opting in for your newsletter.

Some of the things that you can learn are:

Where are they coming from?

What do they on your site?

Who is coming to your site?

Are they doing what you want them to do?

What they are doing on your site?

Which campaign gave you more conversion?

Uses of web analytics2

Still many people are not using any of the web analytics tools because they don’t understand the importance or don’t know how to use it. The truth is, installing analytics tools like Google Analytics on your site is easy.

In this post, we will focus on creating Google Analytics account and setting up GA on a new WordPress site.

Why Google Analytics

Many analytics tools are available in the market. Such as,

However, Google Analytics has its advantages.

10 million websites use Google Analytics, and you too should use. Because it is,

  • Powerful
  • Easy
  • It is FREE!

If you ever wondered how Google Analytics (or any analytical tool) collects data, the answer is a small JavaScript code (you need to add this to your site) and cookies.

Cookies are the small piece of information stored on a computer once a visitor visits your site. These cookies are used to store different information about the visitors, such as last visited date, login details, browsing history, and time of the visit, etc.

Creating Google Analytics Account

All you need is a Google account to create Google Analytics account. You can also use your business email id if you have bought it with Google.

First, go to then search “Google Analytics” and you click the relevant link or directly visit the following link

Search Google Analytics

Now click on Sign Up option and log in to your Google account.

Steps involved in google analytics setup - 3 steps

Before proceeding the next step, understanding the Google Analytics account structure is a must.

Google Analytics is organized into three levels: Account, Property, and View.

Account: Account name implies the company name. Within one Google Analytics account, multiple accounts can be created (up to 100).

Property: Each account(company) can have multiple web properties (up to 50) such as website, mobile app, kiosk, etc.

Say example; an e-Commerce company may have a website and mobile App. Both the website and mobile App should become as the different property under one account.

Views: Each property can have multiple views (up to 25). Views used to separate and filter the original data flowing into the data. ( You can create filter to exclude people visiting from particular range of IP address).

Google Analytics - Account StructureIn the next step, enter details of the website of mobile app you want to track.

Google analytics - Account Creation1

  1.  Choose what you want to track. Either the website or mobile App (Default option is website).
  2. Enter the account name; you can use your company name for this.
  3. Each account/company can have multiple properties such as mobile App and website. Give name like yourcompany-website, yourcompany-App.
  4. Enter the website name of which you wanted to track.
  5. Choose a proper category it suits your site.
  6. Select the time zone you want the report to appear and click submit.

Once you complete the above steps, you will be provided with the Tracking ID.

Google Analytics Tracking ID

It is unique to the property which you have created. Below that there will be a tracking code which you have to install on your site.

Depending on the platform you have used to build the website, it will change. We will discuss in deep how to add tracking code to the WordPress site.

Different Ways to Install Google Analytics Tracking Code To WordPress Websites

1. Theme Options

Most of the paid WordPress themes give the option to add Google Analytics tracking code inside the theme settings itself. But not all themes having this option.

Read the documentation of the theme you are using and use that option if you have one.

2. Plugins

WordPress plugins help to customize website quickly. Many plugins are available in the WordPress free plugin directory for adding tracking code to the site.

Some of them are Yoast Analytics, Google Analyticator, Google Analytics Dashboard for WP, WP Google Analytics.

Yoast Analytics plugin has 1+ million active installs with the rating 4 out of 5. This plugin has options for excluding logged in users, tracking external links, and tracking downloads such as PDF, DOC file.

You can also link to your GA account so that you can see your Analytics data in your WordPress dashboard itself.

Configuring this plugin is quite easy. After you have installed this plugin, navigate to “Analytics” option in the WordPress dashboard menu, then click “Settings”.

Yoast Analytics - Configuring with tracking ID

Two options provided to install the tracking code.

  • Connect your GA account, it will automatically take the code and will insert on the website (you have to use this feature to use dashboard option).
  • The second option is to enter your UA code (Tracking ID) manually.

You can also select the settings you want like ignoring users, if you are not clear, just leave default settings and save changes.

3. Header and Footer Plugin

Using this plugin, you can add anything in header and footer of your site; such as a script to your site such Google Analytics Tracking, Facebook Pixel, etc.

Post installation of this plugin navigates to ‘Settings” in WordPress dashboard then Just copy and paste the tracking code. It will add that code to the footer of every page of your site.


Always insert the scripts in the footer (Adding any scripts to the header of the site may slow down website speed).

4. Add Code Directly

If you are familiar with editing code, you can use this option, but this one is not advisable.

Open the Functions.PHP (find it in the theme editor section) file in the theme section. Copy the GA tracking code and paste after <body > tag.

5. Google Tag Manager

Google tag manager helps you to organize tags on your site. As a beginner you can safely leave this step as of now and later, you can switch to this. You can easily Get Started with Google Tag Manager with the guide by Conversion XL.

When you want to add more tags, that might hurt your site’s speed and performance. But this tool will help you optimize site’s performance by reducing loading times drastically.

Site speed will affect your conversion. Amazon says, for every one-second delay in page loading it affects one percent conversion.

Ecommerce Tracking Through Google Analytics

The universal basic tracking code is limited to the data collection of the visitors.  If you are running an eCommerce store, you need to add extra code and settings.

This additional code will help to know the product performance and the customer journey from visiting category page to the checkout page.

For that, you need to enable eCommerce tracking in Google analytics.

Navigate to Admin section of your GA dashboard, then select Ecommerce Settings.

By default related products tracking will be in disable mode, turn on that option. Proceed to next step.

Ecommerce Setup in Google Analytics-Step1

In the next step, enable the enhanced eCommerce reporting option. Make sure you give labels to the customer navigation path in your online store which customer has to go through to complete order.

Usual customer path would be Category page, Product page, Cart page, Checkout section and thank you page.

Define the customer funnel on your site so that you can understand on which funneling stage has more leakage and fix it.

Enhanced Ecommerce Settings- Google Analytics(step1)

Once you completed the above step, you need to implement code to send data from your site to Google Analytics.

You can send the following link from to your developer to implement on your site. Or you can hire someone from sites like UpWork, PeoplePerHour for the minimum per hour rate.

If you have used WordPress WooCommerce to build your online store, Enhanced Ecommerce Google Analytics for Woocommerce Store plugin, enables you to do the same.

Once install this plugin you will be getting options in the settings and you can configure it quickly.

Enhanced Ecommerce google analytics- Woocoomerce settings

Enter your UA code and website name, check Add enhanced E-commerce tracking code option.

Unselect “Add universal tracking code” as you have already installed that code, you need not add again.

How to Check Google Analytics is Collecting Data or Not?


Checking number of users - Real time data in google analytics

A simple way to check whether Google Analytics is receiving or not is, open your site in an incognito window and go to your site.

Now, you can see 1 active user in Real-Time dashboard of Google Analytics which means GA is receiving your website data correctly.

If you have done this far, congratulate yourself. You have installed Google Analytics code in your website successfully.

But sometimes you might not have got the data even though you completed the above steps. Learn how to debugging the google analytics tracking code in the next section.

Debugging Google Analytics Tracking Code

If you are not receiving data, it might be because of the following reasons.

  • The code might not have implemented correctly. You might have made some typo error, check with your Tracking ID and the tracking code added to your site.
  • You can check whether you have added a code or not. Clear cache and try
  • To check whether you have implemented Google Analytics correctly, install chrome extension and try. Google Analytics Debugger for Google Chrome.

Get Clean Data – Filter Internal Traffic

By default, Google Analytics will create one view name “All Web Site Data” which contains data about all the traffic to your site.

But when you want to understand about all visitors/customers you must exclude traffic from your company internal people like your developers, marketers, and admins.

For that, you need to create a filter to remove those visits.

Google Analytics(GA) gives the option to filter the visits based on attributes you specify, but this option will permanently delete data from you account, so it is advisable to have a backup of website visitors data.

Create a new view in GA dashboard by following steps and create filter in that view to a filter out traffic from your company.

Creating New View In Google Analytics

  1. Click Admin
  2. Select Views, then click new view
  3. Give name to new reporting view and select Time Zone
  4. Click Create view.

Adding new view in google analytics

Next, select the new view you have created, and create a new filter using following steps.

Creating New Filter in Google Analytics

Google Analytics - Filter Option

  1. Click on the Admin
  2. Then navigate to Filters (In view section)
  3. Click Add Filter to create a new filter. Google Analytics - Internal IP Filter
  4. Give name of the filter ( make sure it is easy to identify)
  5. In the type of filters option – Choose Predefined
  6. Choose exclude option for removing traffic
  7. Select the “Traffic from the IP Address”. As we are going to eliminate traffic from you company IP address range.
  8. Select “Begins With” to cover the wide range of IP, that covers over all your company IP address.
  9. You can find your IP address by searching “What is my IP” in Google. If your company’s overall IP is not changing in first two part of IP address, then enter is. For example, if your company IP address always starts with 74.125 then enter that.
  10. Next click Save. Now you have successfully created a filter to exclude traffic from your company.
  11. But make sure that, you often check this IP address range make if the range differs from the previous one.


Enjoy analyzing. Struck with any of the above steps? Or have any questions about setup google analytics? Comment here or mail me.

Bharathidasan Moorthi
[email protected]

I am Bharathidasan Moorthi, a Digital Marketing Professional from Bangalore, India. I help businesses to create and improve their digital marketing strategy to increase traffic and sales. I have 3+ years of experience in SEO, PPC, Facebook Advertising, Google Analytics, E-commerce, Conversion Rate Optimization, Google Tag Manager and WordPress.

No Comments

Post A Comment

Time limit is exhausted. Please reload CAPTCHA.