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

Improve login redirects and step tracking in stepper #91241

Merged

Conversation

daledupreez
Copy link
Contributor

@daledupreez daledupreez commented May 29, 2024

Related to:

Fixes #91243

Proposed Changes

  • This PR introduces some key concepts into the core Stepper framework to allow us to better handle logged out users and the redirects that stem from them. The key changes are as follows:
    • Stepper steps now have an optional requiresLoggedInUser flag that should be specified in flow.useSteps()
      • The PR includes stepWithRequiredLogin() and stepsWithRequiredLogin() helpers to set this flag easily
    • The pre-existing StepRoute component now checks whether the current step has a truthy requiresLoggedInUser value, and will not render any content if the user is also not logged in, as well as triggering a redirect to log the user in.
    • The logic to trigger calypso_signup_step_start Tracks events has been moved from FlowRenderer to StepRoute, and we won't trigger the Tracks event if the StepRoute logic from above performs a login redirect for a step that requires a login

Why are these changes being made?

  • We've been having internal discussions around improvements to the way Stepper handles Tracks and logins, and one of the key items that was flagged is that the current implementation can send calypso_signup_step_start Tracks events even when the user doesn't see the step. This PR attempts to resolve this by "knowing" whether a specific step requires the user to be logged in, and performing a redirect when necessary, as well as skipping rendering and triggering a Tracks event when we know a redirect should occur.
    • For now, the new skip logic only occurs when the step is "opted in" to the new requirement, but it should be relatively easy to roll out the behaviour on a flow-by-flow basis.

Testing Instructions

  • Run this branch locally or via Calypso.live
  • Open a window where you are not logged in
  • Ensure you have some way of seeing Tracks events
  • Navigate to any of the URLs at or below /setup/site-migration, including:
    • /setup/site-migration/
    • /setup/site-migration/site-migration-identify
    • /setup/site-migration/site-migration-import-or-migrate
    • /setup/site-migration/site-migration-upgrade-plan
    • /setup/site-migration/site-migration-instructions-i2
  • Verify that you're redirected to the login page, and the redirect URL will return you to your original location. Also verify that no calypso_signup_step_start Tracks event was recorded for the site-migration flow.
  • Add URL parameters to the URLs above, and verify that you are still redirected to login and these URL parameters are included in the redirect URL used by the login page. You should still see no calypso_signup_step_start Tracks events for the site-migration flow.
  • Specify a valid locale URL parameter for some of the above URLs, and verify that you're redirected to the right login page with the locale in the path and the redirect URL for the login page includes the relevant non-English locale. You should still see no calypso_signup_step_start Tracks events for the site-migration flow.
  • In a second window where you are logged in, work through the same set of URLs above and verify that you're seeing the calypso_signup_step_start event being fired correctly for the site-migration flow
  • In the same logged-in window, work through some other flows and verify that you're seeing the calypso_signup_step_start event being fired correctly

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@daledupreez daledupreez added [Feature] Tracks Metrics & Monitoring Capturing analytics about user behavior on WordPress.com. [Feature] Signup & Account Creation All screens and flows for making a new WordPress.com account. [Feature Group] Signup & Site Onboarding Tools for user registration and onboarding new users to the site. Stepper [Feature] Tailored Onboarding Flows All onbaording flows targeted to a specific marketshare / audience. labels May 29, 2024
@daledupreez daledupreez self-assigned this May 29, 2024
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 29, 2024
@matticbot
Copy link
Contributor

matticbot commented May 29, 2024

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~588 bytes added 📈 [gzipped])

name           parsed_size           gzip_size
entry-stepper      +2330 B  (+0.1%)     +588 B  (+0.1%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~11655 bytes removed 📉 [gzipped])

name                           parsed_size            gzip_size
site-migration-flow                -2026 B   (-3.8%)     -694 B   (-7.3%)
hosted-site-migration-flow         -2026 B   (-3.8%)     -695 B   (-7.3%)
assembler-first-flow               -1494 B   (-2.0%)     -503 B   (-3.3%)
ai-assembler-flow                  -1494 B   (-2.0%)     -499 B   (-3.2%)
blog                               -1477 B  (-47.5%)     -557 B  (-40.4%)
tailored-ecommerce-flow            -1468 B  (-13.3%)     -514 B  (-14.8%)
start-writing-flow                 -1468 B   (-5.8%)     -470 B   (-7.3%)
migration-signup                   -1468 B   (-2.9%)     -487 B   (-5.7%)
free-flow                          -1468 B   (-2.7%)     -497 B   (-5.1%)
entrepreneur-flow                  -1468 B   (-1.3%)     -610 B   (-2.0%)
domain-user-transfer-flow          -1468 B   (-0.6%)     -486 B   (-1.0%)
design-first-flow                  -1468 B   (-5.6%)     -461 B   (-7.0%)
connect-domain                     -1468 B   (-5.2%)     -501 B   (-6.5%)
write-flow                         -1459 B   (-0.2%)     -451 B   (-0.2%)
reblogging-flow                    -1242 B  (-14.5%)     -454 B  (-16.1%)
newsletter-flow                    -1242 B   (-5.7%)     -422 B   (-6.9%)
new-hosted-site-flow               -1242 B  (-15.9%)     -428 B  (-16.2%)
link-in-bio-flow-domain            -1242 B   (-4.4%)     -456 B   (-6.0%)
link-in-bio-flow                   -1242 B   (-6.0%)     -415 B   (-7.0%)
import-hosted-site-flow            -1242 B   (-0.1%)     -346 B   (-0.1%)
hundred-year-plan                  -1242 B   (-3.2%)     -394 B   (-3.5%)
google-transfer                    -1242 B  (-19.6%)     -465 B  (-20.9%)
domain-transfer                    -1242 B  (-20.5%)     -466 B  (-21.3%)
link-in-bio-tld-flow               -1233 B   (-0.1%)     -373 B   (-0.1%)
trial-wooexpress-flow               -217 B   (-0.5%)      -65 B   (-0.9%)
transferring-hosted-site-flow        +18 B   (+0.0%)      +19 B   (+0.1%)
plugin-bundle-flow                   +18 B   (+0.0%)      +16 B   (+0.0%)
copy-site-flow                       +18 B   (+0.0%)      +15 B   (+0.0%)
build-flow                           +18 B   (+0.0%)      +19 B   (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@daledupreez daledupreez requested a review from ddc22 May 29, 2024 12:15
@gabrielcaires gabrielcaires self-assigned this May 29, 2024
@gabrielcaires
Copy link
Contributor

gabrielcaires commented May 29, 2024

@daledupreez I started adding tests to your change and found a scenario I want to confirm.

Should we skip the tracking when the renderStep returns a null content?

I implemented this scenario on this commit 433160a

@gabrielcaires
Copy link
Contributor

@daledupreez I committed this temporary change 355cce9 with some ideas to clean up the code based on this change.

@gabrielcaires gabrielcaires force-pushed the try/improve-login-redirects-and-step-tracking-in-stepper branch from 355cce9 to f07f3e2 Compare May 29, 2024 17:56
Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

I can't tell you how much I appreciate this. Thank you so so much sir. Left a few comments here and there.

Comment on lines +49 to +52
/**
* Does the step require a logged-in user?
*/
requiresLoggedInUser?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

We should make a new type entirely that requires (requiresLoggedInUser) and deprecate the existing ones, so people get deprecation warnings from TS and the flows would organically upgrade to the new type.

I do something like that here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally left this as optional for now, mostly because the login requirement is actually flow-specific. So I don't think we should define the login requirement as part of the core step definition. (More on that below.)

Copy link
Member

Choose a reason for hiding this comment

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

You're right. Maybe it should be requiresLoggedInUser?: true?

Comment on lines 17 to 22
const redirectTo = addQueryArgs( location.pathname, {
...( locale && locale !== 'en' ? { locale } : {} ),
...( siteId ? { siteId } : {} ),
...( siteSlug ? { siteSlug } : {} ),
...Object.fromEntries( new URLSearchParams( location.search ).entries() ),
} );
Copy link
Member

@alshakero alshakero May 29, 2024

Choose a reason for hiding this comment

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

100% a nit, but I would spread this into 4 ifs

Suggested change
const redirectTo = addQueryArgs( location.pathname, {
...( locale && locale !== 'en' ? { locale } : {} ),
...( siteId ? { siteId } : {} ),
...( siteSlug ? { siteSlug } : {} ),
...Object.fromEntries( new URLSearchParams( location.search ).entries() ),
} );
let redirectTo = location.pathname;
if ( locale && locale !== 'en' ) {
redirectTo = addQueryArgs( location.href, { locale } );
}
if ( siteId ) {
redirectTo = addQueryArgs( location.href, { siteId } );
}
if ( siteSlug ) {
redirectTo = addQueryArgs( location.href, { siteSlug } );
}
if ( siteSlug ) {
redirectTo = addQueryArgs( location.href, { siteSlug } );
}

And I think if we use location.href (vs pathname) we don't need to consider the pre-existing params manually.

Copy link
Contributor Author

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

I have some feedback from inspection. I'll start some testing shortly.

@gabrielcaires
Copy link
Contributor

@daledupreez I created a second PR, based on this on just to address the renderStep issue. #91345

@daledupreez daledupreez marked this pull request as ready for review May 31, 2024 14:15
Comment on lines 61 to 68
if ( ! siteSlug && ! siteId && ! isHostedSiteMigrationFlow( this.variantSlug ?? FLOW_NAME ) ) {
window.location.assign( '/start' );
result = {

return {
state: AssertConditionState.FAILURE,
message: 'site-setup did not provide the site slug or site id it is configured to.',
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering if we have two issues in this code block:

  1. This should be inside useEffect()
  2. Should this code also be checking for whether we have a logged-in user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a follow-up, I think this is another situation where we had an implicit dependency on the login redirect logic, which we've now removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix pushed in 4614bf4.

@daledupreez daledupreez changed the title [WIP] Improve login redirects and step tracking in stepper Improve login redirects and step tracking in stepper Jun 3, 2024
@gabrielcaires gabrielcaires dismissed alshakero’s stale review June 4, 2024 17:04

Dismissing to request a new one

@gabrielcaires gabrielcaires requested review from gabrielcaires and removed request for gabrielcaires June 4, 2024 17:04
@alshakero
Copy link
Member

alshakero commented Jun 4, 2024

It seems the /setup/site-migration flow is redirecting me to /start. Am I missing something?

@gabrielcaires
Copy link
Contributor

gabrielcaires commented Jun 5, 2024

It seems the /setup/site-migration flow is redirecting me to /start. Am I missing something?

@alshakero
You can't access this flow directly without having a site defined &siteId=[SiteId], &siteSlug='someSlug'

Copy link
Contributor Author

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

@gabrielcaires, I have re-tested, and I think we are OK to get this shipped. I can't approve as the original PR author, but let me know if you have any concerns about shipping this as-is.

@gabrielcaires gabrielcaires merged commit 7fdd454 into trunk Jun 6, 2024
12 checks passed
@gabrielcaires gabrielcaires deleted the try/improve-login-redirects-and-step-tracking-in-stepper branch June 6, 2024 08:31
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Signup & Site Onboarding Tools for user registration and onboarding new users to the site. [Feature] Signup & Account Creation All screens and flows for making a new WordPress.com account. [Feature] Tailored Onboarding Flows All onbaording flows targeted to a specific marketshare / audience. [Feature] Tracks Metrics & Monitoring Capturing analytics about user behavior on WordPress.com. Stepper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stepper: only trigger calypso_signup_step_start Tracks events when step is actually rendered
4 participants