Skip to content

Fix the advanced tracking of the Site Kit integration#22546

Merged
vraja-pro merged 1 commit intotrunkfrom
763-fix-the-tracking-of-site-kit-options
Sep 2, 2025
Merged

Fix the advanced tracking of the Site Kit integration#22546
vraja-pro merged 1 commit intotrunkfrom
763-fix-the-tracking-of-site-kit-options

Conversation

@leonidasmi
Copy link
Copy Markdown
Contributor

@leonidasmi leonidasmi commented Sep 1, 2025

Context

Summary

This PR can be summarized in the following changelog entry:

  • Fixes the advanced tracking of the Site Kit integration.

Relevant technical choices:

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Preparation:

  • In order to assess whether we're tracking what we think we do, we have to do the below steps
  • Add the following filter:
add_filter( 'pre_http_request', function( $preempt, $args, $url ) {
    // Only intercept requests to https://tracking.yoast.com/stats
    if ( strpos( $url, 'https://tracking.yoast.com/stats' ) === 0 ) {
        // Log details to debug.log
        if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
            error_log( '--- Intercepted Request ---' );
            error_log( 'URL: ' . $url );
            error_log( 'Method: ' . ( isset( $args['method'] ) ? $args['method'] : 'N/A' ) );
            error_log( 'Arguments: ' . print_r( $args, true ) );
            error_log( '---------------------------' );
        }

        // Return a dummy response instead of actually performing the request
        return array(
            'headers'  => array(),
            'body'     => '',
            'response' => array(
                'code'    => 200,
                'message' => 'Intercepted',
            ),
            'cookies'  => array(),
            'filename' => null,
        );
    }

    // For other requests, let WP continue as normal
    return $preempt;
}, 10, 3 );
  • The above will intercept your tracking from sending it to yoast.com and instead log it in your debug.log
  • Also add the following, so that there's no heartbeat pings that might trigger tracking requests without our knowledge:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
	wp_deregister_script('heartbeat');
}
  • That way, we can trigger a tracking response only with a refresh of an admin page.
  • In admin\class-admin.php, find the WEEK_IN_SECONDS and turn it into MINUTE_IN_SECONDS
    • Important: Make sure you revert this change as soon as possible, so that you don't spam yoast.com with tracking requests.
  • In your wp-config.php, add the following to enable logging:
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
  • Make sure you have enabled tracking on your setup (you can do so in the last step of the FTC)

Test the fix:

  • In a fresh site with no Site Kit installed.
  • Go to a Yoast page (but not the dashboard page) and that will trigger your tracked settings to be sent over.
  • Check your debug.log file and search for the "settings" object
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "no",
        "site_kit_tracking_first_interaction_stage": "",
        "site_kit_tracking_last_interaction_stage": "",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": false,
  • Using the modified test helper, enable the Site Kit feature flag (you can use this version of the test helper to do so), wait for a minute and refresh the Yoast page
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "no",
        "site_kit_tracking_first_interaction_stage": "",
        "site_kit_tracking_last_interaction_stage": "",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,
  • Go to the Yoast Dashboard page, wait a minute and then refresh the other Yoast page you have open
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "yes",
        "site_kit_tracking_first_interaction_stage": "install",
        "site_kit_tracking_last_interaction_stage": "install",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,
  • Install Site Kit, dont activate it, go to Dashboard again, wait a minute and refresh the Yoast page
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "yes",
        "site_kit_tracking_first_interaction_stage": "install",
        "site_kit_tracking_last_interaction_stage": "activate",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,
  • Activate Site Kit, dont set it up, go to Dashboard again, wait a minute and refresh the Yoast page
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "yes",
        "site_kit_tracking_first_interaction_stage": "install",
        "site_kit_tracking_last_interaction_stage": "setup",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,
  • Set up Site Kit, dont give consent to Yoast, go to Dashboard again, wait a minute and refresh the Yoast page
  • Confirm that you see the following settings there:
        "site_kit_connected": false,
        "site_kit_tracking_setup_widget_loaded": "yes",
        "site_kit_tracking_first_interaction_stage": "install",
        "site_kit_tracking_last_interaction_stage": "grantConsent",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,
  • Give consent to Yoast in the Yoast Dashboard, wait a minute and refresh the Yoast page
  • Confirm that you see the following settings there:
        "site_kit_connected": true,
        "site_kit_tracking_setup_widget_loaded": "yes",
        "site_kit_tracking_first_interaction_stage": "install",
        "site_kit_tracking_last_interaction_stage": "successfullyConnected",
        "site_kit_tracking_setup_widget_temporarily_dismissed": "no",
        "site_kit_tracking_setup_widget_permanently_dismissed": "no",
        "google_site_kit_feature_enabled": true,

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

@leonidasmi leonidasmi added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Sep 1, 2025
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22eca21e10e0dac09e960da6b21a8b1cecc48895

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 52.681%

Totals Coverage Status
Change from base Build df628e35a752b0d81227e1b68ea64781c576ccb0: -0.5%
Covered Lines: 31166
Relevant Lines: 59280

💛 - Coveralls

@leonidasmi leonidasmi marked this pull request as ready for review September 2, 2025 11:16
Copy link
Copy Markdown
Contributor

@vraja-pro vraja-pro left a comment

Choose a reason for hiding this comment

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

CR & AC ✅

@vraja-pro vraja-pro added this to the 26.0 milestone Sep 2, 2025
@vraja-pro vraja-pro merged commit e918c1a into trunk Sep 2, 2025
30 of 31 checks passed
@vraja-pro vraja-pro deleted the 763-fix-the-tracking-of-site-kit-options branch September 2, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants