diff --git a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js
index aed0f922ae..c1e182012b 100644
--- a/services/web/app/src/Features/Subscription/RecurlyEventHandler.js
+++ b/services/web/app/src/Features/Subscription/RecurlyEventHandler.js
@@ -1,9 +1,11 @@
const AnalyticsManager = require('../Analytics/AnalyticsManager')
+const SplitTestV2Handler = require('../SplitTests/SplitTestV2Handler')
+const SubscriptionEmailHandler = require('./SubscriptionEmailHandler')
function sendRecurlyAnalyticsEvent(event, eventData) {
switch (event) {
case 'new_subscription_notification':
- _sendSubscriptionStartedEvent(eventData)
+ sendSubscriptionStartedEvent(eventData)
break
case 'updated_subscription_notification':
_sendSubscriptionUpdatedEvent(eventData)
@@ -39,7 +41,7 @@ function sendRecurlyAnalyticsEvent(event, eventData) {
}
}
-async function _sendSubscriptionStartedEvent(eventData) {
+async function sendSubscriptionStartedEvent(eventData) {
const userId = _getUserId(eventData)
const { planCode, quantity, state, isTrial } = _getSubscriptionData(eventData)
AnalyticsManager.recordEventForUser(userId, 'subscription-started', {
@@ -58,6 +60,18 @@ async function _sendSubscriptionStartedEvent(eventData) {
'subscription-is-trial',
isTrial
)
+
+ // send the trial onboarding email
+ if (isTrial) {
+ const assignment = await SplitTestV2Handler.promises.getAssignment(
+ userId,
+ 'trial-onboarding-email'
+ )
+
+ if (assignment.variant === 'send-email') {
+ SubscriptionEmailHandler.sendTrialOnboardingEmail(userId)
+ }
+ }
}
async function _sendSubscriptionUpdatedEvent(eventData) {
@@ -197,4 +211,5 @@ function _getSubscriptionData(eventData) {
module.exports = {
sendRecurlyAnalyticsEvent,
+ sendSubscriptionStartedEvent,
}
diff --git a/services/web/app/src/Features/Subscription/SubscriptionEmailBuilder.js b/services/web/app/src/Features/Subscription/SubscriptionEmailBuilder.js
new file mode 100644
index 0000000000..cc9d026e96
--- /dev/null
+++ b/services/web/app/src/Features/Subscription/SubscriptionEmailBuilder.js
@@ -0,0 +1,144 @@
+const EmailBuilder = require('../Email/EmailBuilder')
+const EmailMessageHelper = require('../Email/EmailMessageHelper')
+const settings = require('@overleaf/settings')
+
+EmailBuilder.templates.trialOnboarding = EmailBuilder.NoCTAEmailTemplate({
+ subject() {
+ return `Welcome to your ${settings.appName} Premium Features Trial`
+ },
+ title() {
+ return `Welcome to your Overleaf Premium Features Trial`
+ },
+ greeting() {
+ return 'Hello,'
+ },
+ message(opts, isPlainText) {
+ const invitingNamedCollaborators = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/Sharing_a_project?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=invitelink#Inviting_named_collaborators`,
+ isPlainText
+ )
+ const increasedCompileTimeout = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/What_is_the_maximum_compilation_time,_file_number_and_project_size_allowed_on_free_vs_paid_plans%3F?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=compilelink`,
+ isPlainText
+ )
+ const realTimeTrackChanges = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/Track_Changes_in_Overleaf?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=trackchangeslink`,
+ isPlainText
+ )
+ const history = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/latex/Using_the_History_feature?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=historylink`,
+ isPlainText
+ )
+ const versioning = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/Can_I_save_versions_of_my_work%3F?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=versioninglink`,
+ isPlainText
+ )
+ const advancedReferenceSearch = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/How_to_search_for_references_in_an_Overleaf_project?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=adrefsearchlink`,
+ isPlainText
+ )
+ const referenceManagerSync = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/How_to_link_your_Overleaf_account_to_Mendeley_and_Zotero?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=refmansynclink`,
+ isPlainText
+ )
+ const dropboxSync = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/Dropbox_Synchronization?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=dropboxlink`,
+ isPlainText
+ )
+ const gitSync = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/how-to/Using_Git_and_GitHub?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=gitgithublink`,
+ isPlainText
+ )
+ const latexTutorials = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/latex/Learn_LaTeX_in_30_minutes?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=latextutorialslink`,
+ isPlainText
+ )
+ const knowledgeBase = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=learnlink`,
+ isPlainText
+ )
+ const technicalArticles = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/learn/latex/Articles?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=articleslink`,
+ isPlainText
+ )
+ const webinars = EmailMessageHelper.displayLink(
+ 'Read More',
+ `${settings.siteUrl}/events/webinars?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=webinarslink`,
+ isPlainText
+ )
+
+ const cancel = EmailMessageHelper.displayLink(
+ 'cancel at any time',
+ `${settings.siteUrl}/learn/how-to/Canceling_Subscription?utm_source=Overleaf&utm_medium=email&utm_campaign=TrialEmail&utm_content=cancellink`,
+ isPlainText
+ )
+
+ const feedback = EmailMessageHelper.displayLink(
+ 'hear your feedback',
+ `https://docs.google.com/forms/d/e/1FAIpQLSfMbbh_z-9-dZ3YnrDCyNpNxFPGA492ZSallKOt8WWp2nx7kg/viewform?usp=sf_link/viewform`,
+ isPlainText
+ )
+
+ const unsubscribe = EmailMessageHelper.displayLink(
+ 'here',
+ `${settings.siteUrl}/user/settings`,
+ isPlainText
+ )
+
+ return [
+ `Welcome to your Overleaf Premium Features Trial! We really appreciate your support of Overleaf and are excited for you to use our premium features and get the most out of your trial.`,
+ `During your trial period, be sure to check out these premium features: `,
+
+ `1. Invite more collaborators: You can now invite named collaborators to your project via the ‘share’ menu in your project (with read-only or edit access). Simply add their email address and an email invitation will be sent to them. You can remove these named collaborators at any time via the same ‘share’ menu.`,
+ `
- Inviting Named Collaborators: ${invitingNamedCollaborators}
`,
+
+ `2. Increased compile timeout: You now have more time for compilation (to generate a PDF of your document) before receiving a timeout error message.`,
+ `- Compile Timeout: ${increasedCompileTimeout}
`,
+
+ `3. Real-time track changes: The track changes mode lets you see exactly what has been changed by your collaborators, and allows you to accept or reject each individual change. `,
+ `- Track Changes: ${realTimeTrackChanges}
`,
+
+ `4. Full document history and versioning: View the entire history of your project with the ability to revert to previous versions of your document from your project history (versus only 24 hours of history availability on a free Overleaf account). No more fear of losing work or making changes you can’t undo. `,
+ `- History: ${history}
+ - Versioning: ${versioning}
`,
+
+ `5. Advanced reference search: You can search by citation key, and our premium feature allows the added ability to search by author, title, year, or journal.`,
+ `- Advanced Reference Search: ${advancedReferenceSearch}
`,
+
+ `6. Reference manager sync : You can link your Mendeley and Zotero accounts to your Overleaf account, allowing you to import your reference library and keep your Overleaf document in sync with the references stored in Mendeley / Zotero.`,
+ `- Reference Manager Sync: ${referenceManagerSync}
`,
+
+ `7. Dropbox Sync: You can link your Dropbox account to your Overleaf account, allowing 2-way integration with Dropbox `,
+ `- Dropbox Sync: ${dropboxSync}
`,
+
+ `8. Git and GitHub integration: You can configure your Overleaf project to sync directly with a repository on GitHub, or you can use raw git access. This allows you to work offline and sync your files whenever you come back online. You can also use our Overleaf Git Bridge integration, which lets you git clone, push and pull changes between the online Overleaf editor, and your local offline git repository.`,
+ `- Git, GitHub and Git Bridge: ${gitSync}
`,
+
+ `9. Online tutorials and knowledge base: We have an extensive online knowledge base providing a wide range of platform guidance, LaTeX tutorials, technical articles, and webinars.`,
+ `- LaTeX tutorials: ${latexTutorials}
+ - Knowledge base: ${knowledgeBase}
+ - Technical articles: ${technicalArticles}
+ - Webinars: ${webinars}
`,
+
+ `Your trial will last for seven days from when you started it, and you can ${cancel} via your subscription page on your dashboard. If you’d like to continue your subscription after your trial, you’re all set!`,
+
+ `Please let us know if we can provide any additional support or answer any questions - and we’d love to ${feedback}!`,
+ `Thanks again for supporting Overleaf - Happy TeXing!`,
+ `The Overleaf Team
`,
+
+ `You're receiving this email because you've recently signed up for an Overleaf premium trial. If you've previously subscribed to emails about product offers and company news and events, you can unsubscribe ${unsubscribe}.`,
+ ]
+ },
+})
diff --git a/services/web/app/src/Features/Subscription/SubscriptionEmailHandler.js b/services/web/app/src/Features/Subscription/SubscriptionEmailHandler.js
new file mode 100644
index 0000000000..818a66cfb2
--- /dev/null
+++ b/services/web/app/src/Features/Subscription/SubscriptionEmailHandler.js
@@ -0,0 +1,19 @@
+const EmailHandler = require('../Email/EmailHandler')
+const UserGetter = require('../User/UserGetter')
+require('./SubscriptionEmailBuilder')
+
+const SubscriptionEmailHandler = {
+ async sendTrialOnboardingEmail(userId) {
+ const user = await UserGetter.promises.getUser(userId, {
+ email: 1,
+ })
+
+ const emailOptions = {
+ to: user.email,
+ sendingUser_id: userId,
+ }
+ await EmailHandler.promises.sendEmail('trialOnboarding', emailOptions)
+ },
+}
+
+module.exports = SubscriptionEmailHandler
diff --git a/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js b/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js
index b761289a5f..9c6d5e4cf4 100644
--- a/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js
+++ b/services/web/test/unit/src/Subscription/RecurlyEventHandlerTests.js
@@ -26,6 +26,14 @@ describe('RecurlyEventHandler', function () {
this.RecurlyEventHandler = SandboxedModule.require(modulePath, {
requires: {
+ './SubscriptionEmailHandler': (this.SubscriptionEmailHandler = {
+ sendTrialOnboardingEmail: sinon.stub(),
+ }),
+ '../SplitTests/SplitTestV2Handler': (this.SplitTestV2Handler = {
+ promises: {
+ getAssignment: sinon.stub().resolves({ active: false }),
+ },
+ }),
'../Analytics/AnalyticsManager': (this.AnalyticsManager = {
recordEventForUser: sinon.stub(),
setUserPropertyForUser: sinon.stub(),
@@ -67,6 +75,30 @@ describe('RecurlyEventHandler', function () {
'subscription-is-trial',
true
)
+ sinon.assert.calledWith(
+ this.SplitTestV2Handler.promises.getAssignment,
+ this.userId,
+ 'trial-onboarding-email'
+ )
+ })
+
+ it('sends free trial onboarding email if user in ab group', async function () {
+ this.SplitTestV2Handler.promises.getAssignment = sinon
+ .stub()
+ .resolves({ active: true, variant: 'send-email' })
+ this.userId = '123456789trial'
+ this.eventData.account.account_code = this.userId
+
+ // testing directly on the send subscription started event to ensure the split handler
+ // promise is resolved before checking calls
+ await this.RecurlyEventHandler.sendSubscriptionStartedEvent(this.eventData)
+
+ sinon.assert.calledWith(
+ this.SplitTestV2Handler.promises.getAssignment,
+ this.userId,
+ 'trial-onboarding-email'
+ )
+ sinon.assert.called(this.SubscriptionEmailHandler.sendTrialOnboardingEmail)
})
it('with new_subscription_notification - no free trial', function () {
diff --git a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js
index 4e0cc322e0..a0c1187b42 100644
--- a/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js
+++ b/services/web/test/unit/src/Subscription/SubscriptionControllerTests.js
@@ -150,6 +150,7 @@ describe('SubscriptionController', function () {
'./RecurlyWrapper': (this.RecurlyWrapper = {
updateAccountEmailAddress: sinon.stub().yields(),
}),
+ './RecurlyEventHandler': { sendRecurlyAnalyticsEvent: sinon.stub() },
'./FeaturesUpdater': (this.FeaturesUpdater = {}),
'./GroupPlansData': (this.GroupPlansData = {}),
'./V1SubscriptionManager': (this.V1SubscriptionManager = {}),
diff --git a/services/web/test/unit/src/Subscription/SubscriptionEmailHandlerTests.js b/services/web/test/unit/src/Subscription/SubscriptionEmailHandlerTests.js
new file mode 100644
index 0000000000..b16794a42b
--- /dev/null
+++ b/services/web/test/unit/src/Subscription/SubscriptionEmailHandlerTests.js
@@ -0,0 +1,40 @@
+const SandboxedModule = require('sandboxed-module')
+const sinon = require('sinon')
+const { expect } = require('chai')
+const modulePath =
+ '../../../../app/src/Features/Subscription/SubscriptionEmailHandler'
+
+describe('SubscriptionEmailHandler', function () {
+ beforeEach(function () {
+ this.userId = '123456789abcde'
+ this.email = 'test@test.com'
+
+ this.SubscriptionEmailHandler = SandboxedModule.require(modulePath, {
+ requires: {
+ '../Email/EmailHandler': (this.EmailHandler = {
+ promises: {
+ sendEmail: sinon.stub().resolves({}),
+ },
+ }),
+ '../User/UserGetter': (this.UserGetter = {
+ promises: {
+ getUser: sinon
+ .stub()
+ .resolves({ _id: this.userId, email: 'test@test.com' }),
+ },
+ }),
+ },
+ })
+ })
+
+ it('sends trail onboarding email', async function () {
+ await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(this.userId)
+ expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
+ 'trialOnboarding',
+ {
+ to: this.email,
+ sendingUser_id: this.userId,
+ },
+ ])
+ })
+})