Sending a couple more offers in the next-steps emails.

This commit is contained in:
Nick Winter 2015-03-09 16:32:29 -07:00
parent 031337e472
commit dc5fb0af14
3 changed files with 28 additions and 5 deletions

View file

@ -21,11 +21,15 @@ if docs.length === 1
li
strong
a(class="resource-link", data-resource="code-school", href='http://mbsy.co/bVRsR') Code School
| : Learn web technologies with video lessons, coding challenges, and screencasts. Get your first month for only $9 ($20 off).
| : Learn web technologies with video lessons, coding challenges, and screencasts.
li
strong
a(class="resource-link", data-resource="treehouse", href='http://teamtreehouse.com/') Treehouse
| : Learn HTML, CSS, iPhone apps, and more with a comprehensive video library.
a(class="resource-link", data-resource="learnable", href='http://shrsl.com/?~80my') Learnable
| : Learn web design, HTML, CSS, and so much more.
li
strong
a(class="resource-link", data-resource="pluralsight", href='http://shrsl.com/?~81i5') Pluralsight
| : Unlock new tech skills with over 3000 online courses.
else
ul.nav.nav-tabs
for doc in docs

View file

@ -15,7 +15,7 @@ block modal-body-content
.answers-container-wrapper
.answers-container
table.table.table-hover
for answer in poll.get("answers")
for answer in poll.get("answers") || []
tr(class="answer", data-answer=answer.key)
td!= marked(i18n(answer, "text"))
td.graph-cell

View file

@ -675,7 +675,7 @@ handleNextSteps = (req, res) ->
startTime = getTimeFromDaysAgo now, daysAgo
endTime = startTime + 5 * 60 * 1000
findParameters = {dateCreated: {$gt: new Date(startTime), $lte: new Date(endTime)}, emailLower: {$exists: true}}
selectString = 'name firstName lastName lastLevel points email gender emailSubscriptions emails dateCreated preferredLanguage aceConfig.language activity stats earned testGroupNumber'
selectString = 'name firstName lastName lastLevel points email gender emailSubscriptions emails dateCreated preferredLanguage aceConfig.language activity stats earned testGroupNumber ageRange'
query = User.find(findParameters).select(selectString)
do (daysAgo) ->
query.exec (err, results) ->
@ -710,6 +710,24 @@ sendNextStepsEmail = (user, now, daysAgo) ->
when 0, 1, 2, 3 then name: 'Forgetful Gemsmith', slug: 'forgetful-gemsmith'
when 4, 5, 6, 7 then name: 'Signs and Portents', slug: 'signs-and-portents'
# TODO: make this smarter, actually data-driven, looking at all available sessions
shadowGuardSession = _.find sessions, levelID: 'shadow-guard'
isFast = shadowGuardSession and shadowGuardSession.playtime < 90 # Average is 107s
isVeryFast = shadowGuardSession and shadowGuardSession.playtime < 75
isAdult = user.get('ageRange') in ['18-24', '25-34', '35-44', '45-100']
isKid = not isAdult # Assume kid if not specified
offers =
'app-academy': isAdult and isVeryFast
'designlab': isAdult
'tealeaf-academy': isAdult and isFast
'talent-buddy': isAdult
'coding-campus': isAdult and Math.random() < 0.5 # TODO: geodetect UT and give priority
#'mv-code-club': isKid # TODO: geodetect, get landing page URL
nAdditionalOffers = 4 - _.filter(offers).length
possibleAdditionalOffers = ['code-school', 'one-month', 'learnable', 'pluralsight']
for offer in _.sample possibleAdditionalOffers, nAdditionalOffers
offers[offer] = true
# TODO: do something with the preferredLanguage?
context =
email_id: sendwithus.templates.next_steps_email
@ -724,6 +742,7 @@ sendNextStepsEmail = (user, now, daysAgo) ->
secretLevelName: secretLevel.name
secretLevelLink: "http://codecombat.com/play/level/#{secretLevel.slug}"
levelsComplete: complete.length
offers: offers
log.info "Sending next steps email to #{context.recipient.address} with #{context.email_data.nextLevelName} next and #{context.email_data.levelsComplete} levels complete since #{daysAgo} day(s) ago." if DEBUGGING
sendwithus.api.send context, (err, result) ->
log.error "Error sending next steps email: #{err} with result #{result}" if err