How to Exclude WordPress Admin Traffic from Google Analytics? [2024 Guide]

How to Exclude WordPress Admin Traffic from Google Analytics?

By default, Google Analytics tracks every pageview on your WordPress site that has the Analytics script loaded on. So when you are logged in writing your posts or viewing your pages, all your pageviews and sessions working on the website will be logged into Google Analytics.

For a large website with a lot of traffic, this shouldn’t be an issue, but if you are just starting, your traffic can easily skew your analytics data and may lead you to believe you are receiving more traffic than you do.

So how do you exclude your WordPress admin traffic from Google Analytics? Well, in this post I will share with you more than one method for how to accomplish this, step by step. This works for both Google Analytics 4 (GA4) and Universal Analytics.

Let’s dive in!

Table of Contents

Why Exclude Admin Traffic and Why is this Important?

If you don’t already know, Google Analytics is by far the best web analytics tool out there. Almost every webmaster and developer nowadays is using it at least on one of his websites or apps.

It provides useful insights about your site’s visitors and how they are interacting with your content which comes very handy when you are trying to improve your site’s SEO and increase sales. As they say – “What gets measured gets improved.”

Now back to our issue, Google Analytics will log all your website traffic, including your traffic. So if you spend some time checking your pages or proofreading your articles your average time on page or engagement time will be shooting to the roof because the average time spent by all users on your website will lean forward “your” time spent on the website.

Unfortunately, this doesn’t only affect the time on page metric, it can also affect sessions, pageviews, sessions per user, bounce rate, and other metrics.

This can lead to inaccurate and misleading reports and thus, the whole point of accurately tracking your site traffic is thrown out of the window.

I cannot say for sure, but maybe Google is using Analytics data to rank your pages. If this is true, we now have an even bigger problem.

Thankfully, this is easy to fix and there are multiple ways to go about it!

Method 1. Filter Admin Traffic by IP Address

The most straightforward way to exclude admin traffic is to use an IP address filter.

However, this is only useful when you have a static IP address. If your IP address is constantly changing, please skip this method.

First, you need to know your IP address. A quick Google search for “what’s my IP” will reveal your IP in the search result.

If this is not working for you, you can quickly grab your IP address from this website: WhatIsMyIP.com.

Now log into your Google Analytics account and visit the Admin page. The link to this page will be at the bottom left.

Google Analytics admin

Google Analytics 4 (GA4)

If you are using GA4, filters have moved to Data Streams under the Property menu.

From your admin page, go to Property >> Data Streams and select the existing web data stream or create a new one:

Google Analytics data streams

Under the Web stream details, click Configure tag settings then click Define internal traffic. If the option is not showing for you, make sure to the Show all button on the right.

Under the Internal traffic rules sub-page, click Create. Choose a name for your rule, set the Match type option to IP address equals, and finally add your IP address to the value field.

Google Analytics internal traffic rule

You can exclude multiple IP addresses or IP ranges if you want.

Once done, click the blue Create button for the changes to take effect. Now whenever you visit your website using this IP address, your activity will not be logged.

Please check Google’s GA4 guide for more info.

Universal Analytics

Make sure to select the correct Account, Property, and View before moving to the next step. Choose the view that you use the most or select the default one All Web Site Data view.

On the admin page, click Filters >> ADD FILTER and fill in the fields as follow:

Google Analytics filter by IP address

  • Choose a name for your filter. You can name your filter anything you want but try not to get too fancy and choose something descriptive.
  • Select Predefined as the Filter Type.
  • Set the other fields as in the screenshot above.
  • Enter your IP address in the corresponding text box and click Save.

You can learn more about this on this page.

Don’t worry if you receive the “This filter would not have changed your data” warning when you click Verify this filter. This can happen when Google doesn’t have enough data to test your filter.

Now every time you visit your website from this IP address, Google Analytics will not log your visit.

However, this filter will only work when your IP address is static. If your IP address is dynamic, are not completely out of luck, I still have a solution for you! Please check the next method.

Method 2. Manually Include Your Tracking Code

