2015-02-04 16:54:35 -05:00
|
|
|
log = require 'winston'
|
2014-12-15 14:45:12 -05:00
|
|
|
mongoose = require 'mongoose'
|
|
|
|
plugins = require '../plugins/plugins'
|
2015-02-04 16:54:35 -05:00
|
|
|
utils = require '../lib/utils'
|
2015-03-02 19:02:26 -05:00
|
|
|
http = require 'http'
|
|
|
|
config = require '../../server_config'
|
2014-12-15 14:45:12 -05:00
|
|
|
|
2015-01-14 20:51:04 -05:00
|
|
|
AnalyticsLogEventSchema = new mongoose.Schema({
|
2016-06-09 18:02:01 -04:00
|
|
|
user: String #Actually a `mongoose.Schema.Types.ObjectId` but ...
|
2015-01-14 20:51:04 -05:00
|
|
|
event: String
|
|
|
|
properties: mongoose.Schema.Types.Mixed
|
2016-06-09 18:02:01 -04:00
|
|
|
}, {strict: false, versionKey: false})
|
2015-01-27 13:02:47 -05:00
|
|
|
|
2015-05-01 12:37:43 -04:00
|
|
|
AnalyticsLogEventSchema.index({event: 1, _id: -1})
|
|
|
|
AnalyticsLogEventSchema.index({event: 1, 'properties.level': 1})
|
2016-02-09 19:50:51 -05:00
|
|
|
AnalyticsLogEventSchema.index({event: 1, 'properties.levelID': 1})
|
2015-05-02 21:28:47 -04:00
|
|
|
AnalyticsLogEventSchema.index({user: 1, event: 1})
|
2014-12-15 14:45:12 -05:00
|
|
|
|
2015-02-09 18:02:45 -05:00
|
|
|
AnalyticsLogEventSchema.statics.logEvent = (user, event, properties={}) ->
|
2015-02-04 16:54:35 -05:00
|
|
|
unless user?
|
|
|
|
log.warn 'No user given to analytics logEvent.'
|
|
|
|
return
|
|
|
|
|
2015-03-02 19:02:26 -05:00
|
|
|
doc = new AnalyticsLogEvent
|
|
|
|
user: user
|
|
|
|
event: event
|
|
|
|
properties: properties
|
|
|
|
|
2016-06-09 18:02:01 -04:00
|
|
|
doc.save()
|
|
|
|
|
2016-06-17 14:41:43 -04:00
|
|
|
unless config.proxy
|
|
|
|
analyticsMongoose = mongoose.createConnection()
|
2016-09-02 18:57:26 -04:00
|
|
|
analyticsMongoose.open config.mongo.analytics_replica_string, (error) ->
|
2016-09-02 19:00:50 -04:00
|
|
|
if error
|
|
|
|
log.error "Couldn't connect to analytics", error
|
|
|
|
else
|
|
|
|
log.info "Connected to analytics mongo at #{config.mongo.analytics_replica_string}"
|
2016-07-14 11:58:43 -04:00
|
|
|
|
2016-06-17 14:41:43 -04:00
|
|
|
module.exports = AnalyticsLogEvent = analyticsMongoose.model('analytics.log.event', AnalyticsLogEventSchema, config.mongo.analytics_collection)
|