Переглянути джерело

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
Alberto Fernández Capel 8 роки тому
батько
коміт
7d0d18ea5e

+ 2 - 0
services/web/public/coffee/ide.coffee

@@ -176,6 +176,8 @@ define [
 			$scope.$broadcast('ide:loaded')
 			$scope.$broadcast('ide:loaded')
 			_loaded = true
 			_loaded = true
 
 
+		$scope.$on 'cursor:editor:update', event_tracking.editingSessionHeartbeat
+
 		DARK_THEMES = [
 		DARK_THEMES = [
 			"ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers",
 			"ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers",
 			"merbivore", "merbivore_soft", "mono_industrial", "monokai",
 			"merbivore", "merbivore_soft", "mono_industrial", "monokai",

+ 0 - 2
services/web/public/coffee/ide/editor/directives/aceEditor.coffee

@@ -301,8 +301,6 @@ define [
 				onChange = () ->
 				onChange = () ->
 					updateCount++
 					updateCount++
 
 
-					event_tracking.editingSessionHeartbeat()
-
 					if updateCount == 100
 					if updateCount == 100
 						event_tracking.send 'editor-interaction', 'multi-doc-update'
 						event_tracking.send 'editor-interaction', 'multi-doc-update'
 					scope.$emit "#{scope.name}:change"
 					scope.$emit "#{scope.name}:change"

+ 11 - 11
services/web/public/coffee/main/event.coffee

@@ -37,6 +37,16 @@ define [
 
 
 			localStorage CACHE_KEY, curCache
 			localStorage CACHE_KEY, curCache
 
 
+		_sendEditingSessionHeartbeat = (segmentation) ->
+			$http({
+				url: "/editingSession/#{window.project_id}",
+				method: "PUT",
+				data: segmentation,
+				headers: {
+					"X-CSRF-Token": window.csrfToken
+				}
+			})
+
 		return {
 		return {
 			send: (category, action, label, value)->
 			send: (category, action, label, value)->
 				ga('send', 'event', category, action, label, value)
 				ga('send', 'event', category, action, label, value)
@@ -45,7 +55,7 @@ define [
 			editingSessionHeartbeat: (segmentation = {}) ->
 			editingSessionHeartbeat: (segmentation = {}) ->
 				return unless nextHeartbeat <= new Date()
 				return unless nextHeartbeat <= new Date()
 
 
-				@_sendEditingSessionHeartbeat(segmentation)
+				_sendEditingSessionHeartbeat(segmentation)
 
 
 				heartbeatsSent++
 				heartbeatsSent++
 
 
@@ -60,16 +70,6 @@ define [
 
 
 				nextHeartbeat = moment().add(backoffSecs, 'seconds').toDate()
 				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 = {}) ->
 			sendMB: (key, segmentation = {}) ->
 				$http {
 				$http {
 					url: "/event/#{key}",
 					url: "/event/#{key}",