Vulcan/packages/telescope-events/lib/events.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

Telescope.schemas.events = 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
}
});
Events = new Meteor.Collection('events');
Telescope.schemas.events.internationalize();
Events.attachSchema(Telescope.schemas.events);
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
}
event.createdAt = new Date();
Events.insert(event);
}
}
Events.track = function(event, properties){
// console.log('trackevent: ', event, properties);
var properties= (typeof properties === 'undefined') ? {} : properties;
//TODO
// add event to an Events collection for logging and buffering purposes
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));
}
}
};