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


Attracting a lot of visitors to your new website is 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. Also, you can know what is stopping visitors from accomplishing your goal.

With the help of web analytics tools, you can very well understand people’s behavior on your site and other information like 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:


Who is coming to your site?

Where are they coming from?

What are they doing on your site?

Are they doing what you want them to do?

Which campaign gave you more conversion?


Uses of web analytics2

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

In this post, we will be focusing 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 fall in this category. This is 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 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 to 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 for an example, an e-Commerce company may have a website and mobile App. Both the website and mobile App should be regarded as two different properties 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 ( the 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 names like yourcompany-website, yourcompany-App.
  4. Enter the name of the website you want to track.
  5. Choose a proper category that suits your website.
  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 elaborately 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 have this option.

Read the documentation of the theme you are using and use the option of Google Analytics tracking code 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 over one 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, for example, 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 ignore this step as of now. 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 the 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 which funneling stage has more leakage and fix it.

Enhanced Ecommerce Settings- Google Analytics(step1)

Once you have 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 your developer to implement on your site. Otherwise, you can hire someone from sites like UpWork, PeoplePerHour for the minimum per hour rate to do this task for you.

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 this plug in is installed, 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 data or not is by opening an incognito window and then going to your site.

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

If you have done these so 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 debug 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 again.
  • To check whether you have implemented Google Analytics correctly, install chrome extension and try. Google Analytics Debugger Google Chrome extension.

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’s 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 your account. So, it is recommended to have a backup of your website visitors data.

Create a new view in GA dashboard by following the given steps and create a filter in that view to 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 the 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 to the filter ( make sure it is easy to identify)
  5. In the type of filters option – Choose Predefined
  6. Choose to 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 that. For example, if your company IP address always starts with 74.125 then enter this.
  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 in case the range differs from the previous one.


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

Bharathidasan Moorthi

I am Bharathidasan Moorthi, an eCommerce Specialist & Analytics Expert from Bangalore, India. I help eCommerce sites, small- and medium-sized businesses and companies leverage digital marketing tools and strategies to boost their website traffic, sales and enhance their web presence. I come with over 4 years of experience involving different dimensions of digital marketing including SEO, PPC, Facebook Ads, Google Analytics, E-commerce, Conversion Rate Optimization, Tag Management and WordPress.

No Comments

Post A Comment

Time limit is exhausted. Please reload CAPTCHA.