From 2d18bcf9f021ce67339a11fb712cf274b3ca6842 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Tue, 3 Mar 2015 09:04:53 -0800 Subject: [PATCH] Recording referrer information. Updating parent email prompt to also show after Signs and Portents if that's the fourth level. --- app/core/Tracker.coffee | 13 ++++++++++++- app/core/utils.coffee | 7 +++++++ app/locale/en.coffee | 8 ++++---- app/schemas/models/user.coffee | 3 +++ app/views/core/CocoView.coffee | 7 +------ app/views/play/CampaignView.coffee | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/core/Tracker.coffee b/app/core/Tracker.coffee index e2379e9fd..3eafed272 100644 --- a/app/core/Tracker.coffee +++ b/app/core/Tracker.coffee @@ -1,5 +1,6 @@ {me} = require 'core/auth' SuperModel = require 'models/SuperModel' +utils = require 'core/utils' debugAnalytics = false @@ -9,9 +10,19 @@ module.exports = class Tracker console.error 'Overwrote our Tracker!', window.tracker window.tracker = @ @isProduction = document.location.href.search('codecombat.com') isnt -1 + @trackReferrers() @identify() @supermodel = new SuperModel() + trackReferrers: -> + elapsed = new Date() - new Date(me.get('dateCreated')) + return unless elapsed < 5 * 60 * 1000 + return if me.get('siteref') or me.get('referrer') + if siteref = utils.getQueryVariable '_r' + me.set 'siteref', siteref + if referrer = document.referrer + me.set 'referrer', referrer + identify: (traits={}) -> return unless me @@ -19,7 +30,7 @@ module.exports = class Tracker @explicitTraits ?= {} @explicitTraits[key] = value for key, value of traits - for userTrait in ['email', 'anonymous', 'dateCreated', 'name', 'wizardColor1', 'testGroupNumber', 'gender', 'lastLevel'] + for userTrait in ['email', 'anonymous', 'dateCreated', 'name', 'testGroupNumber', 'gender', 'lastLevel', 'siteref'] traits[userTrait] ?= me.get(userTrait) console.log 'Would identify', traits if debugAnalytics return unless @isProduction and not me.isAdmin() diff --git a/app/core/utils.coffee b/app/core/utils.coffee index 572b3a3da..cd6d079df 100644 --- a/app/core/utils.coffee +++ b/app/core/utils.coffee @@ -177,3 +177,10 @@ if document?.createElement wrap.appendChild temp.children[1] return )(document) + +module.exports.getQueryVariable = getQueryVariable = (param, defaultValue) -> + query = document.location.search.substring 1 + pairs = (pair.split('=') for pair in query.split '&') + for pair in pairs when pair[0] is param + return {'true': true, 'false': false}[pair[1]] ? decodeURIComponent(pair[1]) + defaultValue diff --git a/app/locale/en.coffee b/app/locale/en.coffee index feef4fc14..1a41b3052 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -530,11 +530,11 @@ press_paragraph_1_link: "press packet" press_paragraph_1_suffix: ". All logos and images may be used without contacting us directly." team: "Team" - george_title: "Cofounder" + george_title: "Cofounder" # {change} george_blurb: "Businesser" - scott_title: "Cofounder" + scott_title: "Cofounder" # {change} scott_blurb: "Reasonable One" - nick_title: "Cofounder" + nick_title: "Cofounder" # {change} nick_blurb: "Motivation Guru" michael_title: "Programmer" michael_blurb: "Sys Admin" @@ -564,7 +564,7 @@ age_recommended_title: "What age is it recommended at?" age_recommended_1: "The recommended minimum age is 9, however children as young as 7 can play the first stages with the assistance of an adult." what_cover_title: "What do we cover?" - what_cover_1: "There are 27 levels in the first stage of CodeCombat that teach and reinforce 6 specific computer science concepts:" + what_cover_1: "There are 27 levels in the first stage of CodeCombat that teach and reinforce 6 specific computer science concepts:" # {change} what_cover_notation_1: "Formal notation" what_cover_notation_2: "- builds an understanding of the importance of syntax in programming." what_cover_methods_1: "Calling methods" diff --git a/app/schemas/models/user.coffee b/app/schemas/models/user.coffee index f1c745f2c..9d21db3f7 100644 --- a/app/schemas/models/user.coffee +++ b/app/schemas/models/user.coffee @@ -290,6 +290,9 @@ _.extend UserSchema.properties, free: { type: ['boolean', 'string'], format: 'date-time' } } + siteref: { type: 'string' } + referrer: { type: 'string' } + c.extendBasicProperties UserSchema, 'user' UserSchema.definitions = diff --git a/app/views/core/CocoView.coffee b/app/views/core/CocoView.coffee index cdec6e786..d580ae0f7 100644 --- a/app/views/core/CocoView.coffee +++ b/app/views/core/CocoView.coffee @@ -397,12 +397,7 @@ module.exports = class CocoView extends Backbone.View # Utilities getQueryVariable: (param, defaultValue) -> CocoView.getQueryVariable(param, defaultValue) - @getQueryVariable: (param, defaultValue) -> - query = document.location.search.substring 1 - pairs = (pair.split('=') for pair in query.split '&') - for pair in pairs when pair[0] is param - return {'true': true, 'false': false}[pair[1]] ? decodeURIComponent(pair[1]) - defaultValue + @getQueryVariable: (param, defaultValue) -> utils.getQueryVariable(param, defaultValue) # Moved to utils; TODO finish migrating getRootView: -> view = @ diff --git a/app/views/play/CampaignView.coffee b/app/views/play/CampaignView.coffee index b1c3344e2..c4229ff1b 100644 --- a/app/views/play/CampaignView.coffee +++ b/app/views/play/CampaignView.coffee @@ -143,7 +143,7 @@ module.exports = class CampaignView extends RootView @render() @preloadTopHeroes() unless me.get('heroConfig')?.thangType @$el.find('#campaign-status').delay(4000).animate({top: "-=58"}, 1000) unless @terrain is 'dungeon' - if @terrain and me.get('name') and me.get('lastLevel') is 'forgetful-gemsmith' + if @terrain and me.get('name') and me.get('lastLevel') in ['forgetful-gemsmith', 'signs-and-portents'] @openModalView new ShareProgressModal()