2016-11-11 12:03:01 -05:00
|
|
|
settings = require "settings-sharelatex"
|
2016-08-10 11:42:56 -04:00
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
_ = require "underscore"
|
2016-11-11 12:03:01 -05:00
|
|
|
request = require "request"
|
2016-08-10 11:42:56 -04:00
|
|
|
|
|
|
|
|
2016-11-16 09:40:38 -05:00
|
|
|
makeRequest = (opts, callback)->
|
2016-11-15 05:54:48 -05:00
|
|
|
if settings.apis?.analytics?.url?
|
2016-11-16 09:40:38 -05:00
|
|
|
urlPath = opts.url
|
|
|
|
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
|
2016-11-15 05:54:48 -05:00
|
|
|
request opts, callback
|
|
|
|
else
|
|
|
|
callback()
|
|
|
|
|
|
|
|
|
2016-08-10 11:42:56 -04:00
|
|
|
|
2016-11-11 12:03:01 -05:00
|
|
|
module.exports =
|
|
|
|
|
2017-03-22 11:50:49 -04:00
|
|
|
idendifyUser: (user_id, old_user_id, callback = (error)->)->
|
2017-03-08 12:51:35 -05:00
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
old_user_id:old_user_id
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2017-03-22 11:50:49 -04:00
|
|
|
url: "/user/#{user_id}/identify"
|
|
|
|
makeRequest opts, callback
|
2016-11-15 05:54:48 -05:00
|
|
|
|
2016-11-11 12:03:01 -05:00
|
|
|
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
|
2016-11-28 14:19:00 -05:00
|
|
|
if user_id+"" == settings.smokeTest?.userId+""
|
2016-11-15 08:41:15 -05:00
|
|
|
return callback()
|
2016-11-11 12:03:01 -05:00
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
segmentation:segmentation
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2016-11-16 09:40:38 -05:00
|
|
|
url: "/user/#{user_id}/event"
|
2016-11-15 10:36:26 -05:00
|
|
|
makeRequest opts, callback
|
2016-11-11 12:03:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
getLastOccurance: (user_id, event, callback = (error) ->) ->
|
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
2016-11-16 09:40:38 -05:00
|
|
|
url: "/user/#{user_id}/event/last_occurnace"
|
2016-11-15 10:36:26 -05:00
|
|
|
makeRequest opts, (err, response, body)->
|
2016-11-11 12:03:01 -05: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 09:40:38 -05:00
|
|
|
return callback null, body
|