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

Add Organic Sessions widget #22073

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from

Conversation

igorschoester
Copy link
Member

@igorschoester igorschoester commented Feb 25, 2025

Context

Summary

This PR can be summarized in the following changelog entry:

  • Adds the Organic Sessions widget to the dashboard.

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:

  • Make sure you have an environment with site kit configured with analytics.
  • Make sure site kit is not connected to yoast.
  • Connect to site kit and check you see the organic sessions widget with data.
  • Check the space between the ticks and the chart match the design.
  • Check the font weight and sizes are matching the design.
  • Check the error message is not duplicated if it's the same for both change and daily data. You can do that by opening the network tab in the devtools and change connection to offline. Change the tab to Alert center and go back to the Dashboard.
  • Check the widget title is "Organic sessions"
  • Check the tooltip has the text: "The number of organic sessions that began on your website. "
  • Check the learn more link is "https://yoa.st/dashboard-organic-sessions-learn-more" with link params.
  • Check the info icon is aligned to the title.
  • Check the tooltip arrow is aligned to the i icon.
  • Check the chart has gradient color.
  • Mock no data by changing the respone to empty array in src/dashboard/user-interface/time-based-seo-metrics/time-based-seo-metrics-route.php, line 207:
return new WP_REST_Response(
			[],
			200
		);
  • Check you get only once the message "No data to display: Your site hasn't received any visitors yet."

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:

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 https://github.com/Yoast/reserved-tasks/issues/411

@igorschoester igorschoester added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Feb 25, 2025
@coveralls
Copy link

coveralls commented Feb 25, 2025

Pull Request Test Coverage Report for Build 7df84ae28a5f78d3bb0730712ce6aeadd7b6fa84

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

  • 58 of 68 (85.29%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 57.977%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/js/src/dashboard/services/data-formatter.js 3 5 60.0%
packages/js/src/dashboard/widgets/organic-sessions/daily.js 24 32 75.0%
Totals Coverage Status
Change from base Build 7cbd66303be34423496ddf03e68a394b9457f322: 0.07%
Covered Lines: 13755
Relevant Lines: 23363

💛 - Coveralls

Copy link

A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch.

@vraja-pro vraja-pro marked this pull request as ready for review February 26, 2025 16:38
Copy link
Contributor

@thijsoo thijsoo left a comment

Choose a reason for hiding this comment

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

CR 🚧 some questions and feedback

@@ -98,6 +100,16 @@ export class WidgetFactory {
remoteDataProvider={ this.#remoteDataProvider }
dataFormatter={ this.#dataFormatter }
/>;
case WidgetFactory.types.organicSessions:
if ( ! isFeatureEnabled || ! isConnected ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be a GA 4 connected check as well not just connected. It should be in the script data as isGAConnected

const current = data?.current?.sessions || 0;
const previous = data?.previous?.sessions || 0;
// Delta / average.
const difference = Math.abs( current - previous ) / ( ( current + previous ) / 2 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to have an early return here if both current && previous end up 0?

* @param {DataFormatter} dataFormatter The data formatter.
* @returns {{data: *, error: Error, isPending: boolean}} The remote data info.
*/
export const useOrganicSessionsChange = ( dataProvider, remoteDataProvider, dataFormatter ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might need a bit of a comment describing what happens here, because to me it seems a lot is happening here.

* @param {DataProvider} dataProvider The data provider.
* @param {RemoteDataProvider} remoteDataProvider The remote data provider.
* @param {DataFormatter} dataFormatter The data formatter.
* @returns {{data: *, error: Error, isPending: boolean}} The remote data info.
Copy link
Contributor

Choose a reason for hiding this comment

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

Shoud data: * not be data: our defined response?

* @returns {function(?RawOrganicSessionsChangeData[]): OrganicSessionsChangeData} Function to format the organic sessions change data.
*/
// eslint-disable-next-line complexity -- Fallbacks to zero, easy enough to read.
export const createOrganicSessionsChangeFormatter = ( dataFormatter ) => ( [ data ] ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the word Change everywhere and in the Back-end we use Compare everywhere for these different comparisons between a previous period and the current one. Lets choose one and stick to it.

* @param {DataFormatter} dataFormatter The data formatter.
* @returns {function(?OrganicSessionsDailyData[]): OrganicSessionsDailyData[]} Function to format the organic sessions daily data.
*/
export const createOrganicSessionsDailyFormatter = ( dataFormatter ) => ( data = [] ) => data.map( ( item ) => ( {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this export needed?

* @returns {function(?RawOrganicSessionsChangeData[]): OrganicSessionsChangeData} Function to format the organic sessions change data.
*/
// eslint-disable-next-line complexity -- Fallbacks to zero, easy enough to read.
export const createOrganicSessionsChangeFormatter = ( dataFormatter ) => ( [ data ] ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the export needed?

* @param {DataFormatter} dataFormatter The data formatter.
* @returns {{data: *, error: Error, isPending: boolean}} The remote data info.
*/
export const useOrganicSessionsDaily = ( dataProvider, remoteDataProvider, dataFormatter ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments as with the other method might benefit from a little explanation what this all does?

*/
const getOrganicSessionsDaily = useCallback( ( options ) => {
return remoteDataProvider.fetchJson(
dataProvider.getEndpoint( "timeBasedSeoMetrics" ),
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to also define all endpoints as a constant somewhere since we have quite a few random strings all over the place

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.

4 participants