How to use universal-analytics with express
2 years ago
Just place this inside the app.js
Before you call the routes middleware
var ua = require('universal-analytics');
app.use(function(req,res,next){
ua('GoogleAnaliticsUsedIdGoesHere').pageview({
dp: req.url,
dh: req.headers.host,
uip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
ua: req.headers['user-agent'],
dr: req.headers.referrer || req.headers.referer,
de: req.headers['accept-encoding'],
ul: req.headers['accept-language']
}).send();
next();
});