Skip to content

Track signed in event on sign up#10280

Merged
theck13 merged 5 commits intodevelopfrom
track_signed_in_event_on_sign_up
Jul 30, 2019
Merged

Track signed in event on sign up#10280
theck13 merged 5 commits intodevelopfrom
track_signed_in_event_on_sign_up

Conversation

@planarvoid
Copy link
Copy Markdown
Contributor

@planarvoid planarvoid commented Jul 25, 2019

Fixes #10230

I've tried to identify the places where we're sure we have a token during the signup. I think there are 2 things that could happen. One is a successful Google signup and the other one is going through the magic link and getting the token there. I've covered these two use cases but there might be something wrong because the flow is really hard to follow.

As part of this PR I did a very small refactoring where I moved the AccountStore and SiteStore to the constructor of the LoginAnalyticsModule instead of passing it as parameters. I think that's the correct approach since the module is injected.

Let me know if this approach makes sense!

To test:

  • Check that the sign-up flow isn't broken.

Update release notes:

  • If there are user facing changes, I have added an item to RELEASE-NOTES.txt.

@planarvoid planarvoid added this to the 13.0 milestone Jul 25, 2019
@planarvoid planarvoid requested a review from aforcier July 25, 2019 08:13
@planarvoid planarvoid self-assigned this Jul 25, 2019
@peril-wordpress-mobile
Copy link
Copy Markdown

Messages
📖

This PR contains changes in the subtree libs/login/. It is your responsibility to ensure these changes are merged back into WordPress-Login-Flow-Android. Follow these handy steps!
WARNING: Make sure your git version is 2.19.x or lower - there is currently a bug in later versions that will corrupt the subtree history!

  1. cd WordPress-Android
  2. git checkout track_signed_in_event_on_sign_up
  3. git subtree push --prefix=libs/login/ https://github.com/wordpress-mobile/WordPress-Login-Flow-Android.git merge/WordPress-Android/10280
  4. Browse to https://github.com/wordpress-mobile/WordPress-Login-Flow-Android/pull/new/merge/WordPress-Android/10280 and open a new PR.

Generated by 🚫 dangerJS

