fix PLG email timing

do not send emails if the date has passed
This commit is contained in:
Nuwan 2025-09-22 00:07:16 +05:30
parent 4ffc0d9b3b
commit 675bf2b69c
7 changed files with 22 additions and 22 deletions

View File

@ -436,7 +436,7 @@ module JamRuby
sendgrid_substitute('@USERID', [user.id])
sendgrid_unique_args :type => "profile_complete_reminder2"
mail(:to => user.email, :subject => "Take 2 minutes to fill out your JamKazam profile now") do |format|
mail(:to => user.email, :subject => I18n.t('user_mailer.profile_complete_reminder2.subject')) do |format|
format.text
format.html { render layout: "user_mailer_beta" }
end
@ -448,7 +448,7 @@ module JamRuby
sendgrid_substitute('@USERID', [user.id])
sendgrid_unique_args :type => "profile_complete_reminder3"
mail(:to => user.email, :subject => "Last reminder to update your JamKazam profile") do |format|
mail(:to => user.email, :subject => I18n.t('user_mailer.profile_complete_reminder3.subject')) do |format|
format.text
format.html { render layout: "user_mailer_beta" }
end

View File

@ -32,15 +32,15 @@ module JamRuby
end
def self.reminder1_users
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder1_sent_at IS NULL", 1.day.ago)
EmailProfileReminder.prospect_users.where("users.created_at::date = ? AND users.profile_complete_reminder1_sent_at IS NULL", 1.day.ago.to_date)
end
def self.reminder2_users
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder1_sent_at IS NOT NULL AND users.profile_complete_reminder2_sent_at IS NULL", 3.days.ago)
EmailProfileReminder.prospect_users.where("users.created_at::date = ? AND users.profile_complete_reminder1_sent_at IS NOT NULL AND users.profile_complete_reminder2_sent_at IS NULL", 3.days.ago.to_date)
end
def self.reminder3_users
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder2_sent_at IS NOT NULL AND users.profile_complete_reminder3_sent_at IS NULL", 5.days.ago)
EmailProfileReminder.prospect_users.where("users.created_at::date = ? AND users.profile_complete_reminder2_sent_at IS NOT NULL AND users.profile_complete_reminder3_sent_at IS NULL", 5.days.ago.to_date)
end

View File

@ -28,19 +28,19 @@ module JamRuby
end
def self.prospect_users
User.where("users.first_certified_gear_at IS NULL")
User.where("users.first_certified_gear_at IS NULL AND users.subscribe_email = ?", true)
end
def self.reminder1_users(cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NULL", 1.day.ago, cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at::date = ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NULL", 1.day.ago.to_date, cutoff_date)
end
def self.reminder2_users(cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NOT NULL AND users.gear_setup_reminder2_sent_at IS NULL", 3.days.ago, cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at::date = ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NOT NULL AND users.gear_setup_reminder2_sent_at IS NULL", 3.days.ago.to_date, cutoff_date)
end
def self.reminder3_users(cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder2_sent_at IS NOT NULL AND users.gear_setup_reminder3_sent_at IS NULL", 5.days.ago, cutoff_date)
GearSetupReminder.prospect_users.where("users.created_at::date = ? AND users.created_at > ? AND users.gear_setup_reminder2_sent_at IS NOT NULL AND users.gear_setup_reminder3_sent_at IS NULL", 5.days.ago.to_date, cutoff_date)
end
end

View File

@ -36,11 +36,11 @@ module JamRuby
end
def self.reminder2_users(cutoff_date)
GroupSessionReminder.prospect_users.where("users.created_at > ? AND users.group_session_reminder1_sent_at IS NOT NULL AND users.group_session_reminder2_sent_at IS NULL AND users.first_music_session_at < ?", cutoff_date, 3.days.ago)
GroupSessionReminder.prospect_users.where("users.created_at > ? AND users.group_session_reminder1_sent_at IS NOT NULL AND users.group_session_reminder2_sent_at IS NULL AND users.first_music_session_at::date = ?", cutoff_date, 3.days.ago.to_date)
end
def self.reminder3_users(cutoff_date)
GroupSessionReminder.prospect_users.where("users.created_at > ? AND users.group_session_reminder2_sent_at IS NOT NULL AND users.group_session_reminder3_sent_at IS NULL AND users.first_music_session_at < ?", cutoff_date, 5.days.ago)
GroupSessionReminder.prospect_users.where("users.created_at > ? AND users.group_session_reminder2_sent_at IS NOT NULL AND users.group_session_reminder3_sent_at IS NULL AND users.first_music_session_at::date = ?", cutoff_date, 5.days.ago.to_date)
end
end

View File

@ -31,15 +31,15 @@ module JamRuby
end
def self.reminder1_users(cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at < ? AND users.created_at >= ? AND users.test_gear_reminder1_sent_at IS NULL", 1.day.ago, cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at::date = ? AND users.created_at >= ? AND users.test_gear_reminder1_sent_at IS NULL", 1.day.ago.to_date, cutoff_date)
end
def self.reminder2_users(cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at < ? AND users.created_at >= ? AND users.test_gear_reminder1_sent_at IS NOT NULL AND users.test_gear_reminder2_sent_at IS NULL", 3.days.ago, cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at::date = ? AND users.created_at >= ? AND users.test_gear_reminder1_sent_at IS NOT NULL AND users.test_gear_reminder2_sent_at IS NULL", 3.days.ago.to_date, cutoff_date)
end
def self.reminder3_users(cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at < ? AND users.created_at > ? AND users.test_gear_reminder2_sent_at IS NOT NULL AND users.test_gear_reminder3_sent_at IS NULL", 5.days.ago, cutoff_date)
TestGearReminder.prospect_users.where("users.first_certified_gear_at::date = ? AND users.created_at > ? AND users.test_gear_reminder2_sent_at IS NOT NULL AND users.test_gear_reminder3_sent_at IS NULL", 5.days.ago.to_date, cutoff_date)
end
end
end

View File

@ -8,24 +8,24 @@ module JamRuby
class TrialExpiresReminder
@@log = Logging.logger[TrialExpiresReminder]
FIRST_NOTIFICATION_CHECK = 1.day.ago.to_s
SECOND_NOTIFICATION_CHECK = 5.days.ago.to_s
THIRD_NOTIFICATION_CHECK = 9.days.ago
FIRST_NOTIFICATION_CHECK = 1.day.ago.to_date
SECOND_NOTIFICATION_CHECK = 5.days.ago.to_date
THIRD_NOTIFICATION_CHECK = 9.days.ago.to_date
def self.prospect_users(cutoff_date)
User.where("(users.subscription_trial_ends_at IS NOT NULL AND users.subscription_trial_ends_at > ?)", cutoff_date)
end
def self.reminder1_users(cutoff_date)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at < ? AND users.trial_expires_reminder1_sent_at IS NULL", 1.day.ago, FIRST_NOTIFICATION_CHECK)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at::date = ? AND users.trial_expires_reminder1_sent_at IS NULL", 1.day.ago, FIRST_NOTIFICATION_CHECK)
end
def self.reminder2_users(cutoff_date)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at < ? AND trial_expires_reminder1_sent_at IS NOT NULL AND users.trial_expires_reminder2_sent_at IS NULL", 1.day.ago, SECOND_NOTIFICATION_CHECK)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at::date = ? AND trial_expires_reminder1_sent_at IS NOT NULL AND users.trial_expires_reminder2_sent_at IS NULL", 1.day.ago, SECOND_NOTIFICATION_CHECK)
end
def self.reminder3_users(cutoff_date)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at < ? AND trial_expires_reminder2_sent_at IS NOT NULL AND users.trial_expires_reminder3_sent_at IS NULL", 1.day.ago, THIRD_NOTIFICATION_CHECK)
prospect_users(cutoff_date).where("users.subscription_last_checked_at < ? AND users.subscription_trial_ends_at::date = ? AND trial_expires_reminder2_sent_at IS NOT NULL AND users.trial_expires_reminder3_sent_at IS NULL", 1.day.ago, THIRD_NOTIFICATION_CHECK)
end
def self.send_reminders

View File

@ -84,7 +84,7 @@ en:
regards: "Best Regards,"
signature: "JamKazam Team"
profile_complete_reminder2:
subject: "Complete your JamKazam profile"
subject: "Take 2 minutes to fill out your JamKazam profile now"
greeting: "Hello"
paragraph1: "We share your profile with JamKazam members who may be a good fit to play music with you during your first week on the platform via an automated email feature. Dont miss this opportunity to connect. Click the button below to update your profile now, before its shared with others!"
update_profile: "Update Profile"
@ -92,7 +92,7 @@ en:
regards: "Best Regards,"
signature: "JamKazam Team"
profile_complete_reminder3:
subject: "Complete your JamKazam profile"
subject: "Last reminder to update your JamKazam profile"
greeting: "Hello"
paragraph1: "Your profile is your key to connecting with other musicians on JamKazam. It lets others know what instruments you play at what level of proficiency and what kinds of music you like to play. This lets our existing community find and reach out to you to connect and play, and this information also powers our automated matchmaking features that make recommendations to you. If you think you might want to play music live online on JamKazam, please click the button below now to fill out your profile!"
update_profile: "Update Profile"