-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Move calls for email magic link to data-layer #38866
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~25886 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~27809 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~11905 bytes removed 📉 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. 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. Generated by performance advisor bot at iscalypsofastyet.com. |
If I tagged the wrong folks, feel free to suggest more appropriate reviewer from @Automattic/hogwarts |
this.props
.fetchMagicLoginRequestEmail( usernameOrEmail, this.props.redirectTo )
.then( () => {
this.props.recordTracksEvent( 'calypso_login_email_link_success' );
} )
.catch( error => {
this.props.recordTracksEvent( 'calypso_login_email_link_failure', {
error_code: error.error,
error_message: error.message,
} );
} ); In these cases did you try to send the analytics event names in the original action? I know it sounds a little dirty but I think it could one way to remove the coupling. sendMobileEmailLogin( email, { showGlobalNotices: true, statsType: 'login-form' } ) export const displaySuccessMessage = ( { showGlobalNotices, infoNoticeId = null, statsType } ) => [
// Default Global Notice Handling
...( showGlobalNotices
? [
removeNotice( infoNoticeId ),
successNotice( translate( 'Email Sent. Check your mail app!' ), {
duration: 4000,
} ),
]
: [] ),
statsTypes === 'login' ?
tracksEvent( 'calypso_login_block_login_form_send_magic_link_success' ) :
statsTypes === 'magic-login' ?
tracksEvent( 'calypso_login_email_link_success' ) :
emptyAction
]; or since they are just actions, maybe even passing the onSuccess/onFailure tracks events as properties on the action sendMobileEmailLogin( email, {
showGlobalNotices: true,
actionOnAPISuccess: tracksEvent( … ),
actionOnAPIFailure: tracksEvent( … )
} ) export const displaySuccessMessage = ( { showGlobalNotices, infoNoticeId = null, actionOnAPISuccess } ) => [
// Default Global Notice Handling
...( showGlobalNotices
? [
removeNotice( infoNoticeId ),
successNotice( translate( 'Email Sent. Check your mail app!' ), {
duration: 4000,
} ),
]
: [] ),
actionOnAPISuccess
]; |
I did try passing arrays of arbitrary actions in 76195ba but it does require some action decoration in the error handler (it expects error information for example). I could try that again tomorrow and see if it doesn't bloat this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested locally and with the branch's test site. Happy to confirm that the promo and the get-apps CTA both still worked for me with these changes.
I'll leave it to others with modern JS skills to comment on the code and approve.
client/state/mobile-apps/actions.js
Outdated
|
||
export const sendMobileEmailLogin = ( email, { redirectTo, showGlobalNotices = false } ) => { | ||
//Kind of weird usage, but this is a straight port from undocumented.js for now. | ||
//I can move this to the caller, if there's equivalent info in the state tree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @jsnajdr had some thoughts on where the authoritative l10n info should come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to update, if y'all had recommendations 👍
5d434f3
to
d59f351
Compare
Thanks I'll try rebasing @mmtr ! |
… and error events
d59f351
to
35c6b1f
Compare
Looking at usages, I was only able to find an import for |
oh hmm there are usages calling 🤔@jsnajdr if someone wanted to dispatch |
@gwwar ditto, I don't see any usage. Looks safe to drop. |
fd6a6f1
to
35c6b1f
Compare
Oh hmm, okay maybe I'll just try the inverse again and let the data-layer handler be knowledgeable about all flows. If this doesn't work I'll scale this PR back out of login form flows |
All set for another look 👍 I think lint will probably be unhappy from autofocus, but I didn't want to change behavior here. |
: [] ), | ||
...( loginFormFlow | ||
? [ recordTracksEventWithClientId( 'calypso_login_block_login_form_send_magic_link' ) ] | ||
: [] ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
I know I know I know, but still, I approve these changes. thanks for making a hard call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do hope folks know we can also add add tracks and other types of analytics events in the API in server code :D I think it's a lot less interesting for the client to track non-user initiated actions.
scheme: 'wordpress', | ||
} ); | ||
|
||
this.props.sendEmailLogin( email, { showGlobalNotices: false, isMobileAppLogin: true } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we defer isMobileAppLogin
to this.state.promoItem.type === 'mobile'
? Or am I'm missing the intent of the promoItem
object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, just noted sendMagicLink
is only called from mobilePromo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this worked pretty well on my tests. Nice refactor @gwwar!
I couldn't fully review the code yet, but I'm not sure if we should check for the promo type on the app promo component. Will try to review rest of code before heading out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, code looks good to me 👍 E2E failures seem unrelated.
Login Flow with User account that has no password
I'm actually not sure how to create a user account like that, but I'm reasonably sure the code is correct here.
Yeah, I'm confident too. We can always open a follow up PR if we spot any regression.
Thanks @mmtr, I'll give this a shot and will revert if this causes regressions. |
This PR cleans up some older data patterns, and moves calls to
/auth/send-login-email
from undocumented.js to the data-layer.Part of #38861 this will enable cleaner reuse in other components.
For reference the new
sendEmailLogin
may trigger two types of emails, one for Native Mobile App logins, and the other for WordPress.com loginsTesting Instructions
/me/get-apps
localStorage.debug='calypso:analytics*';
Verify that a tracks event calledcalypso_get_apps_magic_link_button_click
fires.Reader Promo
- If successful, verify that a mobile email was sent - We should see a modal pop up with a message that an email has been sent
Login Flow
npm start
(changes won't be picked up if folks switched branches while Calypso was running)- Verify that the email sent is the **desktop** login variant and that it works - On Error (try an email you own that is not associated with an account) we should see an error in UI and the following analytics events fire.
Login Flow with User account that has no password
Edit: according to @kriskarkoski we should be able to create an account like this starting from https://wordpress.com/start/user?ref=logged-out-homepage-lp and choosing apple or google for user creation.