From 7d0d18ea5ed333a00b8b3f875756bc29af126949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez=20Capel?= Date: Wed, 24 Jan 2018 17:20:30 +0000 Subject: [PATCH] Use the cursor:editor:update event to track user activity It is strictly a superset of the change event we were using before: if there's a change, there will be always a cursor update, but there can be cursor updates (like when the user presses the arrow keys) that don't change the document. This is coherent with what we do to track user activity at https://github.com/sharelatex/web-sharelatex-internal/blob/dfb994352112e3535aac7a2c415e12d8050b2987/public/coffee/ide/connection/ConnectionManager.coffee#L49-L50 --- services/web/public/coffee/ide.coffee | 2 ++ .../ide/editor/directives/aceEditor.coffee | 2 -- services/web/public/coffee/main/event.coffee | 22 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 3d514d093c..7a5738dbc5 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -176,6 +176,8 @@ define [ $scope.$broadcast('ide:loaded') _loaded = true + $scope.$on 'cursor:editor:update', event_tracking.editingSessionHeartbeat + DARK_THEMES = [ "ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers", "merbivore", "merbivore_soft", "mono_industrial", "monokai", diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 80b58cb003..e90fa2f4c0 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -301,8 +301,6 @@ define [ onChange = () -> updateCount++ - event_tracking.editingSessionHeartbeat() - if updateCount == 100 event_tracking.send 'editor-interaction', 'multi-doc-update' scope.$emit "#{scope.name}:change" diff --git a/services/web/public/coffee/main/event.coffee b/services/web/public/coffee/main/event.coffee index 894737557a..e03a0a8afb 100644 --- a/services/web/public/coffee/main/event.coffee +++ b/services/web/public/coffee/main/event.coffee @@ -37,6 +37,16 @@ define [ localStorage CACHE_KEY, curCache + _sendEditingSessionHeartbeat = (segmentation) -> + $http({ + url: "/editingSession/#{window.project_id}", + method: "PUT", + data: segmentation, + headers: { + "X-CSRF-Token": window.csrfToken + } + }) + return { send: (category, action, label, value)-> ga('send', 'event', category, action, label, value) @@ -45,7 +55,7 @@ define [ editingSessionHeartbeat: (segmentation = {}) -> return unless nextHeartbeat <= new Date() - @_sendEditingSessionHeartbeat(segmentation) + _sendEditingSessionHeartbeat(segmentation) heartbeatsSent++ @@ -60,16 +70,6 @@ define [ nextHeartbeat = moment().add(backoffSecs, 'seconds').toDate() - _sendEditingSessionHeartbeat: (segmentation) -> - $http({ - url: "/editingSession/#{window.project_id}", - method: "PUT", - data: segmentation, - headers: { - "X-CSRF-Token": window.csrfToken - } - }) - sendMB: (key, segmentation = {}) -> $http { url: "/event/#{key}",