WordPress Stop Tracking The Site Owner Visit
- Article
- Comment
WordPress Stop Tracking The Site Owner Visit is one of a basic thing to get exact visit count from your website visitors count. And Also you can avoid you site authors and other post editors visit count to get exact visitors tracking. Which is more accurate to narrowing the results. Once you register a new Analytics account and get tracking code js from the Google analytics. And if you are using any plugin or built in feature to add your tracking code to your site.
It will be place on your site Either footer or Header. So it will track each and every visitor who comes to visit your site. Now, we need to avoid the tracking of our website authors view count, if your site is multi-author site, than no need of counting the authors. Because, they will check their post after posting it from the admin section. It will be also added one another count. Lets start with avoiding admin visit count.
The following code help you to avoid the admin visit count.
function kv_ga_tracking_code() { if( !current_user_can( 'administrator' ) ) { //your site tracking code ?> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-42867479-1', 'kvcodes.com'); ga('send', 'pageview'); </script> <?php } } add_action('wp_footer' , ;'kv_ga_tracking_code');
The above function adds a condition to check whether the current user is a administrator or visitor. If you want to prevent by using the user roles, you can use the role checking function. Else if you want to prevent it based on user name thats also possible, and try this code.
function kv_ga_tracking_code() { $kv_current_user = wp_get_current_user(); if( !kv_current_user->user_login == 'varadharaj' ) { //your site tracking code } } add_action('wp_footer' , ;'kv_ga_tracking_code');
The Above function will help you to avoiding the analytics count if the username is ‘varadharaj‘. Likewise, you can do for any users.
The following function will help you to avoid counting for ” author ” and ” Administrator ” .
function kv_ga_tracking_code() { if( !current_user_can( 'administrator' ) ) { if( !current_user_can( 'administrator' ) ) { //your site tracking code } } add_action('wp_footer' , ;'kv_ga_tracking_code');
The same way you can avoid counting your site owner and maintenance people visit counts, which will help you to get exact traffic count and its metrics .