2017-12-07 13:04:16 +00:00
|
|
|
const Insight = require('insight')
|
|
|
|
const path = require('path')
|
|
|
|
const pkg = require(path.join(__dirname, '..', 'package.json'))
|
|
|
|
|
|
|
|
// Google Analytics tracking code
|
|
|
|
const TRACKING_CODE = 'UA-110087713-3'
|
|
|
|
|
|
|
|
class Analytics {
|
2018-12-11 22:11:03 +00:00
|
|
|
constructor ({ enabled }) {
|
2017-12-07 13:04:16 +00:00
|
|
|
this.enabled = enabled
|
|
|
|
this.insight = new Insight({ trackingCode: TRACKING_CODE, pkg })
|
|
|
|
this.insight.optOut = !enabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// report that the gallery has started building
|
|
|
|
start (done) {
|
|
|
|
this.insight.track('start')
|
|
|
|
}
|
|
|
|
|
|
|
|
// report that the gallery has finished building + some stats
|
|
|
|
finish (stats, done) {
|
|
|
|
this.insight.track('finish')
|
|
|
|
this.insight.trackEvent({ category: 'gallery', action: 'albums', label: 'Album count', value: stats.albums })
|
|
|
|
this.insight.trackEvent({ category: 'gallery', action: 'photos', label: 'Photo count', value: stats.photos })
|
|
|
|
this.insight.trackEvent({ category: 'gallery', action: 'videos', label: 'Video count', value: stats.videos })
|
|
|
|
}
|
|
|
|
|
|
|
|
// report that an error happened
|
|
|
|
// but don't report the contents (might contain file paths etc)
|
|
|
|
error (done) {
|
|
|
|
this.insight.track('error')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Analytics
|