Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracks: Don't track users in dev mode or when opted out #13698

Merged
merged 7 commits into from
Oct 11, 2019

Conversation

scruffian
Copy link
Member

We shouldn't fire Tracks events when we are in dev mode, or if users haven't accepted our TOS, or if they have opted out of Tracks.

Changes proposed in this Pull Request:

  • This PR adds a check for these three cases to ensure that we don't fire Tracks events in these cases

Is this a new feature or does it add/remove features to an existing part of Jetpack?

Testing instructions:

  • Upgrade your Jetpack site to Professional
  • Add a Jetpack Search widget to the site
  • Check that you see a jetpack_search_widget_widget_added event in Tracks
  • Enable development mode (by adding this to wp-config.php):
    define( 'JETPACK_DEV_DEBUG', true );
  • Add a Jetpack Search widget to the site
  • Check that you don't see another jetpack_search_widget_widget_added event in Tracks

Proposed changelog entry for your changes:

  • No changelog required?

@scruffian scruffian added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Feature] Tracks labels Oct 9, 2019
@scruffian scruffian requested a review from a team as a code owner October 9, 2019 16:44
@scruffian scruffian self-assigned this Oct 9, 2019
@github-actions github-actions bot added the [Status] Needs Package Release This PR made changes to a package. Let's update that package now. label Oct 9, 2019
@jetpackbot
Copy link

jetpackbot commented Oct 9, 2019

Warnings
⚠️

pre-commit hook was skipped for one or more commits

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 8a14c13

@jeherve jeherve added this to the 7.9 milestone Oct 10, 2019
This will avoid having to bypass the pre-commit hook for all commits to this file
@matticbot
Copy link
Contributor

This PR looks like it might contain user tracking functions. We need to make sure that it is GDPR Compliant.

Rules triggering this positive scan:

  • Called "record_user_event" function.

cc: @pesieminski

@kraftbj
Copy link
Contributor

kraftbj commented Oct 10, 2019

Let's update the legacy file too. I'll push a commit.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a commit to fix all PHPCS issues, to avoid having to bypass the pre-commit hook for that file in the future.

I also have one remark, I think we could simplify this a bit.

packages/tracking/src/Tracking.php Outdated Show resolved Hide resolved
packages/tracking/src/Tracking.php Outdated Show resolved Hide resolved
packages/tracking/src/Tracking.php Outdated Show resolved Hide resolved
@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Oct 10, 2019
The TOS check is used for confirming that a site is "Trackable". For sites in development mode or are not active, we should not track them.
@kraftbj kraftbj added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Status] Needs GDPR Review labels Oct 10, 2019
@kraftbj kraftbj requested a review from jeherve October 10, 2019 15:42
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Oct 11, 2019
@kraftbj kraftbj merged commit 4accf77 into master Oct 11, 2019
@kraftbj kraftbj deleted the update/tracking-in-dev-mode branch October 11, 2019 13:23
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Oct 11, 2019
jeherve pushed a commit to Automattic/jetpack-tracking that referenced this pull request Oct 11, 2019
 Don't track users in dev mode or when opted out

* Fix all phpcs issues

This will avoid having to bypass the pre-commit hook for all commits to this file

* [not verified] Opt out of tracking in dev mode in legacy branch.

* PHPCS fixes

* Include development mode check within Jetpack::jetpack_tos_agreed.

The TOS check is used for confirming that a site is "Trackable". For sites in development mode or are not active, we should not track them.

* Docblock for is_active_and_not_development function

* Bring cookie check back

Just to be sure. See Automattic/jetpack#13698 (comment)
@jeherve jeherve removed the [Status] Needs Package Release This PR made changes to a package. Let's update that package now. label Oct 11, 2019

// We don't want to track user events during unit tests/CI runs.
if ( $user instanceof \WP_User && 'wptests_capabilities' === $user->cap_key ) {
return false;
}

// Don't track users who have opted out or not agreed to our TOS, or are not running an active Jetpack.
if ( ! \Jetpack::jetpack_tos_agreed() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Jetpack is not a package this means that his package is not usable outside of jetpack.
Which kind of defeats the purpose of this a package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Isn't it already an issue with this already?

if ( ! Jetpack::jetpack_tos_agreed() || ! empty( $_COOKIE['tk_opt-out'] ) ) {

Does this mean we should also refrain from relying on constants like JETPACK__PLUGIN_FILE or JETPACK__VERSION, that are not set anywhere but in Jetpack right now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't quite know.
but I always assume that the src folder is there code that is supposed to be working also outside of jetpack and the src are classes that could be used outside of Jetpack.

I think using a filter here instead would work well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enejb Is this what you had in mind? #13746

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constants are a different thing FWIW, we have the constants package and we can use it to access any constants inside packages without relying on the core plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Tracks [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants