Community Forums › Forums › Archived Forums › General Discussion › How to exclude admin activity in Google Analytics statistics
- This topic has 7 replies, 4 voices, and was last updated 10 years, 3 months ago by mynym.
-
AuthorPosts
-
January 24, 2014 at 10:45 am #86842mynymMember
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 #86856rfmeierMemberHello,
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.
January 24, 2014 at 2:20 pm #86873handsome jackMemberAnother 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 #87156mynymMemberHi 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 #87157mynymMemberHi 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 #87164rfmeierMemberMynym,
My apologies-- the code is correct, but my description was not. That code will only add it when non-administrators are viewing the site.
January 26, 2014 at 10:23 pm #87183songdogtechParticipant@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 #87204mynymMember@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.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.