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

Issues/7856 refresh meta data #7880

Merged
merged 11 commits into from
Jun 12, 2018
Merged

Conversation

aerych
Copy link
Member

@aerych aerych commented Jun 8, 2018

Fixes #7856

This PR ensures that analytics metadata is refreshed before bumping the account_created stat so that its not being sent as an anonymous user.

Since a username or email address is all that's needed to de-anonymize events, we either pass the username/email address (as in the Google sign up flow) or attempt to retrieve a saved email address from SharedPreferences (as in the email sign up flow).

To test:
The easiest way to test this is to sign up with each flow, then check the live view for the wpandroid_account_created event in the Tracks dashboard and wait to see your event appear.

Alternatively set breakpoints in AnalyticsTrackerNosara.refreshMetaData and ensure that mNosaraClient.trackAliasUser is called when signing up.

@hypest could I trouble you to take a peek at this one? Oguz has picked up the review after some early feedback from Stefanos. :)

@aerych aerych added this to the 10.2 milestone Jun 8, 2018
@aerych aerych requested a review from hypest June 8, 2018 23:53
@oguzkocer oguzkocer self-assigned this Jun 11, 2018
Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

@aerych I don't think I fully understand the decisions in this PR.

  • Is there a reason we are not doing a similar thing to trackAnalyticsSignIn in trackCreatedAccount, meaning why are we not passing the AccountStore and SiteStore to AnalyticsUtils.trackAnalyticsAccountCreated? I looked at the current code and I think that should work.
  • Although this is not in the current change set, I am a bit confused why we have a call to LoginAnalyticsTracker.trackCreatedAccount from both the WPMainActivity and SignupGoogleFragment. Shouldn't we be able to handle both type of signups from WPMainActivity and track the same way? That'll also resolve my first question.
  • If for some reason we do need it in preferences, we should move the related code to AppPrefs for consistency. The key should probably be moved to DeletablePrefKey, but again, only if we still have the preference code.

My suggestion would be:

  • Check the WPMainActivity.onAuthenticationChanged for google signup. Unless I am missing something, it should be triggered when SignupGoogleFragment.onAuthenticationChanged is triggered. If that's the case, remove the SignupGoogleFragment.onAuthenticationChanged and move the logic under WPMainActivity.onAuthenticationChanged.
  • Change the parameters for LoginAnalyticsTracker.trackCreatedAccount to accept an AccountStore and SiteStore and make that change in WPMainActivity.onAuthenticationChanged.
  • In AnalyticsUtils.trackAnalyticsAccountCreated remove all that custom logic and follow a similar pattern to AnalyticsUtils.trackAnalyticsSignIn. Better yet, extract the common parts of them.
  • Remove the preferences code completely.

@aerych I hope this helps! Let me know if you need help with any of this. I am happy to look into it further for you! Also feel free to ping someone from the login project in case I am missing something.

@aerych
Copy link
Member Author

aerych commented Jun 11, 2018

We caught up on Slack and did some pair programming to improve the patch, but just for the sake of looping back on Github...

Is there a reason we are not doing a similar thing to trackAnalyticsSignIn in trackCreatedAccount, meaning why are we not passing the AccountStore and SiteStore to AnalyticsUtils.trackAnalyticsAccountCreated?

It was because the AccountStore isn't updated with a valid username and email address when the code in WPMainActivity runs. You suggested a nice alternative approach that we'll try. :)

Although this is not in the current change set, I am a bit confused why we have a call to LoginAnalyticsTracker.trackCreatedAccount from both the WPMainActivity and SignupGoogleFragment. Shouldn't we be able to handle both type of signups from WPMainActivity and track the same way?

I'm not sure, but my guess is it was tricky to tell the difference between account creation and logging in from outside of the flow. As it stands the sign up stat is being bumped in both cases which I have mixed feelings about but felt it was out of scope to address here.

If for some reason we do need it in preferences, we should move the related code to AppPrefs for consistency. The key should probably be moved to DeletablePrefKey, but again, only if we still have the preference code.

Just to document the backstory, after some initial tinkering I had a chat with Nick and another with Stefanos about what I thought our options were. The trick is we need updated account info before refreshing metadata, and we need to refresh metadata before bumping account_created because we don't want that and subsequent stats to be anonymous. Where Stefanos and I ended up was thinking we could have a new service or a headless fragement listen for the onchange event after sign up, and then bump the stat that way. But when I started, there was something about it that was nagging at me. We should already have all the info we need to refreshmeta data without the service call. That's when I started thinking about using StoredPreferences.

The approach you suggested on our call is a bit of a hybrid between the stored prefs approach here, and the service/fragement approach I chatted with Stefanos about (in the sense that it refreshes the AccountStore), but with fewer moving parts, and less code required. :)

Update forthcoming!

@aerych aerych removed the request for review from hypest June 11, 2018 20:53
@aerych
Copy link
Member Author

aerych commented Jun 12, 2018

Changes implemented. I confirmed that events are correctly showing up in the tracks admin for both email and google flows.
Ready for another peek @oguzkocer !

Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

Looks good @aerych! I have a few minor suggestions, but this is good to merge as is!

mLoginAnalyticsListener.trackSignupMagicLinkSucceeded();
mDispatcher.dispatch(AccountActionBuilder.newFetchAccountAction());
// While unlikely, its possible the app could be closed before the onAccountChanged event is
// handled. Setting this flag lets us dispatch the event the next time the app opens.
Copy link
Contributor

Choose a reason for hiding this comment

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

Setting this flag doesn't actually lets us dispatch the event, it makes sure it's always handled in the OnAccountChanged even if the user quits the app after signup is completed and before OnAccountChanged could be triggered. Feel free to move this comment under onAccountChanged (or the helper method I mentioned in the other comment) if you think it'll be easier to understand where it's used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll move it to the helper

@@ -752,6 +755,14 @@ public void onAccountChanged(OnAccountChanged event) {
// Sign-out is handled in `handleSiteRemoved`, no need to show the signup flow here
if (mAccountStore.hasAccessToken()) {
mBottomNav.showNoteBadge(mAccountStore.getAccount().getHasUnseenNotes());
if (AppPrefs.getShouldTrackMagicLinkSignup()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed on the call, I think it'd be a good improvement to have this logic by itself in a helper method.

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Arg! Yes, this change slipped my mind.

@aerych
Copy link
Member Author

aerych commented Jun 12, 2018

Thanks Oguz! One last peek for paranoia sake?

@oguzkocer
Copy link
Contributor

Looks great :shipit:

Will merge once Travis is done!

@oguzkocer oguzkocer merged commit 3e6e6a4 into release/10.2 Jun 12, 2018
@oguzkocer oguzkocer deleted the issues/7856-refresh-meta-data branch June 12, 2018 19:59
aforcier added a commit that referenced this pull request Oct 3, 2018
d6e2bf4184 Update login library default FluxC hash
7b3ba9e906 Merge commit 'e500cd63388ba77e7ea13df2fbb199c64e7107c2' into feature/import-latest-login-lib
0fe4cc1bf0 Merge commit '554b41f85535e113b1357e1c708fe304d50e0bd0' into develop
4495659338 Fix text of email not found error
ab65b7ea6e Fix text of sms throttled error
9f2e660eeb Checkstyle fix
61d3e7020e Refactoring
dd3989bbfa Refactoring
5cac71b526 Fix log msgs
42eb5f7300 Set image content description or mark it as not important for accessibility
bb0e745946 Fix checkstyle
0904ff17a5 Add a meaningful error message when the 2fa loggin is stopped because of sms throttling
606eb6fbe6 Trigger 2fa when the authentication SMS has been already sent during the flow
0f27a678d5 Fix google sign in flow
c98a1d473a Fix signup/in flows
30bf1accd1 Fix google sign-up
916621c9d7 Support setting the scheme in LoginMagicLinkRequestFragment
88e73ab293 Login integration
81fa3c9812 Add WP.com login as a step after Jetpack install
e3dd86f22b Localize the error message for invalid 2fa codes
08af882ab2 Merges release/10.2 into develop
7f9fca95f7 Update gradle plugin to 3.1.3
2520aa3844 Update google repository config and list it first
a88a7195ad Merge pull request #7880 from /issues/7856-refresh-meta-data
f2a12f0e4c fixed merge conflict
b218f90a2d Clean up from previous approach.
6ce03885e1 Remove errant space from login string
df7ae86a4d Update login library string to reflect core app string update
078c9c86f8 Remove unused strings from login library
51b07d7776 Tweak logic to allow a single method to bump acct created
17ede53ffc Overload method to have a shorter name.
33326b183b Refresh metadata for the google signup flow.
65c96baefa Call new method when bumping account created stat.
afedb2008a bumped google play services version to 15.0.1
853823cd9a Merge pull request #217 from woocommerce/feature/113-login-notification
848294dc29 Use more generic naming for the login notification channel id
fa437d344f Merge commit '09a0852581dd9a3a6b15109f3a8e9a80e644fbbb' into feature/update-login-library
6b07a925db Enable Google login
066beded26 Update gradle plugin to 3.1.2
3e1abf1cf0 Fix FluxC build error in login library
37707a744c Merge pull request #188 from woocommerce/feature/gradle-3.1.1
1a933195f0 Update gradle plugin and support libraries to latest
9af7502466 Update inner import checkstyle violations in login library
d07401c892 Update IDEA style config files
ad4fc3b429 Revert unintentional color change in the WordPressLoginFlow module.
c1b56716a1 Merge branch 'feature/order-details-screen' into feature/order-detail-views
6c93c92dc5 Exclude utils library from FluxC imports
372719093e Merge branch 'develop' into feature/order-detail-views
eec28986b5 Restore login notification styling changes
103dd8f6a1 Merge commit '6bd01d64a2d01176f5b26ae36836d4f5ff0fcdc9' into feature/update-login-lib
97462cca8e Merge branch 'develop' into feature/order-detail-views
20e9f3b9e3 Move login icon colors to variables
b15f6632fa Merge branch 'develop' into feature/114-login-style-refactor
26d1088134 Fix style violations in login library
17326beace Order Details - Customer Info View - Action Icons and listeners, updated icon assets * Add the ability to click to dial customer phone * Add the ability to click to email customer * Add the ability to click to sms customer
ebfa842faf Make login notification styling overridable
5494d0e742 Make login toolbar styling overridable
8cbdb5b313 Use overridable color names in login flow styles
e9137fe9f7 Replace WordPress buttons with LoginTheme
bf34dabb71 Expose play-services-auth dependency from login library
19203891d7 Merge commit '9751124a62caad5f7c9af772f8b872b604cd02b9' into feature/gradle-3.0
f5b58af6b4 Add WPCOM_LOGIN_ONLY LoginMode, disallowing self-hosted login

git-subtree-dir: libs/login
git-subtree-split: d6e2bf41845cba12bcfc24cde4e21aef032d89e4
aforcier added a commit that referenced this pull request Oct 18, 2018
4896a91c7c Merge pull request #6 from wordpress-mobile/merge-wca
16a871bcf1 Set base button color to white
d6e2bf4184 Update login library default FluxC hash
7b3ba9e906 Merge commit 'e500cd63388ba77e7ea13df2fbb199c64e7107c2' into feature/import-latest-login-lib
0fe4cc1bf0 Merge commit '554b41f85535e113b1357e1c708fe304d50e0bd0' into develop
4495659338 Fix text of email not found error
ab65b7ea6e Fix text of sms throttled error
9f2e660eeb Checkstyle fix
61d3e7020e Refactoring
dd3989bbfa Refactoring
5cac71b526 Fix log msgs
42eb5f7300 Set image content description or mark it as not important for accessibility
bb0e745946 Fix checkstyle
0904ff17a5 Add a meaningful error message when the 2fa loggin is stopped because of sms throttling
606eb6fbe6 Trigger 2fa when the authentication SMS has been already sent during the flow
0f27a678d5 Fix google sign in flow
c98a1d473a Fix signup/in flows
30bf1accd1 Fix google sign-up
916621c9d7 Support setting the scheme in LoginMagicLinkRequestFragment
88e73ab293 Login integration
81fa3c9812 Add WP.com login as a step after Jetpack install
e3dd86f22b Localize the error message for invalid 2fa codes
08af882ab2 Merges release/10.2 into develop
7f9fca95f7 Update gradle plugin to 3.1.3
2520aa3844 Update google repository config and list it first
a88a7195ad Merge pull request #7880 from /issues/7856-refresh-meta-data
f2a12f0e4c fixed merge conflict
b218f90a2d Clean up from previous approach.
6ce03885e1 Remove errant space from login string
df7ae86a4d Update login library string to reflect core app string update
078c9c86f8 Remove unused strings from login library
51b07d7776 Tweak logic to allow a single method to bump acct created
17ede53ffc Overload method to have a shorter name.
33326b183b Refresh metadata for the google signup flow.
65c96baefa Call new method when bumping account created stat.
afedb2008a bumped google play services version to 15.0.1
853823cd9a Merge pull request #217 from woocommerce/feature/113-login-notification
848294dc29 Use more generic naming for the login notification channel id
fa437d344f Merge commit '09a0852581dd9a3a6b15109f3a8e9a80e644fbbb' into feature/update-login-library
6b07a925db Enable Google login
066beded26 Update gradle plugin to 3.1.2
3e1abf1cf0 Fix FluxC build error in login library
37707a744c Merge pull request #188 from woocommerce/feature/gradle-3.1.1
1a933195f0 Update gradle plugin and support libraries to latest
9af7502466 Update inner import checkstyle violations in login library
d07401c892 Update IDEA style config files
ad4fc3b429 Revert unintentional color change in the WordPressLoginFlow module.
c1b56716a1 Merge branch 'feature/order-details-screen' into feature/order-detail-views
6c93c92dc5 Exclude utils library from FluxC imports
372719093e Merge branch 'develop' into feature/order-detail-views
eec28986b5 Restore login notification styling changes
103dd8f6a1 Merge commit '6bd01d64a2d01176f5b26ae36836d4f5ff0fcdc9' into feature/update-login-lib
97462cca8e Merge branch 'develop' into feature/order-detail-views
20e9f3b9e3 Move login icon colors to variables
b15f6632fa Merge branch 'develop' into feature/114-login-style-refactor
26d1088134 Fix style violations in login library
17326beace Order Details - Customer Info View - Action Icons and listeners, updated icon assets * Add the ability to click to dial customer phone * Add the ability to click to email customer * Add the ability to click to sms customer
ebfa842faf Make login notification styling overridable
5494d0e742 Make login toolbar styling overridable
8cbdb5b313 Use overridable color names in login flow styles
e9137fe9f7 Replace WordPress buttons with LoginTheme
bf34dabb71 Expose play-services-auth dependency from login library
19203891d7 Merge commit '9751124a62caad5f7c9af772f8b872b604cd02b9' into feature/gradle-3.0
f5b58af6b4 Add WPCOM_LOGIN_ONLY LoginMode, disallowing self-hosted login

git-subtree-dir: libs/login
git-subtree-split: 4896a91c7cb62100a663fd879915eff73f39a27e
wzieba pushed a commit that referenced this pull request Sep 27, 2024
wzieba pushed a commit that referenced this pull request Oct 21, 2024
wzieba pushed a commit that referenced this pull request Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants