Stop Google Analytics From WordPress User Admin

Posted by: Alex on June 19, 2013

As a WordPress admin/blogger, you will no doubt spend a lot of time browsing throughout your own site. If you are using Google Analytics this can create false results, and although you can configure Google Analytics to ignore certain cookies/IPs etc, I find it easier to just not load the Google Analytics script for Admins/Editors.

To hide Google Analytics from WordPress Editors, use the following:

if (!is_user_logged_in() ) {
  echo "<script>
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', '# Change to your Google UA Code #', '# Change to your Domain #');
  ga('send', 'pageview');

Just ensure to change the line with comments on so that the Analytics snippet has your UA and URL in it.