Exclude WordPress Admin Traffic From Google Analytics

Google Analytics measures all WordPress traffic. Coming from real visitors, bots or admins and editors. It’s all traffic for Google Analytics. Even when previewing a post. This behavior is normal. It’s what Google Analytics should do. Track all traffic and stats when the Google Analytics code loads.

Why Google Analytics Doesn’t Exclude WordPress Admin Traffic By Default

You must be wondering. Why Google Analytics can’t exclude all WordPress admin traffic by default? The reason is simple. Google Analytics script loads every time your WordPress Theme loads. When previewing a post, WordPress loads the active theme. Which includes all its files. Like header, footer, CSS, images etc.

Google Analytics code snippet loads from the WordPress header file. When previewing a post, WordPress loads the active WP Theme to show exactly how the post will look like before you hit publish. All CSS, all images, all scripts are there. Including Google Analytics.

Are you getting it? An admin or an editor wants to preview a post. He wants to see exactly what visitors will see. Before hitting publish. That’s why every WordPress post preview counts as a visit and pageview for Google Analytics.

It’s easy to exclude this WordPress admin traffic from Google Analytics. All you need to do is create a filter with a unique pattern. Google Analytics even lets you preview the filter.

Create Google Analytics Custom Filter For WordPress Admin

Log in to Google Analytics

Selected your website

Click on Admin

Under the View menu select Filters

Create New Filter

Type the name of the new filter. eg WPAdmin

Select Custom

Exclude Request URI

In Filter pattern type: preview=true

Verify this filter

How To Test Google Analytics WPAdmin Exclude Traffic Filter

This is an easy one. After you saved the new exclude WordPress admin traffic filter go back to Google Analytics. Click on the Real-Time stats.

Now login to WordPress and write a test post. Don’t publish it. Just hit preview.

Now go back to Google Analytics Real-Time stats. You should see no activity based on the preview post URL. Nothing at all. The new WPAdmin filter for excluding traffic is now working.

Will Google Analytics New Exclude Traffic Filter Slow Down WordPress?

Absolutely not. What happens in Google Analytics, stays in Google Analytics. WordPress performance and speed will stay intact. The new filter is something for Google servers and algorithms to take into account. It doesn’t affect WordPress performance at all. Your site will load as fast as it did before.

This article was originally posted on titan.as