For this method, you need to get your hands a bit dirty with code. But don’t worry this should be extremely easy. All you need to do is to edit your current theme header.php file using your preferred FTP client and code editor (if you have cPanel, you can use its built-in code editor) and add your Analytics tracking code right before the </head> closing tag.

But you need to get your tracking code first.

How to get Google Analytics 4 (GA4) Tracking Code?

From your Analytics admin menu, select your Account, then Property, click Data Streams then select your web data stream. You should only have one by default.

From your Web stream details page, select the View tag instructions option at the bottom then click Install manually. Now you will receive your tracking code. Copy it for later.

GA4 tracking code

How to get Universal Analytics Tracking Code?

From your Analytics admin menu, select your Account, then Property and finally select Tracking info >> Tracking Code. This is your tracking code. Copy it for later:

Universal Analytics tracking code

Installing Google Analytics tracking code manually

Now that you have your tracking code, you need to open the header.php file using your preferred code editor and add your tracking code right before the </head>  closing tag like this (don’t add another </head> tag. This tag already exists in the file):

<?php if ( !current_user_can( 'manage_options' ) ) { ?>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-XXXXXXXXXX');
    </script>
<?php } ?>

</head>

What this code does is very simple, it checks if the current user is logged in and if yes, it checks whether he can manage WordPress settings and only admins have this capability. And only prints the tracking code when these conditions are false.

Now after installing the tracking code manually, you need to disable any plugin you have already installed to integrate the Analytics tracking code.

Bonus 1. Exclude Traffic on the Login Page (wp-login.php)

While you are at it, it is a good idea to also filter the traffic the WordPress login page receives. This page is highly targeted by bot traffic and it is also the page you use regularly to log in and out of your website.

Google Analytics 4 (GA4)

As of now, I couldn’t find a way to exclude specific pages using the new Google Analytics 4. I will update this section when a new method becomes available for GA4 users. Sorry!

Universal Analytics

Follow the same steps as in method 1 to create a new filter that will exclude traffic on the WordPress login page (wp-login.php).

Make sure this filter is configured as follows:

WordPress exclude wp-login.php from Google Analytics

  • Choose a name for your filter.
  • Select Predefined as the Filter Type.
  • Choose Exclude and set the Filter Field to Request URI.
  • Enter wp-login.php in the Filter Pattern text box.
  • Save the filter.

Bonus 2. Exclude Traffic on Post Preview Pages

If you use a plugin to load your Analytics tracking code or add the code manually to your theme header.php file, all the traffic on /wp-admin/ pages will not be logged (unless you use a plugin that also loads your tracking code on the admin dashboard.

However, there is a particular page that resides on the front of your site but is only used to preview posts. That page is the post preview page and it is recognizable by the preview=true parameter in the URL.

Since this page is on the front end, all traffic activity on it will be logged by Analytics so it’s a good idea to exclude traffic on this page too. However, you only need to do this if you didn’t apply any of the previous methods. Otherwise, traffic will be already filtered on this page.

Google Analytics 4 (GA4)

As of now, I couldn’t find a way to exclude pages with specific URL parameters on the new Google Analytics 4. I will update this section when a new method becomes available for GA4 users. Sorry!

Universal Analytics

Follow the same steps as in method 1 to create a new filter that will exclude traffic on the post preview pages (pages where the URL ends with preview=true).

Since these pages have the preview parameter set to true appended to the URL, we can target this parameter in our filter.

Here is what your filter should look like:

WordPress exclude post preview from Google Analytics

  • Pick a name for your filter. Something like Filter Post Previews.
  • Select Predefined as the Filter Type.
  • Choose Exclude and set the Filter Field to Request URI.
  • Enter preview=true in the Filter Pattern text box.
  • Don’t forget to save the filter.

Wrapping Up

And that’s should do it. If you make it this far, congratulations! And if you have any questions please let me know, I will be happy to help.

Related posts

What is the Difference Between www and non-www?

What is the Difference Between www and non-www?

So what is the difference between www and non-www domains? Are there any SEO…

2 thoughts on “How to Exclude WordPress Admin Traffic from Google Analytics? [2024 Guide]

  1. talia
    1. Khalil AsmiAuthor

Leave a Comment

Your email address will not be published.