admin statistics
-
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?
-
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.
Hi, I don’t mean admin tool bar! I want admin statistics not to be counted
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.
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
if ( !current_user_can( 'administrator' ) ) { G code }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.
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; orreturn true;? }-
This reply was modified 2 years, 4 months ago by
vtrn.
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 falseoutside of the condition if you wish. -
This reply was modified 2 years, 4 months ago by
The topic ‘admin statistics’ is closed to new replies.