mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Closes: https://github.com/fleetdm/confidential/issues/7528 Changes: - Added a new action: unsubscribe-from-marketing-emails, which updates a user record that uses a specified email address to exclude it from the deliver-nurture-emails script. - Updated the email template to include a link that users can click to unsubscribe. - Added a modal to the homepage that is shown to users who unsubscribe from marketing emails - Updated the email template data in deliver-nurture-emails and view-email-template-preview
138 lines
5 KiB
JavaScript
Vendored
138 lines
5 KiB
JavaScript
Vendored
module.exports = {
|
|
|
|
|
|
friendlyName: 'Deliver nurture emails',
|
|
|
|
|
|
description: 'Sends nurture emails to users who have been at psychological stage 3 & 4 for more than a day, and users who have been stage five for six weeks.',
|
|
|
|
|
|
fn: async function () {
|
|
|
|
sails.log('Running custom shell script... (`sails run deliver-nurture-emails`)');
|
|
|
|
let nowAt = Date.now();
|
|
let nurtureCampaignStartedAt = new Date('07-22-2024').getTime();
|
|
let oneHourAgoAt = nowAt - (1000 * 60 * 60);
|
|
let oneDayAgoAt = nowAt - (1000 * 60 * 60 * 24);
|
|
let sixWeeksAgoAt = nowAt - (1000 * 60 * 60 * 24 * 7 * 6);
|
|
// Find user records that are over an hour old that were created after July 22nd.
|
|
let usersWithMdmBuyingSituation = await User.find({
|
|
primaryBuyingSituation: 'mdm',
|
|
createdAt: {
|
|
'>=': nurtureCampaignStartedAt,
|
|
'<=': oneHourAgoAt,
|
|
},
|
|
});
|
|
|
|
// Only send emails to stage 3 users who have not received a nurture email for this stage, and that have been stage 3 for at least one day.
|
|
let stageThreeMdmFocusedUsersWhoHaveNotReceivedAnEmail = _.filter(usersWithMdmBuyingSituation, (user)=>{
|
|
return user.stageThreeNurtureEmailSentAt === 0
|
|
&& user.psychologicalStage === '3 - Intrigued';
|
|
});
|
|
|
|
// Only send emails to stage 4 users who have not received a a nurture email for this stage, and that have been stage 4 for at least one day.
|
|
let stageFourMdmFocusedUsersWhoHaveNotReceivedAnEmail = _.filter(usersWithMdmBuyingSituation, (user)=>{
|
|
return user.stageFourNurtureEmailSentAt === 0
|
|
&& user.psychologicalStage === '4 - Has use case';
|
|
});
|
|
|
|
// Only send emails to stage 5 users who have not received a nurture email for this stage, and that have been stage 5 for at least six weeks.
|
|
let stageFiveMdmFocusedUsersWhoHaveNotReceivedAnEmail = _.filter(usersWithMdmBuyingSituation, (user)=>{
|
|
return user.stageFiveNurtureEmailSentAt === 0
|
|
&& user.psychologicalStage === '5 - Personally confident';
|
|
});
|
|
|
|
let emailedStageThreeUserIds = [];
|
|
for(let user of stageThreeMdmFocusedUsersWhoHaveNotReceivedAnEmail) {
|
|
if(user.psychologicalStageLastChangedAt > oneDayAgoAt) {
|
|
continue;
|
|
} else {
|
|
await sails.helpers.sendTemplateEmail.with({
|
|
template: 'email-nurture-stage-three',
|
|
layout: 'layout-nurture-email',
|
|
templateData: {
|
|
firstName: user.firstName,
|
|
emailAddress: user.emailAddress
|
|
},
|
|
to: user.emailAddress,
|
|
toName: `${user.firstName} ${user.lastName}`,
|
|
subject: 'Was it any good?',
|
|
bcc: [sails.config.custom.activityCaptureEmailForNutureEmails],
|
|
from: sails.config.custom.contactEmailForNutureEmails,
|
|
fromName: sails.config.custom.contactNameForNurtureEmails,
|
|
ensureAck: true,
|
|
});
|
|
emailedStageThreeUserIds.push(user.id);
|
|
}
|
|
}
|
|
|
|
await User.update({id: {in: emailedStageThreeUserIds}})
|
|
.set({
|
|
stageThreeNurtureEmailSentAt: nowAt,
|
|
});
|
|
|
|
let emailedStageFourUserIds = [];
|
|
for(let user of stageFourMdmFocusedUsersWhoHaveNotReceivedAnEmail) {
|
|
if(user.psychologicalStageLastChangedAt > oneDayAgoAt) {
|
|
continue;
|
|
} else {
|
|
await sails.helpers.sendTemplateEmail.with({
|
|
template: 'email-nurture-stage-four',
|
|
layout: 'layout-nurture-email',
|
|
templateData: {
|
|
firstName: user.firstName,
|
|
emailAddress: user.emailAddress
|
|
},
|
|
to: user.emailAddress,
|
|
toName: `${user.firstName} ${user.lastName}`,
|
|
subject: 'Deploy open-source MDM',
|
|
bcc: [sails.config.custom.activityCaptureEmailForNutureEmails],
|
|
from: sails.config.custom.contactEmailForNutureEmails,
|
|
fromName: sails.config.custom.contactNameForNurtureEmails,
|
|
ensureAck: true,
|
|
});
|
|
emailedStageFourUserIds.push(user.id);
|
|
}
|
|
}
|
|
|
|
await User.update({id: {in: emailedStageFourUserIds}})
|
|
.set({
|
|
stageFourNurtureEmailSentAt: nowAt,
|
|
});
|
|
|
|
|
|
let emailedStageFiveUserIds = [];
|
|
for(let user of stageFiveMdmFocusedUsersWhoHaveNotReceivedAnEmail) {
|
|
if(user.psychologicalStageLastChangedAt > sixWeeksAgoAt) {
|
|
continue;
|
|
} else {
|
|
await sails.helpers.sendTemplateEmail.with({
|
|
template: 'email-nurture-stage-five',
|
|
layout: 'layout-nurture-email',
|
|
templateData: {
|
|
firstName: user.firstName,
|
|
emailAddress: user.emailAddress
|
|
},
|
|
to: user.emailAddress,
|
|
toName: `${user.firstName} ${user.lastName}`,
|
|
subject: 'Update',
|
|
bcc: [sails.config.custom.activityCaptureEmailForNutureEmails],
|
|
from: sails.config.custom.contactEmailForNutureEmails,
|
|
fromName: sails.config.custom.contactNameForNurtureEmails,
|
|
ensureAck: true,
|
|
});
|
|
emailedStageFiveUserIds.push(user.id);
|
|
}
|
|
}
|
|
|
|
await User.update({id: {in: emailedStageFiveUserIds}})
|
|
.set({
|
|
stageFiveNurtureEmailSentAt: nowAt,
|
|
});
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|