From 03ecf4b4aed38433768d22e5ed7bf4b70aaefe2e Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 14 Feb 2017 09:34:30 +0100 Subject: [PATCH] Only show track changes onboarding once based on analytics API events --- .../Features/Project/ProjectController.coffee | 17 +++++++++++- services/web/app/views/project/editor.pug | 1 + services/web/public/coffee/ide.coffee | 2 +- .../ide/FeatureOnboardingController.coffee | 5 ++-- .../Project/ProjectControllerTests.coffee | 26 ++++++++++++++++++- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 3e6beaa0fb..f54faa606f 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -20,6 +20,7 @@ ProjectGetter = require("./ProjectGetter") PrivilegeLevels = require("../Authorization/PrivilegeLevels") AuthenticationController = require("../Authentication/AuthenticationController") PackageVersions = require("../../infrastructure/PackageVersions") +AnalyticsManager = require "../Analytics/AnalyticsManager" module.exports = ProjectController = @@ -219,6 +220,19 @@ module.exports = ProjectController = #don't need to wait for this to complete ProjectUpdateHandler.markAsOpened project_id, -> 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)-> if err? logger.err err:err, "error getting details for project page" @@ -226,7 +240,7 @@ module.exports = ProjectController = project = results.project user = results.user subscription = results.subscription - + showTrackChangesOnboarding = results.showTrackChangesOnboarding daysSinceLastUpdated = (new Date() - project.lastUpdated) /86400000 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 } trackChangesEnabled: !!project.track_changes + showTrackChangesOnboarding: !!showTrackChangesOnboarding privilegeLevel: privilegeLevel chatUrl: Settings.apis.chat.url anonymous: anonymous diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index 54c742fd15..dd32a081fe 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -108,6 +108,7 @@ block requirejs window.anonymous = #{anonymous}; window.maxDocLength = #{maxDocLength}; window.trackChangesEnabled = #{trackChangesEnabled}; + window.showTrackChangesOnboarding = #{showTrackChangesOnboarding}; window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.requirejs = { "paths" : { diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 0314e9ffd3..83863b45be 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -70,7 +70,7 @@ define [ chatOpen: false pdfLayout: 'sideBySide' reviewPanelOpen: localStorage("ui.reviewPanelOpen.#{window.project_id}") - showCollabFeaturesOnboarding: true #!window.userSettings.syntaxValidation? + showCollabFeaturesOnboarding: window.showTrackChangesOnboarding } $scope.user = window.user diff --git a/services/web/public/coffee/ide/FeatureOnboardingController.coffee b/services/web/public/coffee/ide/FeatureOnboardingController.coffee index 67f434abaf..69122f3388 100644 --- a/services/web/public/coffee/ide/FeatureOnboardingController.coffee +++ b/services/web/public/coffee/ide/FeatureOnboardingController.coffee @@ -1,14 +1,13 @@ define [ "base" ], (App) -> - App.controller "FeatureOnboardingController", ($scope, settings) -> - # TODO Send event to Analytics API; handle keyboard input. - + App.controller "FeatureOnboardingController", ($scope, settings, event_tracking) -> $scope.onboarding = innerStep: 1 nSteps: 4 $scope.dismiss = () -> + event_tracking.sendMB "shown-track-changes-onboarding" $scope.ui.showCollabFeaturesOnboarding = false $scope.gotoPrevStep = () -> diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index bcb2354b55..ba92046c28 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -58,6 +58,8 @@ describe "ProjectController", -> getLoggedInUserId: sinon.stub().returns(@user._id) getSessionUser: sinon.stub().returns(@user) isUserLoggedIn: sinon.stub().returns(true) + @AnalyticsManager = + getLastOccurance: sinon.stub() @ProjectController = SandboxedModule.require modulePath, requires: "settings-sharelatex":@settings "logger-sharelatex": @@ -82,6 +84,7 @@ describe "ProjectController", -> "../ReferencesSearch/ReferencesSearchHandler": @ReferencesSearchHandler "./ProjectGetter": @ProjectGetter '../Authentication/AuthenticationController': @AuthenticationController + "../Analytics/AnalyticsManager": @AnalyticsManager @projectName = "£12321jkj9ujkljds" @req = @@ -310,9 +313,9 @@ describe "ProjectController", -> @AuthorizationManager.getPrivilegeLevelForProject.callsArgWith 2, null, "owner" @ProjectDeleter.unmarkAsDeletedByExternalSource = sinon.stub() @InactiveProjectManager.reactivateProjectIfRequired.callsArgWith(1) + @AnalyticsManager.getLastOccurance.yields(null, {"mock": "event"}) @ProjectUpdateHandler.markAsOpened.callsArgWith(1) - it "should render the project/editor page", (done)-> @res.render = (pageName, opts)=> pageName.should.equal "project/editor" @@ -357,3 +360,24 @@ describe "ProjectController", -> @ProjectUpdateHandler.markAsOpened.calledWith(@project_id).should.equal true done() @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