2020-04-29 18:44:27 +03:00
|
|
|
const _ = require('lodash');
|
|
|
|
const Analytics = require('analytics-node');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../shared/config');
|
2020-04-30 22:26:12 +03:00
|
|
|
const {events} = require('./lib/common');
|
2017-08-22 14:23:23 +03:00
|
|
|
|
|
|
|
module.exports.init = function () {
|
2020-04-30 22:26:12 +03:00
|
|
|
const analytics = new Analytics(config.get('segment:key'));
|
2020-04-29 18:44:27 +03:00
|
|
|
const trackDefaults = config.get('segment:trackDefaults') || {};
|
|
|
|
const prefix = config.get('segment:prefix') || '';
|
2017-08-22 14:23:23 +03:00
|
|
|
|
2020-04-30 22:26:12 +03:00
|
|
|
const toTrack = [
|
2017-08-22 14:23:23 +03:00
|
|
|
{
|
|
|
|
event: 'post.published',
|
2019-02-05 19:38:40 +03:00
|
|
|
name: 'Post Published'
|
2017-08-22 14:23:23 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
event: 'page.published',
|
2019-02-05 19:38:40 +03:00
|
|
|
name: 'Page Published'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
event: 'theme.uploaded',
|
|
|
|
name: 'Theme Uploaded'
|
2019-03-11 17:28:17 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
event: 'integration.added',
|
|
|
|
name: 'Custom Integration Added'
|
2017-08-22 14:23:23 +03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
_.each(toTrack, function (track) {
|
2020-04-30 22:26:12 +03:00
|
|
|
events.on(track.event, function () {
|
2017-08-22 14:23:23 +03:00
|
|
|
analytics.track(_.extend(trackDefaults, {event: prefix + track.name}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|