mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Send edit sessions heartbeat to the analytics service
This commit is contained in:
parent
1a1ccc9f46
commit
868e32c1bc
5 changed files with 43 additions and 0 deletions
|
@ -3,6 +3,19 @@ Errors = require "../Errors/Errors"
|
|||
AuthenticationController = require("../Authentication/AuthenticationController")
|
||||
|
||||
module.exports = AnalyticsController =
|
||||
updateEditSession: (req, res, next) ->
|
||||
userId = AuthenticationController.getLoggedInUserId(req) or req.sessionID
|
||||
projectId = req.params.projectId
|
||||
|
||||
AnalyticsManager.updateEditSession userId, projectId, {}, (error) ->
|
||||
if error instanceof Errors.ServiceNotConfiguredError
|
||||
# ignore, no-op
|
||||
return res.send(204)
|
||||
else if error?
|
||||
return next(error)
|
||||
else
|
||||
return res.send 204
|
||||
|
||||
recordEvent: (req, res, next) ->
|
||||
user_id = AuthenticationController.getLoggedInUserId(req) or req.sessionID
|
||||
AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
|
||||
|
|
|
@ -39,6 +39,18 @@ module.exports =
|
|||
url: "/user/#{user_id}/event"
|
||||
makeRequest opts, callback
|
||||
|
||||
updateEditSession: (userId, projectId, segmentation = {}, callback = (error) ->) ->
|
||||
if userId+"" == settings.smokeTest?.userId+""
|
||||
return callback()
|
||||
opts =
|
||||
body:
|
||||
segmentation: segmentation
|
||||
json: true
|
||||
method: "PUT"
|
||||
timeout: 1000
|
||||
url: "/editSession?userId=#{userId}&projectId=#{projectId}"
|
||||
makeRequest opts, callback
|
||||
|
||||
|
||||
getLastOccurance: (user_id, event, callback = (error) ->) ->
|
||||
opts =
|
||||
|
|
|
@ -5,6 +5,7 @@ AnalyticsProxy = require('./AnalyticsProxy')
|
|||
module.exports =
|
||||
apply: (webRouter, privateApiRouter, publicApiRouter) ->
|
||||
webRouter.post '/event/:event', AnalyticsController.recordEvent
|
||||
webRouter.put '/editSession/:projectId', AnalyticsController.updateEditSession
|
||||
publicApiRouter.use '/analytics/graphs',
|
||||
AuthenticationController.httpAuth,
|
||||
AnalyticsProxy.call('/graphs')
|
||||
|
|
|
@ -300,6 +300,10 @@ define [
|
|||
updateCount = 0
|
||||
onChange = () ->
|
||||
updateCount++
|
||||
|
||||
projectId = _.last( location.pathname.split("/"))
|
||||
event_tracking.editSessionHeartbeat(projectId)
|
||||
|
||||
if updateCount == 100
|
||||
event_tracking.send 'editor-interaction', 'multi-doc-update'
|
||||
scope.$emit "#{scope.name}:change"
|
||||
|
|
|
@ -3,6 +3,7 @@ define [
|
|||
"modules/localStorage"
|
||||
], (App) ->
|
||||
CACHE_KEY = "mbEvents"
|
||||
EDIT_SESSION_HEARTBEAT_INTERVAL = 5 * 60 * 1000 # 5min
|
||||
|
||||
send = (category, action, attributes = {})->
|
||||
ga('send', 'event', category, action)
|
||||
|
@ -34,6 +35,18 @@ define [
|
|||
send: (category, action, label, value)->
|
||||
ga('send', 'event', category, action, label, value)
|
||||
|
||||
editSessionHeartbeat: _.throttle( (projectId, segmentation = {}) ->
|
||||
$http({
|
||||
url: "/editSession/#{projectId}",
|
||||
method: "PUT",
|
||||
data: segmentation,
|
||||
headers: {
|
||||
"X-CSRF-Token": window.csrfToken
|
||||
}
|
||||
})
|
||||
, EDIT_SESSION_HEARTBEAT_INTERVAL)
|
||||
|
||||
|
||||
sendMB: (key, segmentation = {}) ->
|
||||
$http {
|
||||
url: "/event/#{key}",
|
||||
|
|
Loading…
Reference in a new issue