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-15 05:54:48 -05:00
|
|
|
makeRequest: (opts, callback)->
|
|
|
|
if settings.apis?.analytics?.url?
|
|
|
|
request opts, callback
|
|
|
|
else
|
|
|
|
callback()
|
|
|
|
|
|
|
|
|
2016-08-10 11:42:56 -04:00
|
|
|
|
2016-11-11 12:03:01 -05:00
|
|
|
module.exports =
|
|
|
|
|
2016-11-15 05:54:48 -05:00
|
|
|
|
2016-11-11 12:03:01 -05:00
|
|
|
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
|
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
segmentation:segmentation
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
|
|
|
url: "#{settings.apis.analytics.url}/user/#{user_id}/event"
|
|
|
|
request opts, callback
|
|
|
|
|
|
|
|
|
|
|
|
getLastOccurance: (user_id, event, callback = (error) ->) ->
|
|
|
|
opts =
|
|
|
|
body:
|
|
|
|
event:event
|
|
|
|
json:true
|
|
|
|
method:"POST"
|
|
|
|
timeout:1000
|
|
|
|
url: "#{settings.apis.analytics.url}/user/#{user_id}/event/last_occurnace"
|
|
|
|
request opts, (err, response, body)->
|
|
|
|
if err?
|
|
|
|
console.log response, opts
|
|
|
|
logger.err {user_id, err}, "error getting last occurance of event"
|
|
|
|
return callback err
|
|
|
|
else
|
|
|
|
return callback null, body
|