Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.enable('trust proxy')
if (process.env.MATOMO_URL) {
console.log('Matomo Analytics activated');
app.use(matomo({
siteId: process.env.MATOMO_SITE,
matomoUrl: process.env.MATOMO_URL,
matomoToken: process.env.MATOMO_TOKEN
}));
}
app.use(ua.middleware("UA-115902726-4", { cookieName: '_ga' }));
app.use(function (req, res, next) {
if (!req.headers['x-forwarded-for']) {
req.headers['x-forwarded-for'] = '0.0.0.0';
}
req.visitor.pageview({
dp: req.originalUrl,
dr: req.get('Referer'),
ua: req.headers['user-agent'],
uip: req.connection.remoteAddress
|| req.socket.remoteAddress
|| req.connection.remoteAddress
|| req.headers['x-forwarded-for'].split(',').pop()
}).send()
next();
});
app.use(favicon(path.join(__dirname, 'public/gi/img/favicon.ico'), { maxAge: oneDay }));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride());
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
}
// Route endpoints
routes(app);
// all environments
app.use(ua.middleware(process.env.GA_TRACKING_ID, {cookieName: '_ga'}));
app.use(express.static(path.join(__dirname, 'public'), { maxAge: oneDay }));
app.use(require('uglify-js-middleware')({ src: path.join(__dirname,'public') }));
app.use(require('less-middleware')(path.join(__dirname,'public'), [], [], [{compress: true}]));
// Start server
app.listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
expect.toBeTrue(Analytics.IdFormat.test(userId));
const trackingId: string = (config as any).analytics.trackingId;
log.info('Analytics', 'tracking id', trackingId.slice(0, 7) + '*******');
log.info('Analytics', 'client id', clientId);
log.info('Analytics', 'user id', userId);
const options: ua.VisitorOptions = {
tid: trackingId,
cid: clientId,
uid: userId,
https: true,
};
this.visitor = new ua.Visitor(options);
// Register for messages sent from the renderer
ipcMain.on(
AnalyticsChannelName.ReportEventWithValue,
(event: any, arg: ValueEvent) => this.reportEventWithValue(arg.category, arg.action, arg.label, arg.value));
ipcMain.on(
AnalyticsChannelName.ReportPageView,
(event: any, arg: PageViewEvent) => this.reportPageView(arg.path));
ipcMain.on(
AnalyticsChannelName.ReportException,
(event: any, arg: ExceptionEvent) => this.reportException(arg.description));
}
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) {
async function start() {
const app = express();
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
app.use(cookieParser());
// Setup Google Analytics
app.use(universalAnalytics.middleware(process.env.GA_ID, {cookieName: '_ga'}));
app.use(bodyParser());
app.use(logReqPerf);
const server = http.Server(app);
const io = require('socket.io')(server);
app.set('socketio', io);
// Init Nuxt.js
const nuxt = new Nuxt(config)
const {host, port} = nuxt.options.server
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
const ga = (req, res, next) => {
// We generate a session to be able to keep track of requests coming from the same visitor
const session = expressSession({
httpOnly: true,
secret: 'b4;jP(cUqPaf8TuG@U',
cookie: {
secure: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging',
maxAge: 60*60*24*30*1000 // 1 month
}
});
const mw = ua.middleware(config.GoogleAnalytics.account, {cookieName: '_ga'});
session(req, res, () => {
mw(req, res, next);
req.ga = {
pageview: () => req.visitor.pageview(req.url).send(),
event: (EventCategory, EventName, EventLabel, EventValue) => req.visitor.event(EventCategory, EventName, EventLabel, EventValue, {p: req.url}).send()
}
});
};
return new Promise(resolve => {
// check if the user has opted in to tracking
if (optIn()) {
const params = {
ec: fcVersion + ' - ' + category,
ea: getOS(),
el: message,
};
const analytics: Visitor = new Visitor(GA_TRACKING_ID, vscode.window.forceCode.uuid);
analytics
.event(params, response => {
if (!response) {
// according to universal-analytics, no response from the callback is a success
resolve(true);
}
resolve(false);
})
.send();
} else {
resolve(false);
}
});
}
visitor.item(449.99, 1, 'ID54321', 'T-Shirt', 'Blue', { ti: '123456' }).send();
visitor.pageview('/').send();
visitor.pageview('/').pageview('/contact').send();
visitor.pageview('/landing-page-1').event('Testing', 'Button color', 'Blue').send();
visitor.pageview('/landing-page-1').send();
visitor.event('Testing', 'Button color', 'Blue', 42, { p: '/landing-page-1' }).send();
visitor
.event({ ec: 'Mail Server', ea: 'New Team Member Notification sent' })
.event({ ea: 'Invitation sent' })
.send();
visitor.set('uid', '123456789');
app.use(ua.middleware('UA-XXXX-Y', { cookieName: '_ga' }));
ua.createFromSession({ cid: 'some-string' });
ua('UA-XXXX-XX').debug();
ua('UA-XXXX-XX', {
requestOptions: {
proxy: '…',
},
});
visitor.pageview('/').send();
visitor.pageview('/').pageview('/contact').send();
visitor.pageview('/landing-page-1').event('Testing', 'Button color', 'Blue').send();
visitor.pageview('/landing-page-1').send();
visitor.event('Testing', 'Button color', 'Blue', 42, { p: '/landing-page-1' }).send();
visitor
.event({ ec: 'Mail Server', ea: 'New Team Member Notification sent' })
.event({ ea: 'Invitation sent' })
.send();
visitor.set('uid', '123456789');
app.use(ua.middleware('UA-XXXX-Y', { cookieName: '_ga' }));
ua.createFromSession({ cid: 'some-string' });
ua('UA-XXXX-XX').debug();
ua('UA-XXXX-XX', {
requestOptions: {
proxy: '…',
},
});