Only show track changes onboarding once based on analytics API events

This commit is contained in:
James Allen 2017-02-14 09:34:30 +01:00
parent c8baae84da
commit 03ecf4b4ae
5 changed files with 45 additions and 6 deletions

View file

@ -20,6 +20,7 @@ ProjectGetter = require("./ProjectGetter")
PrivilegeLevels = require("../Authorization/PrivilegeLevels") PrivilegeLevels = require("../Authorization/PrivilegeLevels")
AuthenticationController = require("../Authentication/AuthenticationController") AuthenticationController = require("../Authentication/AuthenticationController")
PackageVersions = require("../../infrastructure/PackageVersions") PackageVersions = require("../../infrastructure/PackageVersions")
AnalyticsManager = require "../Analytics/AnalyticsManager"
module.exports = ProjectController = module.exports = ProjectController =
@ -219,6 +220,19 @@ module.exports = ProjectController =
#don't need to wait for this to complete #don't need to wait for this to complete
ProjectUpdateHandler.markAsOpened project_id, -> ProjectUpdateHandler.markAsOpened project_id, ->
cb() cb()
showTrackChangesOnboarding: (cb) ->
cb = _.once(cb)
if !user_id?
return cb()
timeout = setTimeout cb, 500
AnalyticsManager.getLastOccurance user_id, "shown-track-changes-onboarding", (error, event) ->
clearTimeout timeout
if error?
return cb(null, false)
else if event?
return cb(null, false)
else
return cb(null, true)
}, (err, results)-> }, (err, results)->
if err? if err?
logger.err err:err, "error getting details for project page" logger.err err:err, "error getting details for project page"
@ -226,7 +240,7 @@ module.exports = ProjectController =
project = results.project project = results.project
user = results.user user = results.user
subscription = results.subscription subscription = results.subscription
showTrackChangesOnboarding = results.showTrackChangesOnboarding
daysSinceLastUpdated = (new Date() - project.lastUpdated) /86400000 daysSinceLastUpdated = (new Date() - project.lastUpdated) /86400000
logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor" logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor"
@ -268,6 +282,7 @@ module.exports = ProjectController =
syntaxValidation: user.ace.syntaxValidation syntaxValidation: user.ace.syntaxValidation
} }
trackChangesEnabled: !!project.track_changes trackChangesEnabled: !!project.track_changes
showTrackChangesOnboarding: !!showTrackChangesOnboarding
privilegeLevel: privilegeLevel privilegeLevel: privilegeLevel
chatUrl: Settings.apis.chat.url chatUrl: Settings.apis.chat.url
anonymous: anonymous anonymous: anonymous

View file

@ -108,6 +108,7 @@ block requirejs
window.anonymous = #{anonymous}; window.anonymous = #{anonymous};
window.maxDocLength = #{maxDocLength}; window.maxDocLength = #{maxDocLength};
window.trackChangesEnabled = #{trackChangesEnabled}; window.trackChangesEnabled = #{trackChangesEnabled};
window.showTrackChangesOnboarding = #{showTrackChangesOnboarding};
window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)};
window.requirejs = { window.requirejs = {
"paths" : { "paths" : {

View file

@ -70,7 +70,7 @@ define [
chatOpen: false chatOpen: false
pdfLayout: 'sideBySide' pdfLayout: 'sideBySide'
reviewPanelOpen: localStorage("ui.reviewPanelOpen.#{window.project_id}") reviewPanelOpen: localStorage("ui.reviewPanelOpen.#{window.project_id}")
showCollabFeaturesOnboarding: true #!window.userSettings.syntaxValidation? showCollabFeaturesOnboarding: window.showTrackChangesOnboarding
} }
$scope.user = window.user $scope.user = window.user

View file

@ -1,14 +1,13 @@
define [ define [
"base" "base"
], (App) -> ], (App) ->
App.controller "FeatureOnboardingController", ($scope, settings) -> App.controller "FeatureOnboardingController", ($scope, settings, event_tracking) ->
# TODO Send event to Analytics API; handle keyboard input.
$scope.onboarding = $scope.onboarding =
innerStep: 1 innerStep: 1
nSteps: 4 nSteps: 4
$scope.dismiss = () -> $scope.dismiss = () ->
event_tracking.sendMB "shown-track-changes-onboarding"
$scope.ui.showCollabFeaturesOnboarding = false $scope.ui.showCollabFeaturesOnboarding = false
$scope.gotoPrevStep = () -> $scope.gotoPrevStep = () ->

View file

@ -58,6 +58,8 @@ describe "ProjectController", ->
getLoggedInUserId: sinon.stub().returns(@user._id) getLoggedInUserId: sinon.stub().returns(@user._id)
getSessionUser: sinon.stub().returns(@user) getSessionUser: sinon.stub().returns(@user)
isUserLoggedIn: sinon.stub().returns(true) isUserLoggedIn: sinon.stub().returns(true)
@AnalyticsManager =
getLastOccurance: sinon.stub()
@ProjectController = SandboxedModule.require modulePath, requires: @ProjectController = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings "settings-sharelatex":@settings
"logger-sharelatex": "logger-sharelatex":
@ -82,6 +84,7 @@ describe "ProjectController", ->
"../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler "../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler
"./ProjectGetter": @ProjectGetter "./ProjectGetter": @ProjectGetter
'../Authentication/AuthenticationController': @AuthenticationController '../Authentication/AuthenticationController': @AuthenticationController
"../Analytics/AnalyticsManager": @AnalyticsManager
@projectName = "£12321jkj9ujkljds" @projectName = "£12321jkj9ujkljds"
@req = @req =
@ -310,9 +313,9 @@ describe "ProjectController", ->
@AuthorizationManager.getPrivilegeLevelForProject.callsArgWith 2, null, "owner" @AuthorizationManager.getPrivilegeLevelForProject.callsArgWith 2, null, "owner"
@ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub() @ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub()
@InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1) @InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1)
@AnalyticsManager.getLastOccurance.yields(null, {"mock": "event"})
@ProjectUpdateHandler.markAsOpened.callsArgWith(1) @ProjectUpdateHandler.markAsOpened.callsArgWith(1)
it "should render the project/editor page", (done)-> it "should render the project/editor page", (done)->
@res.render = (pageName, opts)=> @res.render = (pageName, opts)=>
pageName.should.equal "project/editor" pageName.should.equal "project/editor"
@ -357,3 +360,24 @@ describe "ProjectController", ->
@ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true @ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true
done() done()
@ProjectController.loadEditor @req, @res @ProjectController.loadEditor @req, @res
it "should set showTrackChangesOnboarding = false if there is an event", (done) ->
@AnalyticsManager.getLastOccurance.yields(null, {"mock": "event"})
@res.render = (pageName, opts)=>
opts.showTrackChangesOnboarding.should.equal false
done()
@ProjectController.loadEditor @req, @res
it "should set showTrackChangesOnboarding = true if there is no event", (done) ->
@AnalyticsManager.getLastOccurance.yields(null, null)
@res.render = (pageName, opts)=>
opts.showTrackChangesOnboarding.should.equal true
done()
@ProjectController.loadEditor @req, @res
it "should set showTrackChangesOnboarding = false if there is an error", (done) ->
@AnalyticsManager.getLastOccurance.yields(new Error("oops"), null)
@res.render = (pageName, opts)=>
opts.showTrackChangesOnboarding.should.equal false
done()
@ProjectController.loadEditor @req, @res