Skip to content

Commit

Permalink
[Desktop] Add Mixpanel analytics to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGaubert committed Jun 29, 2016
1 parent 6d91c67 commit f49acff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
17 changes: 16 additions & 1 deletion desktop/app/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var log = require('electron').remote.require('electron-log')
var log = require('electron').remote.require('./res/js/console').setup()
var mixpanel = require('electron').remote.require('mixpanel').init('6cae86bf1da092b800b30b27689bd665')

setupMenu()

Expand All @@ -7,6 +8,9 @@ var shell = require('electron').shell
$(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault()
shell.openExternal(this.href)
mixpanel.track('link-clicked', {
link: this.href
})
})

$('.dev-tools').hide()
Expand All @@ -20,14 +24,17 @@ requestServerVersion()

$('#btnDevTools').click(function() {
require('electron').remote.getCurrentWindow().toggleDevTools()
mixpanel.track('dev-toggle-dev-tools')
})

$('#btnExNotif').click(function() {
socket.emit('notification', JSON.stringify(getTestNotification()))
mixpanel.track('dev-test-notification')
})

$('#btnVersion').click(function() {
requestServerVersion()
mixpanel.track('dev-version')
})

socket.on('broadcast', function(msg) {
Expand Down Expand Up @@ -76,6 +83,7 @@ socket.on('updates', function(msg) {
$.snackbar({content: 'Update downloaded, restart to apply. <a href="#" class="snackbar-link" id="changelog-link">Changelog</a>', timeout: 0, htmlAllowed: true})
$('#changelog-link').click(function() {
$('#changelog').html(result)
mixpanel.track('view-changelog')
})
} else if(u.metadata.type == 'update-checking') {
$.snackbar({content: 'Checking for updates...'})
Expand All @@ -95,6 +103,7 @@ socket.on(clientId, function(msg) {
handleNotificationResponse(msg)
} else {
log.info('Unknown private message: ' + m)
mixpanel.track('unknown-private-message', m.metadata)
}
})

Expand Down Expand Up @@ -143,15 +152,18 @@ function verifyVersion(msg) {
log.info('Connected to ' + v.payload.name + ' ' + v.payload.version + ' (' + v.payload.versionCode + ')')
$.snackbar({content: 'Connected to server.'})
$('#status').text('Connected to ' + v.payload.name + ' ' + v.payload.version)
mixpanel.track('connect-success', v.payload)
} else {
log.info('Server is running incompatible version!')
$.snackbar({content: 'Unable to connect: Server is running incompatible version.', timeout: 0})
$('#status').text('Unable to connect: Server is running incompatible version')
mixpanel.track('connect-server-incompatible', v.payload)
}
} else {
log.info('Invalid payload version!')
$.snackbar({content: 'Unable to connect: Invalid payload version.', timeout: 0})
$('#status').text('Unable to connect: Invalid payload version')
mixpanel.track('connect-invalid-version', v.metadata)
}
}

Expand All @@ -161,12 +173,15 @@ function handleNotificationResponse(msg) {
if(r.payload.result) {
log.info('Notification ' + r.payload.id + ' successfully displayed. (' + r.payload.resultCode + ' : ' + r.payload.resultMessage + ')')
$.snackbar({content: 'Notification successfully displayed.'})
mixpanel.track('notification-success', r.payload)
} else {
log.info('Notification ' + r.payload.id + ' failed to display. (' + r.payload.resultCode + ' : ' + r.payload.resultMessage + ')')
$.snackbar({content: 'Failed to display notification. (' + r.payload.resultCode +')'})
mixpanel.track('notification-failed', r.payload)
}
} else {
log.info('Invalid payload version!')
$.snackbar({content: 'Notification response: Invalid payload version.'})
mixpanel.track('notification-invalid-version', r.metadata)
}
}
9 changes: 9 additions & 0 deletions desktop/app/res/js/reveal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var mixpanel = require('electron').remote.require('mixpanel').init('6cae86bf1da092b800b30b27689bd665')

var os = require('os');
if (os.platform() != 'win32') {
$('#reveal-check-for-updates').hide()
mixpanel.track('hide-check-for-updates', {
platform: os.platform()
})
}

$('.app-version').text(require('electron').remote.app.getVersion)
Expand Down Expand Up @@ -61,6 +66,7 @@ function toggleReveal() {
$("body").css("background-color", "#0D253A")
}
}, 250)
mixpanel.track('toggle-reveal')
}
}

Expand All @@ -70,6 +76,7 @@ document.getElementById('reveal-open-dev-tools').addEventListener('click', funct
function() {
$(".dev-tools").toggle()
}, 250)
mixpanel.track('reveal-open-dev-tools')
})

document.getElementById('reveal-check-for-updates').addEventListener('click', function() {
Expand All @@ -78,8 +85,10 @@ document.getElementById('reveal-check-for-updates').addEventListener('click', fu
function() {
require('electron').remote.autoUpdater.checkForUpdates()
}, 250)
mixpanel.track('reveal-check-for-updates')
})

document.getElementById('reveal-close').addEventListener('click', function() {
toggleReveal()
mixpanel.track('reveal-close')
})
4 changes: 4 additions & 0 deletions desktop/app/res/js/toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var mixpanel = require('electron').remote.require('mixpanel').init('6cae86bf1da092b800b30b27689bd665')

$('#minimize').click(function() {
mixpanel.track('toolbar-minimize')
require('electron').remote.getCurrentWindow().minimize()
})

$('#close').click(function() {
mixpanel.track('toolbar-close')
require('electron').remote.getCurrentWindow().close()
})

0 comments on commit f49acff

Please sign in to comment.