• Resolved vtrn

    (@vtrn)


    Hello, I want this plugin not to calculate admin statistics
    In php, we can put an “if” so that the analytics code is not loaded for the admin role
    But this plugin does not have this feature
    How should I do this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support James Osborne

    (@jamesosborne)

    Thanks for reaching out @vtrn. You can disable the Site Kit admin toolbar feature by visiting your plugin settings (Site Kit > Settings > Plugin Settings > Display relevant stats in the Admin toolbar). This will remove the plugins admin bar feature for all users. Note that this includes the Search Console stats, not specifically the Analytics stats. It doesn’t impact the standard Site Kit dashboard page, from your wp-admin panel.

    We also have a filter to disable the admin toolbar if you prefer to programmatically disable the admin toolbar using various conditions, including role based conditions. You’ll find more details on this here. If you need any assistance with this, let me know.

    Thread Starter vtrn

    (@vtrn)

    Hi, I don’t mean admin tool bar! I want admin statistics not to be counted

    Plugin Support James Osborne

    (@jamesosborne)

    Apologies for the confusion, and great question. Site Kit by default won’t include logged in administrators for reporting in Google Analytics. You can change this setting at any stage via Site Kit > Settings > Connected Services > Google Analytics > Exclude Analytics > All logged-in users.

    Let me know if you have any further questions with this.

    Thread Starter vtrn

    (@vtrn)

    Thank you, but I just want to exclude the statistics of the admin role!

    Is there no way?

    For example, the command to the function that inserts the code

    Thread Starter vtrn

    (@vtrn)

    if ( !current_user_can( 'administrator' ) ) { G code }

    Plugin Support James Osborne

    (@jamesosborne)

    Thanks for the update. If you do not want to place the Analytics snippet for only administrators roles, you can use a googlesitekit_analytics-4_tag_blockedfilter, with modifications that apply to administrator roles only below.

    add_filter( 'googlesitekit_analytics-4_tag_blocked', 'restrict_analytics_snippet' );
    function restrict_analytics_snippet( $original ){
     // don't place GA snippet for admins
      if (current_user_can( 'manage_options' ) )
      return true;
    }  

    What the above will do, is not place the Site Kit code snippet (for Google analytics) for administrator roles only. It uses an administrator only capability (manage_options).

    Let me know if that answers your query, or ask if you have any questions. Note that to apply the above, please use a child theme, or a custom functions plugin, as opposed to your themes functions.php file, which will get overwritten on each theme update.

    Thread Starter vtrn

    (@vtrn)

    Hi, it worked, but there was a problem with your code
    You did not write { } for condition!
    Final code:

    add_filter( 'googlesitekit_analytics-4_tag_blocked', 'restrict_analytics_snippet' );
    function restrict_analytics_snippet( $original ) {
    if (current_user_can( 'manage_options' ) ) {
    return true;
    }
    }

    But I have a question, don’t we need to return the initial value after this condition?

    like:

    add_filter( 'googlesitekit_analytics-4_tag_blocked', 'restrict_analytics_snippet' );
    function restrict_analytics_snippet( $original ) {
    if ( current_user_can( 'manage_options' ) ) {
    return true;
    }
    return $original; or return true; ?
    }
    • This reply was modified 9 months ago by vtrn.
    Plugin Support James Osborne

    (@jamesosborne)

    Glad to hear that @vtrn

    But I have a question, don’t we need to return the initial value after this condition?

    The original value of false will remain if the condition isn’t met. But you can add return false outside of the condition if you wish.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘admin statistics’ is closed to new replies.