overleaf/services/web/app/coffee/Features/Analytics/AnalyticsManager.coffee
Henry Oswald 5a13ee1077 use anlaytis api
- don’t talk to postgres
- show recent blog post announcments
- proxy all events to analytics api
2016-11-11 17:03:09 +00:00

36 lines
No EOL
864 B
CoffeeScript

settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
_ = require "underscore"
request = require "request"
module.exports =
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