Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import ua from 'universal-analytics';
import uuid from 'uuid/v4';
const { ipcRenderer, remote } = require('electron');
const { app } = remote;
const appVersion = app.getVersion();
const appName = app.getName();
const log = require('electron-log');
const ua_ID = 'UA-104941988-1';
// get this from saved data or create if it doesn't exist and save it.
let userUuid = ipcRenderer.sendSync('getFromStore', 'uuid');
if (userUuid.length < 10) {
userUuid = uuid();
ipcRenderer.sendSync('setToStore', 'uuid', userUuid);
}
const visitor = ua(ua_ID, userUuid);
function errorHandler(err) {
if (err) {
log.error(`Error with google analytics: ${err}`);
}
}
// support disabling analytics
export const screenview = screenName => {
if (ipcRenderer.sendSync('getFromStore', 'gaEnabled')) {
visitor.screenview(screenName, appName, appVersion, errorHandler).send();
}
};
export const event = (...args) => {
if (ipcRenderer.sendSync('getFromStore', 'gaEnabled')) {
import os from 'os'
import ua from 'universal-analytics'
import uuidv4 from 'uuid/v4'
import Settings from './Settings'
import packageInfo from '../../package.json'
// Init
let visitor
try {
visitor = ua('UA-114351855-1', getClientId())
visitor.set('anonymizeIp', 1)
visitor.set('clientId', getClientId())
visitor.set('dataSource', 'app')
visitor.set('applicationName', 'Pullover')
visitor.set('applicationVersion', packageInfo.version)
visitor.set('applicationInstallerId', getPlatform())
visitor.set('userAgentOverride', window.navigator.userAgent)
if (window.firstRun) {
visitor.event('App', 'Install')
}
if (window.updateRun) {
event('App', 'Updated', packageInfo.version)
}
} catch (e) {
const visitor = () => {
if (visitorCache) {
return visitorCache
}
if (isTrackingEnabled()) {
try {
visitorCache = ua('UA-87361302-1', machineIdSync(), { strictCidFormat: false })
} catch (err) {
console.log('[machine-id error]', err)
visitorCache = ua('UA-87361302-1')
}
}
return visitorCache
}
export const metrics = () => {
const token = typeof config.token === 'string' ? config.token : platform() + release();
const salt = userInfo().username;
const hash = crypto.pbkdf2Sync(token, salt, 1000, 64, 'sha512').toString('hex').substring(0, 24);
return ua(GA_TRACKING_ID, {
cid: hash,
strictCidFormat: false,
uid: hash,
headers: {
'User-Agent': userAgent
}
});
}
constructor() {
super();
this.state = {
loading: true
};
const visitor = ua('UA-80488337-3');
visitor.pageview('/').send();
}
export default getUA => {
if (!a) {
a = ua(CONFIG.GOOGLE_GA);
}
return a
}
async function getAnalyticsVisitor() {
const clientId = await getClientId();
const visitor = analytics(analyticsTrackingId, clientId);
reportData.clientId = clientId;
const { email } = await getValue('developer') || {};
if (email) {
visitor.set('userId', email);
reportData.userId = email;
}
visitor.set('isDeveloper', true);
reportData.isDeveloper = true;
return visitor;
}
public use(req: Request, res: Response, next: NextFunction) {
const { headers, path } = req;
logger.info(`Analytics pageview on ${path}`);
if (env.ANALYTICS) {
const visitor: Visitor = ua(env.ANALYTICS);
const options: PageviewParams = {
dp: path,
dh: headers.host,
uip: headers['x-forwarded-for'] || headers['x-real-ip'],
ua: headers['user-agent'],
};
logger.info(`Analytics pageview on ${path}`);
visitor.pageview(options).send(() => next());
}
next();
}
}
try {
pkg = fs.readJsonSync(join(pluginInstance.prefix, 'package.json'));
} catch (err) {
_.noop();
}
}
const str =
pkg.author ||
_.get(pkg, 'repository.url') ||
pkg.name ||
pkg.homepage ||
uuid.v4();
const userId = createHash('md5')
.update(str)
.digest('hex');
const visitor = ua('UA-73165042-2', userId, {
strictCidFormat: false,
https: true
});
return visitor;
}