Ghost/core/server/analytics-events.js
Hannah Wolfe baa8118893 Refactor common pattern in service files
- Use array destructuring
- Use @tryghost/errors
- Part of the big move towards decoupling, this gives visibility on what's being used where
- Biting off manageable chunks / fixing bits of code I'm refactoring for other reasons
2020-04-30 20:48:42 +01:00

36 lines
983 B
JavaScript

const _ = require('lodash');
const Analytics = require('analytics-node');
const config = require('./config');
const {events} = require('./lib/common');
module.exports.init = function () {
const analytics = new Analytics(config.get('segment:key'));
const trackDefaults = config.get('segment:trackDefaults') || {};
const prefix = config.get('segment:prefix') || '';
const toTrack = [
{
event: 'post.published',
name: 'Post Published'
},
{
event: 'page.published',
name: 'Page Published'
},
{
event: 'theme.uploaded',
name: 'Theme Uploaded'
},
{
event: 'integration.added',
name: 'Custom Integration Added'
}
];
_.each(toTrack, function (track) {
events.on(track.event, function () {
analytics.track(_.extend(trackDefaults, {event: prefix + track.name}));
});
});
};