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