mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-25 14:04:54 -05:00
Switch to using actual node server to receive log events
This commit is contained in:
parent
bd14e49707
commit
3a9f0adba8
3 changed files with 16 additions and 41 deletions
|
@ -165,16 +165,7 @@ module.exports = class Tracker extends CocoClass
|
||||||
|
|
||||||
properties[key] = value for key, value of @explicitTraits if @explicitTraits?
|
properties[key] = value for key, value of @explicitTraits if @explicitTraits?
|
||||||
console.log 'Tracking internal analytics event:', event, properties if debugAnalytics
|
console.log 'Tracking internal analytics event:', event, properties if debugAnalytics
|
||||||
if @isProduction
|
|
||||||
eventObject = {}
|
|
||||||
eventObject["event"] = event
|
|
||||||
eventObject["properties"] = properties unless _.isEmpty properties
|
|
||||||
eventObject["user"] = me.id
|
|
||||||
dataToSend = JSON.stringify eventObject
|
|
||||||
# console.log dataToSend if debugAnalytics
|
|
||||||
$.post("#{window.location.protocol or 'http:'}//analytics-cf.codecombat.com/analytics", dataToSend).fail ->
|
|
||||||
console.error "Analytics post failed!"
|
|
||||||
else
|
|
||||||
request = @supermodel.addRequestResource {
|
request = @supermodel.addRequestResource {
|
||||||
url: '/db/analytics.log.event/-/log_event'
|
url: '/db/analytics.log.event/-/log_event'
|
||||||
data: {event: event, properties: properties}
|
data: {event: event, properties: properties}
|
||||||
|
|
|
@ -6,15 +6,10 @@ http = require 'http'
|
||||||
config = require '../../server_config'
|
config = require '../../server_config'
|
||||||
|
|
||||||
AnalyticsLogEventSchema = new mongoose.Schema({
|
AnalyticsLogEventSchema = new mongoose.Schema({
|
||||||
u: mongoose.Schema.Types.ObjectId
|
user: String #Actually a `mongoose.Schema.Types.ObjectId` but ...
|
||||||
e: Number # event analytics.string ID
|
|
||||||
p: mongoose.Schema.Types.Mixed
|
|
||||||
|
|
||||||
# TODO: Remove these legacy properties after we stop querying for them (probably 30 days, ~2/16/15)
|
|
||||||
user: mongoose.Schema.Types.ObjectId
|
|
||||||
event: String
|
event: String
|
||||||
properties: mongoose.Schema.Types.Mixed
|
properties: mongoose.Schema.Types.Mixed
|
||||||
}, {strict: false})
|
}, {strict: false, versionKey: false})
|
||||||
|
|
||||||
AnalyticsLogEventSchema.index({event: 1, _id: -1})
|
AnalyticsLogEventSchema.index({event: 1, _id: -1})
|
||||||
AnalyticsLogEventSchema.index({event: 1, 'properties.level': 1})
|
AnalyticsLogEventSchema.index({event: 1, 'properties.level': 1})
|
||||||
|
@ -30,23 +25,9 @@ AnalyticsLogEventSchema.statics.logEvent = (user, event, properties={}) ->
|
||||||
user: user
|
user: user
|
||||||
event: event
|
event: event
|
||||||
properties: properties
|
properties: properties
|
||||||
if config.isProduction and not config.unittest
|
|
||||||
docString = JSON.stringify doc
|
|
||||||
headers =
|
|
||||||
"Content-Type":'application/json'
|
|
||||||
"Content-Length": docString.length
|
|
||||||
|
|
||||||
options =
|
|
||||||
host: 'analytics.codecombat.com'
|
|
||||||
port: 80
|
|
||||||
path: '/analytics'
|
|
||||||
method: 'POST'
|
|
||||||
headers: headers
|
|
||||||
req = http.request options, (res) ->
|
|
||||||
req.on 'error', (e) -> log.warn e
|
|
||||||
req.write(docString)
|
|
||||||
req.end()
|
|
||||||
else
|
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
module.exports = AnalyticsLogEvent = mongoose.model('analytics.log.event', AnalyticsLogEventSchema)
|
analyticsMongoose = mongoose.createConnection "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}"
|
||||||
|
|
||||||
|
module.exports = AnalyticsLogEvent = analyticsMongoose.model(config.mongo.analytics_collection, AnalyticsLogEventSchema)
|
||||||
|
|
|
@ -21,10 +21,13 @@ config.mongo =
|
||||||
analytics_port: process.env.COCO_MONGO_ANALYTICS_PORT or 27017
|
analytics_port: process.env.COCO_MONGO_ANALYTICS_PORT or 27017
|
||||||
analytics_host: process.env.COCO_MONGO_ANALYTICS_HOST or 'localhost'
|
analytics_host: process.env.COCO_MONGO_ANALYTICS_HOST or 'localhost'
|
||||||
analytics_db: process.env.COCO_MONGO_ANALYTICS_DATABASE_NAME or 'analytics'
|
analytics_db: process.env.COCO_MONGO_ANALYTICS_DATABASE_NAME or 'analytics'
|
||||||
|
analytics_collection: process.env.COCO_MONGO_ANALYTICS_COLLECTION or 'analytics.log.event'
|
||||||
mongoose_replica_string: process.env.COCO_MONGO_MONGOOSE_REPLICA_STRING or ''
|
mongoose_replica_string: process.env.COCO_MONGO_MONGOOSE_REPLICA_STRING or ''
|
||||||
mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or ''
|
mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or ''
|
||||||
mongoose_saoPaulo_replica_string : process.env.COCO_MONGO_MONGOOSE_SAOPAULO_REPLICA_STRING or ''
|
mongoose_saoPaulo_replica_string : process.env.COCO_MONGO_MONGOOSE_SAOPAULO_REPLICA_STRING or ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if config.tokyo or config.saoPaulo
|
if config.tokyo or config.saoPaulo
|
||||||
config.mongo.readpref = 'nearest'
|
config.mongo.readpref = 'nearest'
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue