Log analytics events internally

This commit is contained in:
Matt Lott 2014-12-15 11:45:12 -08:00
parent 5817553d54
commit c76662c967
6 changed files with 58 additions and 0 deletions

View file

@ -1,4 +1,5 @@
{me} = require 'core/auth'
AnalyticsLogEvent = require 'models/AnalyticsLogEvent'
debugAnalytics = false
@ -68,6 +69,10 @@ module.exports = class Tracker
for integration in includeIntegrations
context.integrations[integration] = true
analytics?.track action, properties, context
# Log internally too. Will turn off external event logging when internal logging is sufficient.
event = new AnalyticsLogEvent event: action, properties: properties
event.save()
trackTiming: (duration, category, variable, label, samplePercentage=5) ->
# https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingTiming

View file

@ -0,0 +1,6 @@
CocoModel = require './CocoModel'
module.exports = class AnalyticsLogEvent extends CocoModel
@className: 'AnalyticsLogEvent'
@schema: require 'schemas/models/analytics_log_event'
urlRoot: '/db/analytics.log.event'

View file

@ -0,0 +1,16 @@
c = require './../schemas'
AnalyticsLogEventSchema = c.object {
title: 'Analytics Log Event'
description: 'Analytics event logs.'
}
_.extend AnalyticsLogEventSchema.properties,
created: c.date({title: 'Created', readOnly: true})
user: c.objectId(links: [{rel: 'extra', href: '/db/user/{($)}'}])
event: {type: 'string'}
properties: {type: 'object'}
c.extendBasicProperties AnalyticsLogEventSchema, 'analytics.log.event'
module.exports = AnalyticsLogEventSchema

View file

@ -0,0 +1,10 @@
mongoose = require 'mongoose'
plugins = require '../plugins/plugins'
AnalyticsLogEventSchema = new mongoose.Schema({
created:
type: Date
'default': Date.now
}, {strict: false})
module.exports = AnalyticsLogEvent = mongoose.model('analytics.log.event', AnalyticsLogEventSchema)

View file

@ -0,0 +1,20 @@
AnalyticsLogEvent = require './AnalyticsLogEvent'
Handler = require '../commons/Handler'
class AnalyticsLogEventHandler extends Handler
modelClass: AnalyticsLogEvent
jsonSchema: require '../../app/schemas/models/analytics_log_event'
editableProperties: [
'event'
'properties'
]
hasAccess: (req) ->
req.method in ['PUT', 'POST'] or req.user?.isAdmin()
makeNewInstance: (req) ->
instance = super(req)
instance.set('user', req.user._id)
instance
module.exports = new AnalyticsLogEventHandler()

View file

@ -1,4 +1,5 @@
module.exports.handlers =
'analytics_log_event': 'analytics/analytics_log_event_handler'
'analytics_users_active': 'analytics/analytics_users_active_handler'
'article': 'articles/article_handler'
'level': 'levels/level_handler'