How to exclude administrators from the eCommerce statistics

This documentation is for the EDD Enhanced eCommerce Tracking plugin.

Personally, I like to test all the things to make sure it all works as expected. This includes buying our own products. A big downside of this is that my purchases are included in the eCommerce statistics which makes them less accurate. This document will give you the tools to exclude administrator (or other roles) sales/views from your Google Analytics Enhanced eCommerce statistics.

Requirements

To set this up you need the EDD Enhanced eCommerce Tracking plugin, version 1.0.2 or higher. You will also need to have edit access to your (child) theme's functions.php file. We will add a peace of custom code to that file to make sure no data is sent to Google Analytics when someone is logged in as a site Admin.

Custom code

Add the following code to your (child) theme functions.php

add_filter( 'eddeet_api_call_return', 'eddeet_dont_track_admin' );
function eddeet_dont_track_admin( $return ) {
	global $current_user;
	if ( ( isset( $body['ea'] ) && $body['ea'] != 'refund' ) && in_array( 'administrator', $current_user->caps ) ) :
		return true;
	endif;

	return $return;
}

If you want to change the code to work for other roles you can change the 'administrator' to another value.

Or if you want to exclude multiple roles at the same time, you can replace that line with this;

if ( array_intersect( array( 'administrator', 'editor' ), $current_user->caps ) ) :

With this code, all transactions/views from administrators will be omitted from the Google Analytics reports.

Still need help? Contact Us Contact Us