• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to exclude admin activity in Google Analytics statistics

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › How to exclude admin activity in Google Analytics statistics

This topic is: not resolved

Tagged: exclude admin user from stats, google analytics

  • This topic has 7 replies, 4 voices, and was last updated 12 years, 5 months ago by mynym.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • January 24, 2014 at 10:45 am #86842
    mynym
    Member

    Hi

    I want to exclude my own activity from my Google Analytics statistics.

    I found this suggestion, that should prevent the Google Analytics script to be used for any user logged in as an adminstrator:

    <?php if (!is_user_logged_in()) : ?>
    here comes the Code-Snippet from Google Analytics
    <?php endif; ?>

    My questions:

    A. I put my Analytics snippet in the "Header and Footer" box of my backed "Genesis Theme Settings". Can i simply add the two lines of code before and after the Script of the snippet? I do not want to risk a white page by adding php code in a place I should not do so...

    B. Can I differentiate further, and only exclude the script for admin users, but include it for all regular users that are logged in?

    Thanks for you help

    January 24, 2014 at 12:06 pm #86856
    rfmeier
    Member

    Hello,

    PHP won't execute for the header and footer box of the Genesis Theme Settings page. I would recommend installing Genesis Simple Hooks.

    This will create another menu under the Gensis Tab within the admin.

    Under the wp_head hook, you can paste the following code. Make sure to add your google script.

    <?php if( ! current_user_can( 'manage_options' ) ) : ?>
    
    	//	place your google script here.
    
    <?php endif; ?>

    Then, check the Execute PHP on this hook? checkbox and click Save Changes.

    This code will only add the script if the current user is logged-in and an administrator.

    I hope this helps.


    Ryan Meier – Twitter

    January 24, 2014 at 2:20 pm #86873
    handsome jack
    Member

    Another alternative would be to block your own IP address from within Google Analytics (it's a good practice to do so anyway).

    January 26, 2014 at 7:26 pm #87156
    mynym
    Member

    Hi rfmeier
    Thanks for the example. I am already using Simple Hooks and will move my Analytics snippet from the Genesis settings to this section.

    Just to make sure: You wrote

    This code will only add the script if the current user is logged-in and an administrator.

    What I want is exactly the opposite of that behavior, the script should only be added if the current user is NOT logged in and an administrator. As far as I know, the "!" stands for "not", so the code seems to to what I want, does it...?

    January 26, 2014 at 7:35 pm #87157
    mynym
    Member

    Hi handsome jack

    Thanks for your advice.

    Another alternative would be to block your own IP address from within Google Analytics (it’s a good practice to do so anyway).

    My problems with this:
    A. I checked with Google, but it was not obvious on the first glance how to block an IP address. This is nothing seriouc, I just will have to dive into the matter a little deeper. More critical is
    B. As far as I know, my IP address changes periodically, depending on the Intenet service provider that gets me online. Plus there will be differetn IP addresse at my office, at home, at Starbucks, etc. Or am I wrong, and "MY" IP address is tied to the machine I use to go online?

    January 26, 2014 at 8:40 pm #87164
    rfmeier
    Member

    Mynym,

    My apologies-- the code is correct, but my description was not. That code will only add it when non-administrators are viewing the site.


    Ryan Meier – Twitter

    January 26, 2014 at 10:23 pm #87183
    songdogtech
    Participant

    @Mynym, Try a plugin like http://wordpress.org/plugins/google-analyticator/ You can disallow tracking of logged in admins, editors, and other roles. No need to block an IP at Google Analytics.

    That plugin will give you a WP dashboard view of stats, too, and it will add your GA tracking script so you don't have to add in in Simple Hooks or anywhere else in the child theme.

    January 27, 2014 at 3:21 am #87204
    mynym
    Member

    @songdogtech, Thanks for the hint. Though the additional features are interesting, I try to keep the number of plugins installed as low as possible. Therefore I will first try the workaround using stuff already 'on board'. Maybe I'll come back to the plugin later.

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble