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

Best practice for dealing with email address confirmation? #279

Open
marckohlbrugge opened this issue Oct 31, 2024 · 3 comments
Open

Best practice for dealing with email address confirmation? #279

marckohlbrugge opened this issue Oct 31, 2024 · 3 comments

Comments

@marckohlbrugge
Copy link

The example code shows this:

after_create_commit do
  OnboardingCampaign.add(self)
end

Which conveniently omits the fact that we'll want to hold off sending emails until the user has confirmed their email address.

The intuitive solution is to add a segment check to the campaign like below, but I believe this won't work as expected. The campaign will be triggered, the user does not fit the segment yet, and thus the campaign will never be sent. Even after email confirmation.

class OnboardingCampaign < ApplicationCampaign
  segment :confirmed?
end

The proper solution then seems to be to hold off on adding the user to the campaign, until the user has confirmed their email address. We could add OnboardingCampaign.add(user) in a ConfirmationsController.

This seems like a pragmatic solution, but it doesn't work well if you also use OAuth logins where email confirmations can be skipped. Which means we'll need to add another OnboardingCampaign.add(user) somewhere in the OAuth signup process.

So my question is this: what's the best practice for holding off on sending campaigns until the user has confirmed their email address?

@joshuap
Copy link
Member

joshuap commented Nov 5, 2024

@marckohlbrugge what you suggested—waiting until they confirm their email to add them—is the right way, but I've also experienced some friction with having multiple onboarding paths. I don't have a great answer, except that you could add them to the campaign using an after_save callback in the User model with an if: ->(u) { u.confirmed? } condition, so it adds them regardless of where the email was confirmed (assuming the OAuth process auto-confirms the email). Or, you could have some kind of service object or decorator that you call from both places that does all of the post-confirm onboarding stuff.

@joshuap
Copy link
Member

joshuap commented Nov 6, 2024

I have thought about other ways of doing this potentially, like instrumenting the app for events and then having a way to subscribe to those events. You could technically do that with ActiveSupport::Notifications (we use that a bit), but I don't think it's simpler. Some kind of event-driven workflow API in the future could be interesting for driving more complex campaigns/workflows though.

@marckohlbrugge
Copy link
Author

marckohlbrugge commented Nov 6, 2024

Yeah I actually use ActiveSupport::Notifications a lot for that type of stuff. But it's not idempotent, because there's no persistency. (Which could lead to duplicate events, etc)

I also have a Event model to track important user events. I might elaborate on that, add a "user_is_confirmed" event, and have the campaign "subscribe" to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants