GA give an option to exclude by IP , but IP can be changed..
so is it a good way to use this code which prints the tracking code only if it is not an admin?
or is there a more elegnat way ?<?php if ( !current_user_can( ‘manage_options’ ) ) { ?>
<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX”></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());gtag(‘config’, ‘G-XXXXXXXXXX’);
</script>
<?php } ?>Hi,
Thank you for the question.Your code seems fine to me. Please feel free to use it and it is a better approach than excluding the ip.
Regards
Brajeshthank you very much!
do you use such a method also in yout site?
or do u think it is not such important to exclude admins from tracking (a waste of time) ?Hi,
We are using the analytics plugin. The benefit is, it shows some of the data in dashboard.I will recommend exuding admins to avoid the impact on visit time. If you are spending small amount on site as admin, it has n impact then.
Regards
Brajeshthat was my next question!
regarding the analytics plugins –
if u can watch details outside the site (on google dashboard)
isnt it better?
cause inside the site it is taken resources isnt it?Can I ask which plugin do u use, Monster Insight?
i know it has so many users
but i was always afraid that this plugin is too heavy isnt it?Hi,
1. We have a smaller traffic here and we do not do any seo/marketing. So, stats have very limited significant for us.We started using Google Analyticator around 2010 and still using it. I found that the plugin has changed hands now and is owned by a different company.
https://wordpress.org/plugins/google-analyticator/The plugins will not have much resource issue on your site as the stats etc viewing is limited to admin and accessible to limited number of users. On front end, most of these plugin will do exactly what you achieve with the above code.
Regards
Brajeshoh no. i an getting lotsss of errors like this:
Got error ‘PHP message: PHP Warning: Use of undefined constant \xe2\x80\x98manage_options\xe2\x80\x99 – assumed ‘\xe2\x80\x98manage_options\xe2\x80\x99′ (this will throw an Error in a future version of PHP) in /home/****functions.php on line 65’
this line is wrong? :
<?php if ( !current_user_can( ‘manage_options’ ) ) { ?>
Hi,
You are using code where the quotations are encoded.Let me clean your code and put here in the proper tags.
Please copy it from the forums here and not from your email.
<?php if ( ! current_user_can( 'manage_options' ) ) : ?> <!– Global site tag (gtag.js) – Google Analytics –> <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); </script> <?php endif; ?>
Let me know if it works or not?
Regardsthank u so much!
that site and forum is amazing, this is the reason i feel so comfortable to buy plugins of yours
cause i know that you are our there and giving always such a proffesional and kind support.Hi,
Thank you for the kind words.
I appreciate you supporting us by using and purchasing our plugins.Regards
Brajesh
The topic ‘ [Resolved] how to exclude admin from GA analytics’ is closed to new replies.