Rename metadata -> segmentation in Events table to play well with metabase

This commit is contained in:
James Allen 2016-08-10 17:22:35 +01:00
parent 056bb6b0f4
commit 4886e8ba0e

View file

@ -4,8 +4,8 @@ _ = require "underscore"
if !Settings.analytics?.postgres?
module.exports =
recordEvent: (user_id, event, metadata, callback = () ->) ->
logger.log {user_id, event, metadata}, "no event tracking configured, logging event"
recordEvent: (user_id, event, segmentation, callback = () ->) ->
logger.log {user_id, event, segmentation}, "no event tracking configured, logging event"
callback()
else
Sequelize = require "sequelize"
@ -21,22 +21,22 @@ else
Event = sequelize.define("Event", {
user_id: Sequelize.STRING,
event: Sequelize.STRING,
metadata: Sequelize.JSON
segmentation: Sequelize.JSON
})
module.exports =
recordEvent: (user_id, event, metadata = {}, callback = (error) ->) ->
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
if user_id? and typeof(user_id) != "string"
user_id = user_id.toString()
if user_id == Settings.smokeTest?.userId
# Don't record smoke tests analytics
return callback()
Event
.create({ user_id, event, metadata })
.create({ user_id, event, segmentation })
.then(
(result) -> callback(),
(error) ->
logger.err {err: error, user_id, event, metadata}, "error recording analytics event"
logger.err {err: error, user_id, event, segmentation}, "error recording analytics event"
callback(error)
)