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

First run at a setup #21965

Merged
merged 15 commits into from
Jan 23, 2025
Merged

First run at a setup #21965

merged 15 commits into from
Jan 23, 2025

Conversation

thijsoo
Copy link
Contributor

@thijsoo thijsoo commented Jan 13, 2025

Context

  • We want to add the possibility to integrate with GSC.

Summary

This PR can be summarized in the following changelog entry:

  • Adds a endpoint to get your top 5 most view pages.

Relevant technical choices:

  • I used the same setup we are using for the scores by only needing a rest endpoint with some configuration to make the API request via Google Site Kit.
  • I have added a search-rankings-parser class that does not do alot yet but as a blueprint where we can link the indexables to the api results.
  • This PR does not have any fallbacks or checks to make sure site kit is configured or it takes a look a api limits. This is just a POC of the connection.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

With the YOAST_SEO_GOOGLE_SITE_KIT_FEATURE feature flag enabled:

  • To test this make sure you have a working Site Kit running.
  • Go to /wordpress-seo/src/dashboard/user-interface/search-rankings/abstract-ranking-route.php and comment out line 112.
  • Go to wp-json/yoast/v1/top_pages?limit=5 you should see an API response with your top 5 pages in terms of clicks. The response should look something like this:
 [
    {
        "clicks": 10,
        "ctr": 0.16393442622950818,
        "impressions": 61,
        "position": 28.278688524590162,
        "subject": "https://example.com/",
        "seoScore": 0
    },
    {
        "clicks": 3,
        "ctr": 0.076923076923076927,
        "impressions": 13,
        "position": 26.692307692307693,
        "subject": "https://example.com/page_1/",
        "seoScore": 0
    },
    {
        "clicks": 3,
        "ctr": 0,
        "impressions": 1,
        "position": 28.600000000000001,
        "subject": "https://example.com/page_2/",
        "seoScore": 0
    },
    {
        "clicks": 1,
        "ctr": 0,
        "impressions": 5,
        "position": 45,
        "subject": "https://example.com/page_3/",
        "seoScore": 0
    },
    {
        "clicks": 1,
        "ctr": 0,
        "impressions": 5,
        "position": 111,
        "subject": "https://example.com/page_4/",
        "seoScore": 0
    },
]
  • Go to wp-json/yoast/v1/top_queries?limit=5 you should see an API response with your top 5 queries in terms of clicks. The response will look like something like the above but with queries instead of URLs in the subject attributes.
  • Note that the seoScore is going to be 0 in all elements, since we haven't implemented that yet.

With the YOAST_SEO_GOOGLE_SITE_KIT_FEATURE feature flag disabled:

  • Repeat both requests and confirm you get an error response.

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.

QA can test this PR by following these steps:

  • This PR is just a blueprint for later development of this feauture. This pr does not need to be tested on its own.

Impact check

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

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

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 #

@thijsoo thijsoo added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Jan 13, 2025
@thijsoo thijsoo marked this pull request as ready for review January 14, 2025 13:08
@coveralls
Copy link

coveralls commented Jan 14, 2025

Pull Request Test Coverage Report for Build 2e90e5baee9d8bd392c2a163eb41788468aea0ff

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 123 (0.0%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on first-setup-for-gsc-api-integration at 51.119%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/dashboard/user-interface/search-rankings/top-page-route.php 0 3 0.0%
src/dashboard/user-interface/search-rankings/top-query-route.php 0 3 0.0%
src/dashboard/application/search-rankings/top-page-repository.php 0 4 0.0%
src/dashboard/application/search-rankings/top-query-repository.php 0 4 0.0%
src/dashboard/infrastructure/search-console/search-console-parameters.php 0 4 0.0%
src/dashboard/infrastructure/endpoints/search-rankings/top-page-endpoint.php 0 8 0.0%
src/dashboard/infrastructure/endpoints/search-rankings/top-query-endpoint.php 0 8 0.0%
src/dashboard/domain/data-provider/data-container.php 0 9 0.0%
src/dashboard/domain/data-provider/parameters.php 0 12 0.0%
src/dashboard/domain/search-rankings/search-data.php 0 16 0.0%
Totals Coverage Status
Change from base Build 9c66956756c0900e29fb6645e4308dfb47898de1: 51.1%
Covered Lines: 16657
Relevant Lines: 32585

💛 - Coveralls

Copy link
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

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

CR: 🏗️

Aside from the comments, I think there might be some changes in the architecture when we cross-reference the sitekit data with the indexable data, but let's tackle those with the next PR.

*
* @var int
*/
private $seo_score;
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 having reservations about whether the seo_score should be here or it should be injected by an indexable-related domain class, but let's see that in the final backend task for that widget.

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 unresolving this because indeed it needs to be dealt with in the future, so lets keep it open for future reference.

There are going to be search-ranking data that will not have seo scores, so we will need a tweak of the approach here, which we can do when we finalize the endpoint,

Copy link
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

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

I want to re-iterate this point and actually extend it for the whole data provider class.

These classes being in such a generic domain that's about dashboard in general, makes me feel weird about our already-implemented SEO/Readability score widgets that are also about dashboard, are also repositories that deal with data/parameters/anything else that directory is about, but are being excluded by those classes because they are different things.

In any case, I dont want to block merging this PR because of this, we can talk about it and maybe iterate it on the next stage, when the indexable data come into play

So, CR + Acceptance test is ✅

class Search_Data implements Data_Interface {

/**
* The amount of clicks a `key` gets.
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no longer a key but rather a subject. Don't want to block merging because of that, I'll correct in my subsequent PR if that's ok.

*
* @var int
*/
private $seo_score;
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 unresolving this because indeed it needs to be dealt with in the future, so lets keep it open for future reference.

There are going to be search-ranking data that will not have seo scores, so we will need a tweak of the approach here, which we can do when we finalize the endpoint,

@leonidasmi leonidasmi added this to the 24.5 milestone Jan 23, 2025
@leonidasmi leonidasmi merged commit 37106cf into trunk Jan 23, 2025
24 of 25 checks passed
@leonidasmi leonidasmi deleted the first-setup-for-gsc-api-integration branch January 23, 2025 12:46
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