@aforcier aforcier assigned aforcier and unassigned planarvoid Jul 29, 2019
public void onGoogleSignupFinished(String name, String email, String photoUrl, String username) {
AnalyticsTracker.track(AnalyticsTracker.Stat.SIGNUP_SOCIAL_SUCCESS);

mLoginAnalyticsListener.trackAnalyticsSignIn(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be trackAnalyticsSignIn(true)? I believe the flag is meant to identify self-hosted vs WP.com logins, and WP.com signups should count as the latter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(The same would apply to the change in WPMainActivity.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right of course! good catch

@aforcier
Copy link
Copy Markdown
Contributor

@planarvoid aside from my comment this looks good to me. Definitely 👍 on the DI refactor.

It's probably worth having someone who worked on signup take a look as well though as I agree the flow is fairly complex. @theck13 could you give this a once-over?

Copy link
Copy Markdown
Contributor

@theck13 theck13 left a comment

Choose a reason for hiding this comment

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

I agree with @aforcier that I believe both mLoginAnalyticsListener.trackAnalyticsSignIn(false); statements should be mLoginAnalyticsListener.trackAnalyticsSignIn(true);.

I'm not sure, but we might want to call mLoginAnalyticsListener.trackAnalyticsSignIn(true); immediately after LoginAnalyticsListener.trackCreatedAccount(username, email) instances. @aerych, can you confirm that's what is intended with the issue?

@aerych
Copy link
Copy Markdown
Contributor

aerych commented Jul 30, 2019

can you confirm that's what is intended with the issue?

Basically, once we've obtained the user's bearer token, we want to bump the signed in stat. If that happens immediately after we bump account created, then yes.

@planarvoid
Copy link
Copy Markdown
Contributor Author

@theck13 You're definitely right with the SignupGoogleFragment, it was already happening at the same moment so I moved the both calls next to each other.
It's hard for me to find out about the WPMainActivity case. I'm basically tracking the moment when we retrieve the token from the magic link and I'm not sure what steps are happening between that and onAccountChanged call which triggers the trackMagicLinkSignupIfNeeded. WDYT?

@aforcier
Copy link
Copy Markdown
Contributor

👍 to the move to the SignupGoogleFragment.

For the WPMainActivity (signup via magic link) case, I'm not completely sure. Here's my take:

Where it currently is, it triggers when we extract the token from the magic link. This matches the criterion of "once we've obtained the user's bearer token" for dispatching the tracks event, but at this point we wouldn't know if the token was invalid for any reason.

If we move it to where trackCreatedAccount is called (inside trackMagicLinkSignupIfNeeded()), we're relying on these things having gone well:

  1. Token is registered with FluxC properly
  2. AccountAction.FETCH_ACCOUNT was dispatched and came back from the server successfully
  3. The account has been updated with a username and e-mail

My instinct would be to leave it where it is, as some of those things can go wrong and succeed later after retrying without needing a new token (so I would count the user as already 'logged in').

Since ultimately we're trying to be consistent with iOS though, @aerych could you tell us at which point this event is fired on that platform? Is it right when the token is obtained from the magic link or sometime later?

@aforcier
Copy link
Copy Markdown
Contributor

Note: I'm taking this PR over for @planarvoid since he's going on vacation.

@jkmassel
Copy link
Copy Markdown
Contributor

I'm bumping this to 13.1 as part of the 13.0 code freeze.

If you'd like it to be released as part of 13.0, please merge it against release/13.0 then DM me, and I'll be happy to issue a new beta release! :)

@jkmassel jkmassel modified the milestones: 13.0, 13.1 Jul 30, 2019
@aerych
Copy link
Copy Markdown
Contributor

aerych commented Jul 30, 2019

at which point this event is fired on that platform? Is it right when the token is obtained from the magic link or sometime later?

Its actually a bit later. (My earlier comment wasn't terribly accurate.) The tl;dr is we bump the signed in stat once account information has been synced. This is true for both sign up and log in flows.

Here are the relevant code points:

  • The magic links is clicked, the app is launched, and the token extracted. The user is presented with an instance of the NUXLinkAuthViewController to look at while account information is synced. The account created stat is bumped from here. Note that the stat is bumped while the api call(s) to sync account information are in flight.

  • To sync account info,NUXLinkAuthViewController calls a method declared in LoginViewController called syncWPComAndPresentEpilogue #. This in turn calls syncWPCom #, which calls a method on the authentication delegate (the actual WordPress app) to perform the sync. When syncing account and blog information is complete the completion callback block is executed, and we see that here is where we finally bump the signed in stat.

@aforcier
Copy link
Copy Markdown
Contributor

aforcier commented Jul 30, 2019

@aerych thanks for the walkthrough on that!

Then, given that:
a. iOS is bumping the stat after account info is fetched and we want to be as consistent as possible, and
b. We're storing whether signup tracks need to be sent or not in a preference (AppPrefs.getShouldTrackMagicLinkSignup()), which will persist and should cause the event to be tracked on the first successful account fetch even if the app is restarted,

I propose we move the call to trackAnalyticsSignIn() to the same place we call trackCreatedAccount() for the e-mail sign up flow, as @theck13 had suggested:

private void trackMagicLinkSignupIfNeeded() {
AccountModel account = mAccountStore.getAccount();
if (!TextUtils.isEmpty(account.getUserName()) && !TextUtils.isEmpty(account.getEmail())) {
mLoginAnalyticsListener.trackCreatedAccount(account.getUserName(), account.getEmail());
mLoginAnalyticsListener.trackSignupMagicLinkSucceeded();
AppPrefs.removeShouldTrackMagicLinkSignup();
}
}

WDYT @theck13 ?

@theck13
Copy link
Copy Markdown
Contributor

theck13 commented Jul 30, 2019

Just for clarification, we would only move the trackAnalyticsSignIn() instance in WPMainActivity to the location in your code snippet above and leave the other trackAnalyticsSignIn() instances as is, right? If so, that makes sense to me.

@aforcier
Copy link
Copy Markdown
Contributor

aforcier commented Jul 30, 2019

@theck13 yep! Just this one would be moved.

This is more consistent with when iOS dispatches a
signed in event during e-mail sign up.
@theck13 theck13 merged commit f76d724 into develop Jul 30, 2019
@theck13 theck13 deleted the track_signed_in_event_on_sign_up branch July 30, 2019 21:57
@aerych
Copy link
Copy Markdown
Contributor

aerych commented Jul 31, 2019

Thank you, everyone, for wrangling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analytics: Bump the the signed_in event at the end of account creation

5 participants