2017-08-22 14:23:23 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
Analytics = require('analytics-node'),
|
2017-12-12 00:47:46 +03:00
|
|
|
config = require('./config'),
|
|
|
|
common = require('./lib/common'),
|
2017-08-22 14:23:23 +03:00
|
|
|
analytics;
|
|
|
|
|
|
|
|
module.exports.init = function () {
|
|
|
|
analytics = new Analytics(config.get('segment:key'));
|
|
|
|
var toTrack,
|
|
|
|
trackDefaults = config.get('segment:trackDefaults') || {},
|
|
|
|
prefix = config.get('segment:prefix') || '';
|
|
|
|
|
|
|
|
toTrack = [
|
|
|
|
{
|
|
|
|
event: 'post.published',
|
|
|
|
name: 'Blog Post Published'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
event: 'page.published',
|
|
|
|
name: 'Blog Page Published'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
_.each(toTrack, function (track) {
|
2017-12-12 00:47:46 +03:00
|
|
|
common.events.on(track.event, function () {
|
2017-08-22 14:23:23 +03:00
|
|
|
analytics.track(_.extend(trackDefaults, {event: prefix + track.name}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|