What's WP
Find Everything Related to WordPress - Best Tutoriasl on WordPress!
How to Add Google Analytics to WordPress for Website Tracking

How to Add Google Analytics to WordPress for Website Tracking

We have already shared a lot of useful tips helping you increase the traffic and page views of your site easily. However, how do you estimate the value these tricks put into your site? After all, you need to keep tracking the site traffic, and then optimize the website accordingly. In this case, the powerful tool of Google Analytics can come into play. In below, we come out the detailed tutorial to guide you add Google Analytics to WordPress websites for traffic monitoring.

Google Analytics helps users analyse visitor traffic, including who visit the site, what they do, when they visit, where they come from and what content they are interested in. It is the best way to show customers’ preference through ads, videos, websites, social tools, and smartphones, which makes things much easier to serve for the existing customers and attract new ones.

Why Use Google Analytics

This tool is an online service offered by Google, which is used to monitor the traffic of a website and generate the detailed statistics for users. It allows webmasters to know the daily views, traffic source, and conversion rate clearly via a lot of objective referrers like search engines, social networking platforms, and some referring sites.

With it, you can

  • Have an insight of the grow pace of your website.
  • Have a complete picture of your audience and their needs.
  • Know the devices and routes that take people to your site.
  • Know how people interact with your posts.
  • Track multiple websites at one time.
  • Keep pace with your site without spending even one penny.

Frankly speaking, one of the main purposes of Google Analytics is to tell you who have visited or are visiting your website. Thus, you can know where your audiences come from, which browsers bring them to you and some other sensitive information, such as their native languages, the screen resolution of their browsers and so on. Even, you can know whether these browsers allow the Flash support and the JavaScript support. These statistics are really important. By knowing them, you can customize your website design to make your website compatible with your audiences. For instance, you should remove the Flash elements if most of your readers do not have the Flash support.

In addition, with this tool, you can easily know what your visitors have done when browsing your website. Thus, you can know which posts retain them longer, which posts have the higher bounce rate and which posts get the most click through rate.

Lastly, by learning how your readers reach your website, you can better promote your site on the social media platforms and optimize the site for the higher online ranking.

Sign Up A Google Analytics Account

First of all, you need to create a Google Analytics account. Visit the Google Analytics homepage and you are required to sign in with a Gmail account. If you don’t have one already, you need to create an account for yourself, which is available for all Google products like YouTube, Gmail, Google+, etc. On the other hand, you can sign in directly if you already have a Gmail account.

sign in Gmail account

Then, you are linked to the next page like the following one, where you can feel free to sign up Google Analytics, it’s easy and free! Click the Sign Up button, it will automatically sign up Google Analytics with your Gmail account.

sign up Google Analytics

Now, it’s time to create a new account. You are able to choose what you would like to track, a website or mobile app. In order to install Google Analytics in WordPress websites, we select Website in this step.

As well, you can also select a tracking method as Universal Analytics or Classic Analytics to track your website. The only difference is that Universal Analytics is in beta and comes with extra features. You are free to choose either of these two methods. Even if choosing the Classic Analytics, you will be upgraded to new features once needed.

tracking method

Now, you can be directed to a page that requires you to fill out the account information, which includes the account name, website URL, time zone, and contact information. After completing these blanks, you need to accept the Terms and Service.

google analytics account

Now, you have created a new account successfully. The next thing you need to do is getting Google Analytics tracking code. You can be led to the right page immediately after the account creation process. In this page, you can decide whether to track a single domain or multiple top-level domains. After deciding this, there will be lines of HTML code available in the right side. Copy it immediately.

tracking code

Install Google Analytics in WordPress

Now, you have prepared everything already, and it’s time to install Google Analytics in your WordPress websites. Briefly, there are 3 typical methods: plugins, direct paste code and functions.php. In the following, we explain every method carefully, and you can choose the one you like best.

Install Plugin

There are thousands of plugins available for installing Google Analytics in WordPress websites. Here, it is better choose the best Google Analytics plugin reviewed by both users and experts. Here, we’d like to take the Monster Insights plugin as an example. With it, you can easily track your website with the latest tracking code.

To use it, you firstly need to enter the Settings page of this plugin to finish the Google Authentication with the below steps.

Google Authentication

  • Click the authenticate link in the WordPress dashboard and hit the Next button in the popup.
  • Click the right link to get the Google code and allow this plugin to view and to access your Google Analytics account.
  • Copy and paste the Google code in the popup window and click the Next button.
  • Choose your website from the drop-down menu for tracking.

Monster Insights Authentication

That’s it. Now, you have already connected your Google Analytics account with your WordPress site. If yout to check the data from your WordPress admin directly, you can go back to the settings page to make sure that you haven’t tick the checkbox of the Disable Dashboard option. And also, you can enable the automatic data updates.

Monster Insights Insights

Paste Tracking Code

If you don’t want to install extra plugins, you can directly paste the tracking codes into your themes. Login into your dashboard, go to Appearance > Editor, find header.php File and open it, then paste the tracking codes right after the “body” tag.

Edit function.php File

For webmasters who prefer coding stuff, they can install Google Analytics by adding the following code into function.php File. Note that only use this method if you are clear of what you are doing.

add_action('whatswp_footer', 'add_analytics');
function add_analytics() { ?-->
// Paste your Google Analytics tracking code here
<!--?php } ?-->

Remember to add your tracking code in the right place.

Start Tracking

Still now, you have done all the steps and installed Google analytics in your website successfully and can start tracking your site with a precise analysis. You can click the Reporting tab to see your website’s analytics overview. With the reporting, you can also learn about all visits, new visits, unique visitors, visits by browser, bounce rate, revenue, and so on.

start tracking

In fact, there are also a few things you need to do for better convenience. In the dashboard of Google Analytics, you can see a lot of reports concerning about different parts. Simply choose the type of data you need the most from the left column, and click the button of Add to Dashboard. Thus, you can check it on the dashboard and decide the position as you wish by dragging it.

Besides, you can also decide the time range. You can track your site daily, weekly, monthly or whatever you want. Simply click date range box, and do some configurations based on your needs. If you want to compare date range, you can check the box before “compare to post” in this calendar page.

time range

Useful In-built Features

After presenting how to use this tool basically, we’d like to show some advanced options in the following.

Site Speed – There is no need to emphasize the importance of the page loading speed as it determines the quality of reading experience largely. You can check the detailed data from Google Analytics in seconds.

speed tracking

Event Tracking – Knowing what visitors have done with your site makes it easy to know their ultimate needs. With this advanced feature, you can get the clear information of what happened between your visitors and websites, and how many people have done the same things.

event tracking

Real Time Report – For people who are targeting foreign visitors, seeing the traffic of some specific moments is important. After all, they need to figure out the best time to publish posts for more page views easily.

real time tracking


Joyce is a professional writer & SEOer who loves trying new things and sharing the experience through blogging. She loves clean design, playing with different WordPress themes, SEO, etc. Very often, you could find her in various WordPress event as invited speakers.