• Home

  • Productivity

  • App tips

App tips

4 min read

How to add Google Analytics to WordPress

By Juliet John · September 17, 2024
A hero image for WordPress app tips with the WordPress logo on a blue background

Whatever the purpose of your WordPress website—be it to sell services or products, host a blog, or just show the world how gorgeous your dog is—the only way to tell if it's having an impact is by digging into the data. 

Want to know how many people visited your website in the last month? Or what brought users to your site in the first place? Google Analytics can tell you all of this—and then some. 

When you add Google Analytics to your WordPress site, you get real-time data on metrics that will help you better understand your audience and their behaviors—for example, traffic sources, user behavior, and demographics. 

Here, I'll show you how to add Google Analytics to your WordPress website, step by step. 

How to add Google Analytics to WordPress

Before we get started, you'll need to register for a free Google Analytics account. Once you've set that up, you have two options for adding Google Analytics to your WordPress page. 

  • How to add Google Analytics to WordPress with a plugin

  • How to add Google Analytics to WordPress manually 

How to add Google Analytics to WordPress with a plugin

The most straightforward way to add Google Analytics to your WordPress website is with a WordPress plugin. There are lots of popular options to choose from, including Site Kit by Google, MonsterInsights, ExactMetrics, and Analytify. 

Since Site Kit is the official Google Analytics plugin for WordPress, we'll use that one. It's free, provides reliable data from multiple Google products, and apart from granting the necessary permissions, it doesn't require any other manual effort on your end. 

  1. Log in to wordpress.org

  2. From the sidebar of your WordPress dashboard, click Plugins

  3. Click Add New Plugin.

    How to add a new plugin in WordPress.

  4. In the search bar next to Search Plugins, enter Site Kit

  5. From the list of results, click Install Now next to the plugin you want to add—in this case, it's Site Kit.

  6. Once installed, the Install Now button will change to Activate. Click Activate

    How to activate the Site Kit plugin in WordPress.

  7. Once activated, the plugin will appear in your WordPress dashboard. From the sidebar of your WordPress dashboard, click Site Kit to set up the plugin. 

  8. Click the checkbox next to Connect Google Analytics as part of your setup, and then click Sign in with Google

    The Site Kit plugin in WordPress.
  9. Complete the sign-in process by verifying that you own your website and giving Google and Site Kit the required access, including access to your Search Console. 

  10. Click Next.

    Confirmation page indicating that the Site Kit plugin is added to a WordPress website.

  11. Site Kit will immediately connect with Google Analytics and display the account information in the connected Google Analytics account. If everything looks good, click Complete setup

    Completing the Site Kit WordPress plugin in WordPress.

That's it. Now you can access your site's data directly from your WordPress backend. 

Example of google analytics data appearing in WordPress.

How to add Google Analytics to WordPress manually

If you prefer to not install a WordPress plugin, and you have the technical expertise, you can also add Google Analytics to WordPress manually. To do this, you'll need to install your Google Analytics tracking code to WordPress. 

But first, let's quickly cover some of the reasons why you might not want to go this route: 

  • The setup can be tedious and time-consuming. 

  • You stand the risk of getting inaccurate data if the code isn't installed properly.

  • You can't track your site's data directly in WordPress—you'll need to open your Google Analytics dashboard to do this. 

  • A theme update can easily erase the code, forcing you to redo it. 

  • You won't have access to advanced features offered by plugins.

If I haven't scared you off, then let's continue. 

How to find your Google Analytics tracking code 

  1. Back up your WordPress website. This step is optional but highly recommended before making any changes to your site's theme because any mistakes can break your site. 

  2. Go to analytics.google.com

  3. In the sidebar, click Admin

    Google Analytics dashboard with an arrow pointing to the Admin button.

  4. In the Data collection and modification widget, click Data streams

    Google Analytics Admin dashboard with an arrow pointing to data streams.

  5. Click the data stream you want to use. 

    List of Google Analytics data streams.

  6. Click View tag instructions

    Google tag options with an arrow pointing to view tag instructions.

  7. Click the Install manually tab to reveal your Google Analytics script (tracking code). 

    Example of a Google Analytics tracking code.

  8. Click the Copy icon, which looks like two overlapping rectangles, in the script box. 

Google Analytics tracking code in hand, you now have two options for adding it to your WordPress website: 

  • How to add the Google Analytics tracking code to your website's header.php file 

  • How to add the Google Analytics tracking code to your website's functions.php file

How to add the Google Analytics tracking code to your website's header.php file 

  1. Go to wordpress.org.

  2. In the sidebar, click Appearance, and then select Theme File Editor

    Theme file editor in the WordPress dashboard.

  3. You'll be warned about editing your theme. Click I understand to continue. 

    Warning message in WordPress.

  4. From the Theme Files sidebar, click Theme Header (header.php).

    WordPress theme header script.

  5. Paste the Google Analytics code you previously copied above the closing head tag: </head>.

    Theme header script in WordPress with the closing head tag highlighted.

  6. Click Update File

You're all set. 

How to add the Google Analytics tracking code to your website's functions.php file

Unlike adding your Google Analytics code to your header.php file, I recommend first installing a child theme. This will help preserve your existing design after updating your site's parent theme. 

Once you've set that up, you can install your code. 

  1. Go to wordpress.org.

  2. In the sidebar, click Appearance, and then select Theme File Editor

  3. From the Theme Files sidebar, click Theme Functions (functions.php).

    Theme functions script in WordPress.

  4. Paste the Google Analytics code you previously copied in the text box before the closing </script> tag.

    Theme functions script in WordPress with the closing script tag highlighted.

  5. Click Update File

Automatically monitor your site's performance 

Tracking your site data is one thing, but if you want a more holistic view, you'll want to gather data from other apps connected to your site. With Zapier's Google Analytics 4 integration, you can automatically do things like track form submissions or payments on your site. For more inspiration, check out ways you can automate your data analytics. Or use one of these pre-made templates to get started.  

Track new Jotform submissions by creating conversion events for properties in Google Analytics 4

Track new Jotform submissions by creating conversion events for properties in Google Analytics 4
  • Jotform logo
  • Google Analytics 4 logo
Jotform + Google Analytics 4

Create conversion events for properties in Google Analytics 4 from new requests in Jobber

Create conversion events for properties in Google Analytics 4 from new requests in Jobber
  • Jobber logo
  • Google Analytics 4 logo
Jobber + Google Analytics 4

Send measurement events in Google Analytics 4 for new submissions in Jotform

Send measurement events in Google Analytics 4 for new submissions in Jotform
  • Jotform logo
  • Google Analytics 4 logo
Jotform + Google Analytics 4

Related reading

  • How to uninstall a WordPress plugin (completely)

  • GA4 vs. Universal Analytics: What's new in Google Analytics 4?

  • WordPress.com vs. WordPress.org: What's the difference?

  • How to set up Google Analytics to track your website

This article was originally published in March 2019 by Justin Pot. The most recent update was published in September 2024.

Get productivity tips delivered straight to your inbox

We’ll email you 1-3 times per week—and never share your information.

tags

Related articles

Improve your productivity automatically. Use Zapier to get your apps working together.

Sign up
See how Zapier works
A Zap with the trigger 'When I get a new lead from Facebook,' and the action 'Notify my team in Slack'