Vulcan/packages/nova-events/lib/collection.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-06-23 15:16:32 +09:00
const Events = new Mongo.Collection('events');
2015-05-11 12:15:10 +09:00
Events.schema = new SimpleSchema({
2014-12-31 17:44:21 +09:00
createdAt: {
type: Date
},
name: {
type: String
},
description: {
type: String,
optional: true
},
unique: {
type: Boolean,
optional: true
},
important: { // marking an event as important means it should never be erased
type: Boolean,
optional: true
2015-02-03 11:17:34 +09:00
},
properties: {
type: Object,
optional: true,
blackbox: true
2014-12-31 17:44:21 +09:00
}
});
2016-02-16 15:08:30 +09:00
// Meteor.startup(function(){
// // needs to happen after every fields are added
// Events.internationalize();
// });
2014-12-31 17:44:21 +09:00
2015-05-11 12:15:10 +09:00
Events.attachSchema(Events.schema);
2014-12-31 17:44:21 +09:00
if (Meteor.isServer) {
Events.log = function (event) {
2014-12-31 17:44:21 +09:00
// if event is supposed to be unique, check if it has already been logged
2014-12-31 17:44:21 +09:00
if (!!event.unique && !!Events.findOne({name: event.name})) {
return;
2014-12-31 17:44:21 +09:00
}
event.createdAt = new Date();
Events.insert(event);
};
}
Events.track = function(event, properties){
// console.log('trackevent: ', event, properties);
properties = properties || {};
//TODO
// add event to an Events collection for logging and buffering purposes
2016-02-16 15:08:30 +09:00
// if(Meteor.isClient){
// if(typeof mixpanel !== 'undefined' && typeof mixpanel.track !== 'undefined'){
// mixpanel.track(event, properties);
// }
// if(typeof GoSquared !== 'undefined' && typeof GoSquared.DefaultTracker !== 'undefined'){
// GoSquared.DefaultTracker.TrackEvent(event, JSON.stringify(properties));
// }
// }
};
2016-06-23 15:16:32 +09:00
export default Events;