Three Ways To Get Google Analytics Connected To Your WordPress Site

Posted on by Nikki Remington | Updated:
Home > Blog > Freelancer > Three Ways To Get Google Analytics Connected To Your WordPress Site

Looking for the exact place to add the Google Analytics tracking code and connect it to your WordPress site?

Google Analytics is a powerful analytics service that provides reports on website traffic, page views, bounce rate, referral sources, user behavior, website conversions and goals, and more. This information is critical to the growth and improvement of your website, your ongoing marketing strategy, and the expansion of your brand.

Google Analytics is by far the most widely used and most popular website analytics tool available. It's not only robust in features, but also free to use.

But finding where to add Google Analytics to your WordPress website code can be challenging, so we made it easy with this helpful guide.

Here are the three ways to connect WordPress and Google Analytics:

1. Add Google Analytics Code Directly To Your WordPress Theme

You can easily add Google Analytics tracking code to your WordPress site without a plugin through the header.php file or the theme functions file.

Add Google Analytics Tracking Code to Your WordPress Site Using the PHP Header File

  1. Login to your Google Analytics account and copy the tracking code for the website you’re working on. You can find the tracking code under Admin > Tracking Info > Tracking Code.
  2. Open the header.php file for your Wordpress website and paste the tracking code directly after the <body> tag and click update.

Add Google Analytics Tracking Code to your WordPress Site Using the Theme PHP Functions File

  1. Login to your Google Analytics account and copy the tracking code for the site. Look for the tracking code under Admin > Tracking Info > Tracking Code.
  2. Open the functions.php file and paste the tracking code like so:

<?php
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// Paste your Google Analytics tracking code here
<?php } ?>

Tip: Perform a complete site backup before editing your theme files.

Google Analytics Integration with WordPress

2. Add Google Analytics To WordPress With The Insert Headers and Footers Plugin

If you prefer to add Google Analytics to your site through a more straightforward plugin that doesn’t have you editing your theme files, you can use the plugin Insert Headers and Footers, a simple plugin that lets you insert tracking code like Google Analytics, custom CSS, Facebook Pixel, and more to your WordPress site header and footer.

Here’s how to add Google Analytics tracking code to WordPress with this plugin:

  1. Install and activate the Insert Headers and Footers plugin.
  2. Login to your Google Analytics account and copy the tracking code for the WordPress site you’re working on.
  3. Open the settings page for the plugin.
  4. Paste your Google Analytics tracking code into the “headers” section.
  5. Save your changes.

Tip: Backup your WordPress site before installing any new plugin.

3. Connect WordPress And Google Analytics With MonsterInsights

MonsterInsights is another WordPress plugin that connects Google Analytics with your WordPress website, but MonsterInsights offers advanced tracking configuration and adds a Google Analytics dashboard right into your WordPress site admin area. The dashboard allows you to see real-time stats and data about your website and visitors without ever leaving your website.

Here’s how to install MonsterInsights and connect Google Analytics to your WordPress site:

  1. Install and activate the Google Analytics by MonsterInsights plugin.
  2. Open the settings under the new Analytics menu item in your WordPress admin bar.
  3. Connect your Google Analytics account in one of two ways:
    • Authenticate the plugin with your Google account — If you are signed in to your Google Analytics account, click the Authenticate with your Google account and follow the instructions.
    • Manually enter your UA (User Account) code — Check the Manually enter your UA code box and paste in your Google Analytics tracking code with your UA number.
  4. Save your changes.

Start Capturing Data and Insight By Connecting Google Analytics to WordPress Today

Google Analytics will only have data about your website from the time it was connected to your website, and you may not see that data right away.

Give Google about 24 hours to crawl your website, and soon you’ll begin seeing data about your website traffic, where it’s coming from, what visitors are doing on your site, and how long they stay.

Over time this collection of data will allow you to make informed, educated decisions about the management of your WordPress website, the improvement of your WordPress website, your blog content strategy, your Search Engine Optimization strategy, and more.

Struggling to Scale Your Business? Download Our eBook to Find Out 15 Ways Managed Hosting Grows Your Business.
About the Author

Nikki Remington

Nikki Remington is the Web Operations Manager at Liquid Web with more than 16 years in the Search Engine Marketing. Her focus at Liquid Web is to help create a smooth user experience from the first time someone searches for web hosting and each interaction with our website.

View All Posts By Nikki Remington