mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Log analytics events internally
This commit is contained in:
parent
5817553d54
commit
c76662c967
6 changed files with 58 additions and 0 deletions
|
@ -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
|
||||
|
|
6
app/models/AnalyticsLogEvent.coffee
Normal file
6
app/models/AnalyticsLogEvent.coffee
Normal 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'
|
16
app/schemas/models/analytics_log_event.coffee
Normal file
16
app/schemas/models/analytics_log_event.coffee
Normal 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
|
10
server/analytics/AnalyticsLogEvent.coffee
Normal file
10
server/analytics/AnalyticsLogEvent.coffee
Normal 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)
|
20
server/analytics/analytics_log_event_handler.coffee
Normal file
20
server/analytics/analytics_log_event_handler.coffee
Normal 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()
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue