BuddyDev

Search

[Resolved] how to exclude admin from GA analytics

  • Participant
    Level: Master
    Posts: 152
    טליה שוורץ on #48018

    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&gt;
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘G-XXXXXXXXXX’);
    </script>
    <?php } ?>

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #48028

    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
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    טליה שוורץ on #48036

    thank 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) ?

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #48044

    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
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    טליה שוורץ on #48050

    that 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?

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #48066

    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
    Brajesh

  • Participant
    Level: Master
    Posts: 152
    טליה שוורץ on #48076

    oh 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’ ) ) { ?>

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #48081

    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?
    Regards

  • Participant
    Level: Master
    Posts: 152
    טליה שוורץ on #48082

    thank 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.

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #48094

    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.

This topic is: resolved