Add segment analytics for blog data (#8912)

no issue
- adds data to track such as post published
- adds ability to add custom data and event prefix via config file
This commit is contained in:
David Wolfe 2017-08-22 12:23:23 +01:00 committed by Kevin Ansfield
parent ff15dc1667
commit be54da265b
4 changed files with 145 additions and 2 deletions

View File

@ -0,0 +1,69 @@
var _ = require('lodash'),
config = require('./config'),
events = require('./events'),
Analytics = require('analytics-node'),
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.added',
name: 'Blog Post Created'
},
{
event: 'post.published',
name: 'Blog Post Published'
},
{
event: 'page.published',
name: 'Blog Page Published'
},
{
event: 'user.added',
name: 'User Invite Sent'
},
{
event: 'user.activated',
name: 'User Invite Activated'
},
{
event: 'user.activated.edited',
name: 'User Account Updated'
},
{
event: 'subscriber.added',
name: 'New Subscriber Added'
},
{
event: 'token.added',
name: 'Access Token Added'
},
{
event: 'setup.completed',
name: 'Created Owner Account'
},
{
event: 'theme.uploaded',
name: 'Uploaded Theme'
},
{
event: 'theme.downloaded',
name: 'Downloaded Theme'
},
{
event: 'theme.deleted',
name: 'Deleted Theme'
}
];
_.each(toTrack, function (track) {
events.on(track.event, function () {
analytics.track(_.extend(trackDefaults, {event: prefix + track.name}));
});
});
};

View File

@ -71,6 +71,11 @@ function init() {
// Setup our collection of express apps
parentApp = require('./app')();
// Initialise analytics events
if (config.get('segment:key')) {
require('./analytics-events').init();
}
debug('Express Apps done');
}).then(function () {
return auth.validation.validate({

View File

@ -28,6 +28,7 @@
},
"dependencies": {
"amperize": "0.3.4",
"analytics-node": "2.4.1",
"archiver": "1.3.0",
"bcryptjs": "2.4.3",
"bluebird": "3.5.0",

View File

@ -2,6 +2,13 @@
# yarn lockfile v1
"@segment/loosely-validate-event@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@segment/loosely-validate-event/-/loosely-validate-event-1.1.2.tgz#d77840999e3f7e43e74b3b0d43391c1526f793b8"
dependencies:
component-type "^1.2.1"
join-component "^1.1.0"
JSONSelect@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/JSONSelect/-/JSONSelect-0.4.0.tgz#a08edcc67eb3fcbe99ed630855344a0cf282bb8d"
@ -81,6 +88,20 @@ amperize@0.3.4:
rewire "^2.5.2"
uuid "^3.0.0"
analytics-node@2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/analytics-node/-/analytics-node-2.4.1.tgz#1f96c8eb887b6c47691044ac7fc9a1231fb020f7"
dependencies:
"@segment/loosely-validate-event" "^1.1.2"
clone "^2.1.1"
commander "^2.9.0"
crypto-token "^1.0.1"
debug "^2.6.2"
lodash "^4.17.4"
remove-trailing-slash "^0.1.0"
superagent "^3.5.0"
superagent-retry "^0.6.0"
ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@ -610,6 +631,10 @@ clone@^1.0.0, clone@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.2.tgz#260b7a99ebb1edfe247538175f783243cb19d149"
clone@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.1.tgz#d217d1e961118e3ac9a4b8bba3285553bf647cdb"
co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
@ -714,6 +739,10 @@ component-emitter@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
component-type@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-type/-/component-type-1.2.1.tgz#8a47901700238e4fc32269771230226f24b415a9"
compress-commons@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-1.2.0.tgz#58587092ef20d37cb58baf000112c9278ff73b9f"
@ -806,7 +835,7 @@ cookie@0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
cookiejar@^2.0.6:
cookiejar@^2.0.6, cookiejar@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.1.tgz#41ad57b1b555951ec171412a81942b1e8200d34a"
@ -853,6 +882,10 @@ cryptiles@2.x.x:
dependencies:
boom "2.x.x"
crypto-token@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/crypto-token/-/crypto-token-1.0.1.tgz#27c6482faf3b63c2f5da11577f8304346fe797a5"
css-color-names@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
@ -993,7 +1026,7 @@ debug@2.6.7:
dependencies:
ms "2.0.0"
debug@2.6.8, debug@2.x.x, debug@^2.1.3, debug@^2.2.0:
debug@2.6.8, debug@2.x.x, debug@^2.1.3, debug@^2.2.0, debug@^2.6.0, debug@^2.6.2:
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
@ -2610,6 +2643,10 @@ jodid25519@^1.0.0:
dependencies:
jsbn "~0.1.0"
join-component@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/join-component/-/join-component-1.1.0.tgz#b8417b750661a392bee2c2537c68b2a9d4977cd5"
js-base64@^2.1.9:
version "2.1.9"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.1.9.tgz#f0e80ae039a4bd654b5f281fc93f04a914a7fcce"
@ -3354,6 +3391,10 @@ mime@1.3.4, mime@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"
mime@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0"
mime@~1.2.11:
version "1.2.11"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10"
@ -4293,6 +4334,10 @@ qs@6.4.0, qs@^6.0.2, qs@^6.1.0, qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
qs@^6.4.0:
version "6.5.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.0.tgz#8d04954d364def3efc55b5a0793e1e2c8b1e6e49"
qs@~5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-5.1.0.tgz#4d932e5c7ea411cca76a312d39a606200fd50cd9"
@ -4473,6 +4518,10 @@ remove-trailing-separator@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.0.1.tgz#615ebb96af559552d4bf4057c8436d486ab63cc4"
remove-trailing-slash@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/remove-trailing-slash/-/remove-trailing-slash-0.1.0.tgz#1498e5df0984c27e49b76ebf06887ca2d01150d2"
repeat-element@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a"
@ -4997,6 +5046,10 @@ strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
superagent-retry@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/superagent-retry/-/superagent-retry-0.6.0.tgz#e49b35ca96c0e3b1d0e3f49605136df0e0a028b7"
superagent@3.5.2, superagent@^3.0.0:
version "3.5.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.5.2.tgz#3361a3971567504c351063abeaae0faa23dbf3f8"
@ -5012,6 +5065,21 @@ superagent@3.5.2, superagent@^3.0.0:
qs "^6.1.0"
readable-stream "^2.0.5"
superagent@^3.5.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.6.0.tgz#eb679651057c3462199c7b902b696c25350e1b87"
dependencies:
component-emitter "^1.2.0"
cookiejar "^2.1.0"
debug "^2.6.0"
extend "^3.0.0"
form-data "^2.1.1"
formidable "^1.1.1"
methods "^1.1.1"
mime "^1.3.6"
qs "^6.4.0"
readable-stream "^2.0.5"
supertest@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/supertest/-/supertest-3.0.0.tgz#8d4bb68fd1830ee07033b1c5a5a9a4021c965296"