2016-11-11 17:03:01 +00:00
|
|
|
settings = require "settings-sharelatex"
|
2016-08-10 15:42:56 +00:00
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
_ = require "underscore"
|
2016-11-11 17:03:01 +00:00
|
|
|
request = require "request"
|
2017-03-21 10:57:39 +00:00
|
|
|
Errors = require '../Errors/Errors'
|
2016-08-10 15:42:56 +00:00
|
|
|
|
|
|
|
|
2016-11-16 14:40:38 +00:00
|
|
|
makeRequest = (opts, callback)->
|
2016-11-15 10:54:48 +00:00
|
|
|
if settings.apis?.analytics?.url?
|
2016-11-16 14:40:38 +00:00
|
|
|
urlPath = opts.url
|
|
|
|
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
|
2016-11-15 10:54:48 +00:00
|
|
|
request opts, callback
|
|
|
|
else
|
2017-03-21 10:57:39 +00:00
|
|
|
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|
2016-11-15 10:54:48 +00:00
|
|
|
|
2016-08-10 15:42:56 +00:00
|
|
|
|
2016-11-11 17:03:01 +00:00
|
|
|
module.exports =
|
|
|
|
|
2017-03-22 16:01:26 +00:00
|
|
|
identifyUser: (user_id, old_user_id, callback = (error)->)->
|
2017-03-08 17:51:35 +00:00
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
old_user_id:old_user_id
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2017-03-22 15:50:49 +00:00
|
|
|
url: "/user/#{user_id}/identify"
|
|
|
|
makeRequest opts, callback
|
2016-11-15 10:54:48 +00:00
|
|
|
|
2016-11-11 17:03:01 +00:00
|
|
|
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
|
2016-11-28 19:19:00 +00:00
|
|
|
if user_id+"" == settings.smokeTest?.userId+""
|
2016-11-15 13:41:15 +00:00
|
|
|
return callback()
|
2016-11-11 17:03:01 +00:00
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
segmentation:segmentation
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2016-11-16 14:40:38 +00:00
|
|
|
url: "/user/#{user_id}/event"
|
2016-11-15 15:36:26 +00:00
|
|
|
makeRequest opts, callback
|
2016-11-11 17:03:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
getLastOccurance: (user_id, event, callback = (error) ->) ->
|
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2016-11-16 14:40:38 +00:00
|
|
|
url: "/user/#{user_id}/event/last_occurnace"
|
2016-11-15 15:36:26 +00:00
|
|
|
makeRequest opts, (err, response, body)->
|
2016-11-11 17:03:01 +00:00
|
|
|
if err?
|
|
|
|
console.log response, opts
|
|
|
|
logger.err {user_id, err}, "error getting last occurance of event"
|
|
|
|
return callback err
|
|
|
|
else
|
2016-11-16 14:40:38 +00:00
|
|
|
return callback null, body
|