Site-kit-wp: Need an option to disable tracking logged in users

Created on 1 Jul 2019  Â·  8Comments  Â·  Source: google/site-kit-wp

Feature Description

Currently, it's logging the data for logged-in users to Analytics and Search Console which is skewing the data. I wouldn't want my own site visits to be logged in to Analytics and Console.

Proposed solution

An option in the Settings page to exclude logged-in users.

A further granular control for specifying which roles to exclude would be more appreciated for people who only want to exclude Administrators / Editors, etc.


_Do not alter or remove anything below. The following sections will be managed by moderators only._

Acceptance criteria

  • In Analytics settings, display a checkbox: "Disable tracking for logged-in users"
  • Based on this, store an option trackingDisabled which is an array (for future compatibility, see related #536) with or without the value loggedinUsers (i.e. the checkbox should probably have that as its value attribute)
  • By default the option should be the array including loggedinUsers (in other words, the checkbox would be checked at first)
  • If tracking is disabled for logged-in users, the functions that print out the snippet (both AMP and non-AMP) should check whether the user is logged in, and if so, bail before printing the snippet
  • the checkbox should _only_ show up in Analytics settings, not in the Analytics setup flow

Implementation Brief

  • Add a new "Exclude from Analytics" section at the bottom of the Analytics settings
  • Add "Logged-in users" checkbox (unchecked by default)

    • The checked state should correlate to the presence of loggedinUsers in the settings.trackingDisabled array

  • Update the handleSubmit to include the new trackingDisabled key to be saved
  • Update the settings datapoint to ensure the key is included
  • Update unit tests
  • Update VRT - VRT: Editing Settings Module story will need to be approved as it displays the Analytics setup in settings context

Changelog entry

  • Add a checkbox to allow disabling Analytics tracking for logged-in users, and introduce a filter to adjust the behavior programmatically.
P0 Enhancement

Most helpful comment

@felixarntz This is the issue we spoke about at WCUS. :)

All 8 comments

@Paras16699 Thanks for the suggestion. We will log this feature request for discussion.

This is a necessity for websites with few readers. Without this option it's difficult to see if the increased traffic is because I've worked a lot recently, or because what I'm doing is attracting visitors.

This would be a very useful feature. We already have the option in the settings to remove the snippet, so adding a toggle to do that for logged in users or admins would be helpful. Even adding a filter where we could return false to remove the output. That way developers could create more complex filtering to remove it for anyone logged in except subscribers for example. If such a filter already exists, please let me know. My site is running AMP for all pages in Standard.

@felixarntz This is the issue we spoke about at WCUS. :)

I don't know if whats development has been happening with this but i think i have worked a temporary fix until a toggle switch can be made.

if you add the following script to a plugin or the theme's function.php file

function wpdocs_dequeue_script() {
    if ( is_user_logged_in() ) {
    wp_dequeue_script( 'google_gtagjs' );
    }
}
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );

for what i know and tested, it does work but don't know 100% what affect it will have on the site. It can be adjusted for just admins. Currently, it disables tracking for all logged-in users.

IB ✅

QA ✅

For both AMP and non-AMP sites the script is excluded when signed in and the "disable for logged-in users" is disabled. It still shows for anonymous users when that option is enabled.

It always appears when the option is disabled.

verified, lgtm

Was this page helpful?
0 / 5 - 0 ratings