mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
7 years ago
|
const _ = require('lodash')
|
||
7 years ago
|
const axios = require('axios')
|
||
|
const bugsnag = require('bugsnag')
|
||
|
const path = require('path')
|
||
|
const uuid = require('uuid/v4')
|
||
|
|
||
|
/* global wiki */
|
||
|
|
||
|
module.exports = {
|
||
|
cid: '',
|
||
|
enabled: false,
|
||
|
init() {
|
||
|
this.cid = uuid()
|
||
|
bugsnag.register(wiki.data.telemetry.BUGSNAG_ID, {
|
||
|
appVersion: wiki.version,
|
||
|
autoNotify: false,
|
||
|
hostname: this.cid,
|
||
|
notifyReleaseStages: ['production'],
|
||
|
packageJSON: path.join(wiki.ROOTPATH, 'package.json'),
|
||
|
projectRoot: wiki.ROOTPATH,
|
||
|
useSSL: true
|
||
|
})
|
||
|
bugsnag.onBeforeNotify((notification, originalError) => {
|
||
|
if (!this.enabled) { return false }
|
||
|
})
|
||
|
|
||
|
if (_.get(wiki.config, 'logging.telemetry', false) === true) {
|
||
|
this.enabled = true
|
||
|
}
|
||
|
|
||
|
return this
|
||
|
},
|
||
|
sendError(err) {
|
||
7 years ago
|
bugsnag.notify(err, { userId: this.cid })
|
||
7 years ago
|
},
|
||
|
sendEvent(eventCategory, eventAction, eventLabel) {
|
||
|
if (!this.enabled) { return false }
|
||
|
axios({
|
||
|
method: 'post',
|
||
|
url: wiki.data.telemetry.GA_REMOTE,
|
||
|
headers: {
|
||
|
'Content-type': 'application/x-www-form-urlencoded'
|
||
|
},
|
||
|
params: {
|
||
|
v: 1, // API version
|
||
|
tid: wiki.data.telemetry.GA_ID, // Tracking ID
|
||
|
aip: 1, // Anonymize IP
|
||
|
ds: 'server', // Data source
|
||
|
cid: this.cid, // Client ID
|
||
|
t: 'event', // Hit Type
|
||
|
ec: eventCategory, // Event Category
|
||
|
ea: eventAction, // Event Action
|
||
|
el: eventLabel // Event Label
|
||
|
}
|
||
|
}).then(resp => {
|
||
|
if (resp.status !== 200) {
|
||
|
wiki.logger.warn('Unable to send analytics telemetry request.')
|
||
|
}
|
||
|
}, err => {
|
||
|
wiki.logger.warn('Unable to send analytics telemetry request.')
|
||
|
})
|
||
|
}
|
||
|
}
|