Skip to content

Conversation

sergeymitr
Copy link
Contributor

@sergeymitr sergeymitr commented Sep 7, 2024

Proposed changes:

  • Optimize the way we initialize ToS component.

Tracking of Jetpack-the-plugin events is initialized on-demand via do_action( 'jetpack_initialize_tracking' ).
The action will first check if tracking is allowed to be initialized.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

pdWQjU-QN-p2#comment-918
https://github.com/Automattic/vulcan/issues/503

Does this pull request change what data or activity we track or use?

We modify the way we initialize tracking, but do not add or remove any tracking events.

Testing instructions:

  1. Disconnect Jetpack if connected, but set the jetpack_tos_agreed option (wp option update jetpack_tos_agreed 1).
  2. Edit the file/jetpack/src/class-tracking.php, find the init() method and add the following code before static::$initialized = true;:
error_log( 'Jetpack Tracking initialized' );
  1. Visit a few non-Jetpack admin pages, confirm debug.log stays empty.
  2. Visit "My Jetpack", confirm Jetpack Tracking initialized line shows up in debug.log (there'll be a few due to API requests).
  3. Visit other Jetpack pages, confirm new log entries show up for each.
  4. Run an XML-RPC request, confirm new log entry gets added:
curl -is -H 'Content-Type: text/xml' --data '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>' 'https://yours-site.example/xmlrpc.php?for=jetpack' && echo
  1. Open a REST route in the browser (e.g. https://your-site.example/?rest_route=%2Fjetpack%2Fv4%2Fconnection), confirm new log entry gets added.
  2. Connect Jetpack, confirm new entries show up even on non-Jetpack pages.

Copy link
Contributor

github-actions bot commented Sep 7, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the update/jetpack-tos-initialization branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack update/jetpack-tos-initialization
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Sep 7, 2024
Copy link
Contributor

github-actions bot commented Sep 7, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for October 1, 2024 (scheduled code freeze on September 30, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@sergeymitr sergeymitr force-pushed the update/jetpack-tos-initialization branch from 54499d0 to 854f57c Compare September 7, 2024 22:46
@sergeymitr sergeymitr added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 10, 2024
@sergeymitr sergeymitr requested a review from a team September 10, 2024 00:57
Copy link
Contributor

@coder-karen coder-karen left a comment

Choose a reason for hiding this comment

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

Tests well for me! Left a couple of questions from reviewing the code.

Comment on lines +164 to +165
public function wp_login_failed() {
_deprecated_function( __METHOD__, '$$next-version$$' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entirely sure how we integrate with wp_login_failed elsewhere, but it looks like there's a few other places where we use do_action or add_action with wp_login_failed. Would removing it here have any affect on those use-cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've now realized it's an existing WordPress hook, but I'm still not too familiar with how it's used elsewhere in the monorepo and whether this version would attempt to be used. For example in class-sso.php, we import the Tracking class, so would the use-cases in that file attempt to use this wp_login_failed function over the WP hook? I'm guessing probably not as we'd need to explicitly use the Tracking class version in class-sso.php - but just wanted to double check.

Copy link
Contributor Author

@sergeymitr sergeymitr Sep 10, 2024

Choose a reason for hiding this comment

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

Thanks for taking a look!

I agree, it is a bit confusing due to the function having same name as the hook.
Essentially, this is a WP hook that may or may not have any functions attached to it.
But since we're not removing the hook, they won't be affected.

We only remove this particular function attached to the hook.
Its only purpose was to track failed logins, but that Tracks event has been blocked on our servers for years, so this code is now useless: pdWQjU-QN-p2#comment-918

In class-sso.php we run the wp_login_failed action because we try to imitate the login failure the same way WP Core does it. That functionality shouldn't be affected by the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks for explaining :)

Co-authored-by: Karen Attfield <karenlattfield@gmail.com>
@sergeymitr sergeymitr merged commit 9c6a672 into trunk Sep 10, 2024
57 checks passed
@sergeymitr sergeymitr deleted the update/jetpack-tos-initialization branch September 10, 2024 14:25
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Sep 10, 2024
@oskosk
Copy link
Contributor

oskosk commented Sep 10, 2024

oh amazing. I missed this one!

gogdzl pushed a commit that referenced this pull request Oct 25, 2024
Optimize the way we initialize ToS component.

---------

Co-authored-by: Karen Attfield <karenlattfield@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Performance [Package] Connection [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants