From 0bb1153103d468f76c50c919017aee5090d31ac0 Mon Sep 17 00:00:00 2001 From: Jeff Morgan Date: Sat, 6 Dec 2014 14:41:59 -0500 Subject: [PATCH] Initial implementation of mixpanel instead of GA --- .gitignore | 9 ++- meteor/.jshintrc | 4 +- meteor/.meteor/packages | 1 - meteor/.meteor/versions | 1 - meteor/client/lib/imageutil.js | 2 +- meteor/client/lib/metrics.js | 37 ++++++++++++ meteor/client/lib/router.js | 15 +---- meteor/client/lib/startup.js | 7 +++ meteor/client/lib/util.js | 9 --- .../apps/dashboard-apps-settings.html | 10 ++-- .../views/dashboard/apps/dashboard-apps.html | 4 +- .../dashboard/apps/dashboard-single-app.html | 24 ++++---- .../dashboard/components/dashboard-menu.html | 6 +- .../components/modal-create-app.html | 2 +- .../components/modal-create-image.html | 4 +- .../images/dashboard-images-settings.html | 4 +- .../dashboard/images/dashboard-images.html | 4 +- .../images/dashboard-single-image.html | 12 ++-- .../layouts/dashboard-apps-layout.html | 21 +++---- .../layouts/dashboard-images-layout.html | 12 ++-- .../settings/dashboard-settings.html | 11 +--- .../dashboard/settings/dashboard-settings.js | 56 +++---------------- .../views/includes/update-notification.html | 2 +- meteor/settings_dev.json | 7 +-- package.json | 5 +- script/run.sh | 1 - script/setup.sh | 2 +- 27 files changed, 123 insertions(+), 149 deletions(-) create mode 100644 meteor/client/lib/metrics.js diff --git a/.gitignore b/.gitignore index 9640d95d..aed401fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .DS_Store -bundle -bundle.tar.gz .demeteorized dist node_modules @@ -9,14 +7,15 @@ cache bin # Resources -resources/cache -resources/base-images-*.tar.gz resources/virtualbox-*.pkg resources/boot2docker* -resources/node-webkit resources/mongod resources/MONGOD_LICENSE.txt resources/node resources/NODE_LICENSE.txt +resources/settings.json + +# Cache +cache script/sign.sh diff --git a/meteor/.jshintrc b/meteor/.jshintrc index 66bf659a..0cb05371 100755 --- a/meteor/.jshintrc +++ b/meteor/.jshintrc @@ -166,6 +166,7 @@ "VirtualBox": true, "ImageUtil": true, "AppUtil": true, + "Metrics": true // Forms "showFormErrors": true, @@ -173,8 +174,7 @@ "formValidate": true, "FormSchema": true, "showFormSuccess": true, - "resetForm": true, - "trackLink": true, + "resetForm": true // Testing "require": false, diff --git a/meteor/.meteor/packages b/meteor/.meteor/packages index 0eef044d..8b07153a 100755 --- a/meteor/.meteor/packages +++ b/meteor/.meteor/packages @@ -9,5 +9,4 @@ raix:handlebar-helpers mrt:underscore-string-latest dburles:collection-helpers iron:router -reywood:iron-router-ga simison:bootstrap3-less diff --git a/meteor/.meteor/versions b/meteor/.meteor/versions index c821689b..b3372a1f 100644 --- a/meteor/.meteor/versions +++ b/meteor/.meteor/versions @@ -49,7 +49,6 @@ reactive-dict@1.0.4 reactive-var@1.0.3 reload@1.1.1 retry@1.0.1 -reywood:iron-router-ga@0.4.1 routepolicy@1.0.2 session@1.0.4 simison:bootstrap3-less@0.3.0 diff --git a/meteor/client/lib/imageutil.js b/meteor/client/lib/imageutil.js index 24b9e62e..6f8e83fa 100644 --- a/meteor/client/lib/imageutil.js +++ b/meteor/client/lib/imageutil.js @@ -269,7 +269,7 @@ ImageUtil.sync = function (callback) { return _.contains(kitematicIds, image.Id); }); _.each(diffDockerImages, function (image) { - if (!image.RepoTags || _.isEmpty(image.Config.ExposedPorts)) { + if (!image.RepoTags || !image.Config || _.isEmpty(image.Config.ExposedPorts)) { return; } diff --git a/meteor/client/lib/metrics.js b/meteor/client/lib/metrics.js new file mode 100644 index 00000000..b161c59d --- /dev/null +++ b/meteor/client/lib/metrics.js @@ -0,0 +1,37 @@ +var remote = require('remote'); +var app = remote.require('app'); +var crypto = require('crypto'); +var getmac = require('getmac'); +var uuid = require('node-uuid'); + +var Mixpanel = require('mixpanel'); +var mixpanel = Mixpanel.init(Meteor.settings.public.mixpanel.token); + +Metrics = {}; + +Metrics.trackEvent = function (name) { + if (!name) { + return; + } + var uuid = localStorage.getItem('metrics.userId'); + if (localStorage.getItem('metrics.enabled') && uuid) { + mixpanel.track('docker_gui ' + name, { + distinct_id: uuid, + version: app.getVersion() + }); + } +}; + +Metrics.prepareTracking = function () { + if (localStorage.getItem('metrics.enabled') === null) { + var settings = Settings.findOne(); + if (settings && settings.tracking) { + localStorage.setItem('metrics.enabled', !!settings.tracking); + } else { + localStorage.setItem('metrics.enabled', true); + } + } + if (!localStorage.getItem('metrics.uuid')) { + localStorage.setItem('metrics.uuid', uuid.v4()); + } +}; diff --git a/meteor/client/lib/router.js b/meteor/client/lib/router.js index 47444c42..c7a277a6 100755 --- a/meteor/client/lib/router.js +++ b/meteor/client/lib/router.js @@ -1,13 +1,5 @@ Router.configure({ - layoutTemplate: 'layout', - onBeforeAction: function () { - var setting = Settings.findOne({}); - if (setting && setting.tracking) { - var currentPath = Router.current().path; - ga('send', 'pageview', currentPath); - } - this.next(); - } + layoutTemplate: 'layout' }); DashboardController = RouteController.extend({ @@ -44,11 +36,8 @@ Router.map(function () { if (err) { console.log('Setup failed.'); console.log(err); + Metrics.trackEvent('app setup failed'); } else { - var settings = Settings.findOne(); - if (!settings) { - Settings.insert({tracking: true}); - } startUpdatingBoot2DockerUtilization(); startSyncingAppState(); if (Apps.findOne()) { diff --git a/meteor/client/lib/startup.js b/meteor/client/lib/startup.js index c53faaee..6bd9ea31 100644 --- a/meteor/client/lib/startup.js +++ b/meteor/client/lib/startup.js @@ -18,6 +18,13 @@ Meteor.startup(function () { fs.mkdirSync(Util.getResourceDir()); } + Metrics.prepareTracking(); + Metrics.trackEvent('app started'); + Metrics.trackEvent('app heartbeat'); + Meteor.setInterval(function () { + Metrics.trackEvent('app heartbeat'); + }, 14400000); + Boot2Docker.ip(function (err, ip) { if (!err) { console.log('Setting host IP to: ' + ip); diff --git a/meteor/client/lib/util.js b/meteor/client/lib/util.js index a1edeb2b..9973e812 100755 --- a/meteor/client/lib/util.js +++ b/meteor/client/lib/util.js @@ -186,12 +186,3 @@ Util.compareVersions = function (v1, v2, options) { return 0; }; - -trackLink = function (trackLabel) { - var setting = Settings.findOne({}); - if (setting && setting.tracking) { - if (trackLabel) { - ga('send', 'event', 'link', 'click', trackLabel); - } - } -}; diff --git a/meteor/client/views/dashboard/apps/dashboard-apps-settings.html b/meteor/client/views/dashboard/apps/dashboard-apps-settings.html index ba356177..79de6305 100755 --- a/meteor/client/views/dashboard/apps/dashboard-apps-settings.html +++ b/meteor/client/views/dashboard/apps/dashboard-apps-settings.html @@ -29,7 +29,7 @@
{{name}}
{{value}}
- +
{{/each}} @@ -41,7 +41,7 @@ - + @@ -52,9 +52,9 @@
{{#if volumesEnabled}} - Disable Volumes + Disable Volumes {{else}} - Enable Volumes + Enable Volumes {{/if}}
@@ -64,7 +64,7 @@

Delete this container permanently.

- Delete Container + Delete Container
diff --git a/meteor/client/views/dashboard/apps/dashboard-apps.html b/meteor/client/views/dashboard/apps/dashboard-apps.html index 7c02610c..5c627058 100755 --- a/meteor/client/views/dashboard/apps/dashboard-apps.html +++ b/meteor/client/views/dashboard/apps/dashboard-apps.html @@ -5,7 +5,7 @@ {{#if $.Session.equals 'boot2dockerState' 'poweroff'}} Create Container {{else}} - Create Container + Create Container {{/if}} @@ -24,7 +24,7 @@ {{#if $.Session.equals 'boot2dockerState' 'poweroff'}} Create Container {{else}} - Create Container + Create Container {{/if}} {{/if}} diff --git a/meteor/client/views/dashboard/apps/dashboard-single-app.html b/meteor/client/views/dashboard/apps/dashboard-single-app.html index bf3a3756..08a1d7e4 100755 --- a/meteor/client/views/dashboard/apps/dashboard-single-app.html +++ b/meteor/client/views/dashboard/apps/dashboard-single-app.html @@ -18,18 +18,18 @@ {{/if}} {{/if}} {{/if}} - {{name}} - {{displayTags image.tags}} + {{name}} + {{displayTags image.tags}}
{{#if $eq status 'READY'}} {{#if ports}} {{#if viewPort}}
- + - + Toggle Dropdown @@ -40,7 +40,7 @@ {{else}}
diff --git a/meteor/client/views/dashboard/components/dashboard-menu.html b/meteor/client/views/dashboard/components/dashboard-menu.html index ae4bbe3c..bc989dae 100755 --- a/meteor/client/views/dashboard/components/dashboard-menu.html +++ b/meteor/client/views/dashboard/components/dashboard-menu.html @@ -6,10 +6,10 @@