Running a successful WordPress site requires you to understand what makes your content successful. If you are new to the game, trying to gather this information can be a painful process as you get acclimated. However, ignoring this process can cost you valuable time when it comes to maintaining a successful web presence.

Understanding metrics like bounce rates, time spent on each page, and even browser information is a great way to gain insight into your audience and your site’s performance. Google Analytics is an invaluable tool for helping you use this information to target your best and worst performing content, so you can give your audience what they want.

In this guide, we will explain what Google Analytics is, how it works, and why you should use it. Then, we will discuss the different ways you can use Google Analytics in WordPress, and show you how to do just that. We’ve got a lot of ground to cover, so let’s dive in!

An Introduction to Google Analytics

Google Analytics Homepage
Google Analytics is a free service that provides statistics and analytical reports to help you optimize your site for search engines and marketing purposes. It’s also a powerful tool that enables you to take control of your site’s direction and focus when used correctly.

Google Analytics uses JavaScript to collect information from visitors who access your website. The script gathers data and sends it to Google’s server as ‘hits.’ The server then processes the information, and creates actionable reports you can use to improve your site and better target your audience.

The hits gathered in the report include:

  • Which browser was used to access the site.
  • The operating system of your visitor.
  • The screen resolution and device used to access the site.
  • Time the user spent on the site overall, as well as specific pages.
  • The geographic locations and languages of your visitors.
  • How the visitor found your site (search, social media, etc.)

This is just the tip of the iceberg. What’s important to know is that all of the WordPress analytics provided by this tool can help you enhance your site and hone your content for your target audience. So whether you are running a blog and want to gain a larger viewership, building an affiliate site and need more leads, or managing an e-commerce site and looking to boost your sales, using Google Analytics in WordPress can be your secret weapon for reaching your goals.

Why You Should Use Google Analytics in WordPress

Optimize page for Google Analytics

You can use Google Analytics in WordPress to optimize your site.

Google Analytics is free, easy to use, and beginner-friendly. What’s more, as it’s connected to the world’s most popular search engine, you can use it to gain insight into ways to improve your search engine optimization, .

The benefits of using Google Analytics in WordPress are too numerous to list fully. So we are going to address a few key ones, starting with how it helps you enhance your content:

  • You can analyze bounce rates, click-throughs, and time spent on your site. By reviewing this information, you can see what content is encouraging users to click, stay on your site, or leave after a few seconds.
  • You can see the browser and device information about your users. You can use this data to optimize your site and its content for specific mobile devices, as well as to correct browser display issues.

By using Google Analytics, you can discover what led visitors to your site in the first place. By finding their point of origin, you can tell whether or not your social media, search engine optimization, or other advertising campaigns are working. This enables you to focus on and enhance what’s successful, while freeing you from the things that aren’t.

What’s more, if you are managing a site for another business or individual, using Google Analytics in WordPress enables you to show them their Return on Investment (ROI). This includes:

  • Providing customized reports. You can use the drag-and-drop interface to tailor reports that show metrics specific to your client, such as site traffic comparisons based on particular date ranges.
  • Enabling comparisons between platforms. If your client uses multiple platforms for advertising, you can show comparisons between those methods, such as charting the success rates of their Facebook content versus their Twitter or Instagram accounts.

When it comes to monitoring WordPress analytics on your site (or your clients’ sites), Google Analytics is a fantastic all-in-one tool. Even better, it delivers outstanding customer support, easy-to-follow tutorials and training to help you get started, and content optimization tips.

3 Ways to Add Google Analytics to WordPress

Google Analytics Capabilities page

By using Google Analytics in WordPress, you can increase your audience and improve your bottom line.

Now that you’re ready to learn how to add Google Analytics to WordPress, let’s talk about some ways to do just that. Before we address the methods, however, there are a few prerequisites to get out of the way.

First, you’ll want to have a recent site backup in case something goes wrong during the process. Then, you’ll need to create a Google Analytics account. To do this, you’ll have to:

  1. Go to the Google Analytics home page and click Sign Up.
  2. Select Website and fill in the form. Be sure to complete all required fields, and pay attention to their tracking recommendations.
  3. Click the Get Tracking ID button to get your Google Analytics ID.

The process for getting started is very fast, but it may take Google up to 3 days to verify your site and approve your account. When your account is approved, you will need to log in and get your your Google Analytics tracking code snippet. This is what the code should look like:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'GA_TRACKING_ID');

You’ll need to replace GA_TRACKING_ID with your own Google Analytics tracking ID. Once you have this code saved, you can choose a method below to use Google Analytics in WordPress.

1. Add Google Analytics by Editing Your header.php File

Adding Google Analytics to your header.php file may be the ideal solution if you don’t want to install a plugin and you’re comfortable working within the WordPress admin panel. Before you get started, make sure you’ve created a backup of your site.

Log in to your WordPress admin panel, and click Appearance followed by Editor. You should see a list of PHP files on the right side of the edit window. Select header.php. The file will open in the window, and you’ll see the code for your header.

Paste your Google Analytics tracking code above the </head> tag, and click Update File. Once you’ve saved your changes, the analytics code will be in place for every page on your site that uses your header.

2. Use Your functions.php File to Add Google Analytics to WordPress

Depending on the theme you chose, you may not have an active header file. In some cases, you may have different headers for different pages. In this situation, you can instead use your functions.php file to add your analytics globally. This will require you to be comfortable working with code, as you will be creating a new function inside of your functions.php file.

Again, it is very important that you have a full site backup before you proceed. Once that is in place, you will need to go to Appearance and click on Editor. From the list on the right side of the screen, select functions.php. Use the following snippet to create your function with the Google Analytics code:

add_action('wp_head','my_analytics', 20);
function my_analytics() {
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
ga('create', 'UA-00000000-1', 'auto');
ga('send', 'pageview');

Replace UA-00000000-1 with your Google Analytics ID. Once that’s done, click Update File to save your changes. Keep in mind that this function will only work for the theme you are actively using. If you change your theme later on, you will need to update the functions.php file for that theme as well.

3. Integrate Google Analytics With a Plugin

A plugin for using Google Analytics in WordPress.

If you are not comfortable working with code, there are plenty of plugin options available. For the purpose of this guide, we are going to use Google Analytics Dashboard for WP. We chose this plugin based on a few clear criteria:

  • It is highly rated, with over a million active installations.
  • It’s consistently updated by the developers.
  • It updates analytics in real time, and enables you to customize your results.

To get started, log in to your WordPress admin panel and go to Plugins. Then, search for “Google Analytics Dashboard for WP.” Select the plugin, and install and activate it as normal. After that, you can visit the Google Analytics menu. From that menu, choose Authorize Plugin. This will enable the plugin to connect to Google Analytics in WordPress.

Once you authorize the plugin and it is connected, you will need to go to the Plugin Configuration page under the Google Analytics menu. Once you’re on this page, you’ll need to update your settings. This is where you will want to add your analytics ID, as well as enable tracking. Don’t forget to save your updates! You will now be able to monitor your analytics in real time from your dashboard.

As with any plugin you’re thinking about adding to your site, we suggest that you do your research first. While we’ve recommended Google Analytics Dashboard for WP, there are other plugins that you may want to also check out before making a decision. Here are a few that you may want to review:

  • Google Analytics for WordPress by MonsterInsights. This is a freemium plugin, which means that even though it’s free, it includes some of the features you would expect to find in the premium version. In addition to fast and reliable tracking results, it is very easy to use. You can use this plugin to track WordPress analytics such as demographics, outbound links and downloads, search and 404 pages, and even subdomains. You can also install add-ons that enable you to use this tool for e-commerce.
  • Google Analytics Dashboard by Analytify. While is a free plugin, the developers also offer a premium version with extended features. It enables analytics for single posts, pages, and custom post types. What’s more, the premium version includes real-time statistics, campaign stats, and shortcodes. You can also purchase elements of the premium version as add-ons, if you prefer a la carte options.
  • Enhanced Ecommerce Google Analytics. If you are using WooCommerce to run an e-commerce store, this free plugin may come in very handy. In addition to the normal features provided by Google Analytics, you can use this plugin to track products. It includes reports specific to e-commerce, such as shopping behavior, checkout behavior, product performance, and sales performance. Even better, this is a completely free plugin.

No matter which method you choose for adding Google Analytics in WordPress, you will be rewarded with real information that you can use to target your content and grow your audience. We recommend you learn more about Google Analytics by reviewing its features, and working through some of the free online courses offered through their Analytics Academy.


When you are new to managing a website, it is easy to feel inundated with confusing information about how to improve it. Using a powerful tool like Google Analytics can solve this problem for you, but only if you understand how it works and the benefits it provides.

In this piece, we introduced you to Google Analytics and explored its benefits. We also explained how to add Google Analytics to WordPress using three different methods. To briefly recap, you can:

  1. Edit your header.php file.
  2. Edit your function.php file.
  3. Use a plugin such as Google Analytics Dashboard for WP.

Do you have questions about Google Analytics or how to add it to your WordPress site? Let us know in the comments section below!

  • php
  • my sql
  • intel
  • cloudlinux
  • nginx
  • cloudflare
  • wordpress