Permalink
Browse files

added optional analytics support

  • Loading branch information...
1 parent 59bfd00 commit 38ef64ab6b58ff8e468c75225d54bf453d43a5c8 Jen Fong-Adwent committed Oct 27, 2012
Showing with 25 additions and 6 deletions.
  1. +1 −1 app.js
  2. +3 −1 local.json-dist
  3. +19 −4 routes/index.js
  4. +2 −0 views/layout.jade
View
2 app.js
@@ -54,7 +54,7 @@ var isLoggedIn = function(req, res, next) {
/* Routing setup */
-require('./routes')(app, client, isLoggedIn, noodle);
+require('./routes')(app, client, isLoggedIn, noodle, nconf);
require('./routes/auth')(app, passport);
app.get('/404', function(req, res, next){
View
4 local.json-dist
@@ -9,5 +9,7 @@
"appnet_consumer_secret": "appnet_secret",
"redis_dev": 0,
"redis_test": 8,
- "redis_prod": 9
+ "redis_prod": 9,
+ "analytics": "analytics_id",
+ "imgur_key": "img_api_key"
}
View
23 routes/index.js
@@ -1,6 +1,6 @@
'use strict';
-module.exports = function(app, client, isLoggedIn, noodle) {
+module.exports = function(app, client, isLoggedIn, noodle, config) {
var appnet = require('../lib/appnet');
var webremix = require('../lib/web-remix');
var utils = require('../lib/utils');
@@ -12,6 +12,8 @@ module.exports = function(app, client, isLoggedIn, noodle) {
app.get('/', function(req, res) {
res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
+ var analytics = false;
+
if (req.session.passport.user) {
// Process all the users's top 300 followed
req.body.count = FOLLOWING_MAX;
@@ -41,6 +43,10 @@ module.exports = function(app, client, isLoggedIn, noodle) {
charLimit = 256;
}
+ if (config.get('analytics')) {
+ analytics = config.get('analytics');
+ }
+
req.session.url = '/my/feed';
res.render('index', {
pageType: 'index',
@@ -51,7 +57,8 @@ module.exports = function(app, client, isLoggedIn, noodle) {
username: utils.getUser(req).username,
mediaOn: mediaOn,
charLimit: charLimit,
- loggedUsername: utils.getUser(req).username
+ loggedUsername: utils.getUser(req).username,
+ analytics: analytics
});
}
});
@@ -64,12 +71,15 @@ module.exports = function(app, client, isLoggedIn, noodle) {
username: '',
mediaOn: '',
charLimit: charLimit,
- loggedUsername: ''
+ loggedUsername: '',
+ analytics: analytics
});
}
});
app.get('/user/:username', isLoggedIn, function(req, res) {
+ var analytics = false;
+
appnet.getUser(req, function(err, user) {
if (err) {
res.status(500);
@@ -106,6 +116,10 @@ module.exports = function(app, client, isLoggedIn, noodle) {
}
}
+ if (config.get('analytics')) {
+ analytics = config.get('analytics');
+ }
+
req.session.url = '/user/posts/' + user.id;
res.render('profile', {
@@ -119,7 +133,8 @@ module.exports = function(app, client, isLoggedIn, noodle) {
loggedInId: utils.getUserById(req),
mediaOn: mediaOn,
charLimit: charLimit,
- loggedUsername: utils.getUser(req).username
+ loggedUsername: utils.getUser(req).username,
+ analytics: analytics
});
});
}
View
2 views/layout.jade
@@ -22,6 +22,8 @@ html
link(rel='apple-touch-icon', sizes='114x114', href='/images/logo-114.png')
link(rel='apple-touch-icon', sizes='128x128', href='/images/logo-128.png')
link(rel='stylesheet', href='/stylesheets/main.css')
+ if analytics
+ != '<script type="text/javascript">var _gaq = _gaq || []; _gaq.push(["_setAccount", "' + analytics + '"]); _gaq.push(["_trackPageview"]); (function() { var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true; ga.src = "http://www.google-analytics.com/ga.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s); })();</script>'
body(data-url='#{url}', data-username='#{loggedUsername}', data-sessionid='#{loggedInId}', class='#{mediaOn}', data-charlimit='#{charLimit}')
#hush

0 comments on commit 38ef64a

Please sign in to comment.