Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved google analytics module

* fixed coding guideline issues
* added page speed tracking
* added possibillity to anonymize ips
  • Loading branch information...
commit cea3acd867d69cdad9b129c81f9803aab6625e1b 1 parent cbb0695
@php-workx php-workx authored
View
6 conf/development.js
@@ -9,6 +9,8 @@ module.exports = function(app,express) {
// Change to suit - this key works for calip.so
app.set('google-analytics-key', 'UA-17607570-4');
+ app.set('google-analytics-anonymize-ip', true);
+ app.set('google-analytics-track-pagespeed', true);
// Disqus
app.set('disqus-shortname', 'calipsojs');
@@ -19,7 +21,5 @@ module.exports = function(app,express) {
// Language mode
app.set('language-add', true);
-
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
-
-}
+}
View
5 conf/production.js
@@ -9,6 +9,8 @@ module.exports = function(app,express) {
// Change to suit - this key works for calip.so
app.set('google-analytics-key', 'UA-17607570-4');
+ app.set('google-analytics-anonymize-ip', false);
+ app.set('google-analytics-track-pagespeed', false);
// Disqus
app.set('disqus-shortname', 'calipsojs');
@@ -20,5 +22,4 @@ module.exports = function(app,express) {
app.set('language-add', false);
app.use(express.errorHandler({ dumpExceptions: true, showStack: false }));
-
-}
+}
View
7 conf/test.js
@@ -9,6 +9,8 @@ module.exports = function(app,express) {
// Change to suit - this key works for calip.so
app.set('google-analytics-key', 'UA-17607570-4');
+ app.set('google-analytics-anonymize-ip', false);
+ app.set('google-analytics-track-pagespeed', false);
// Disqus
app.set('disqus-shortname', 'calipsojs');
@@ -16,9 +18,8 @@ module.exports = function(app,express) {
// App config
app.set('server-url', 'http://localhost:3000');
-// Language mode
+ // Language mode
app.set('language-add', false);
app.use(express.errorHandler({ dumpExceptions: false, showStack: false }));
-
-}
+}
View
48 modules/community/google-analytics/google-analytics.js
@@ -16,11 +16,10 @@ exports = module.exports = {
*Router
*/
function route(req, res, module, app, next) {
-
+
// Router
module.router.route(req, res, next);
-
-};
+}
/**
*Init
@@ -30,23 +29,20 @@ function init(module, app, next) {
// Any pre-route config
calipso.lib.step(
- function defineRoutes() {
-
- // Tracking code is added to every page
- module.router.addRoute(/.*/, ga, {
- end: false,
- template: 'ga',
- block: 'scripts.ga'
- }, this.parallel());
-
- }, function done() {
-
- // No initialisation?
- next();
-
- });
-
-};
+ function defineRoutes() {
+ // Tracking code is added to every page
+ module.router.addRoute(/.*/, ga, {
+ end: false,
+ template: 'ga',
+ block: 'scripts.ga'
+ }, this.parallel());
+ },
+ function done() {
+ // No initialisation?
+ next();
+ }
+ );
+}
/**
* Render the ga code, extracting the key from app config
@@ -54,9 +50,11 @@ function init(module, app, next) {
function ga(req, res, template, block, next) {
var key = req.app.set('google-analytics-key');
+ var anonymizeIP = req.app.set('google-analytics-anonymize-ip');
+ var trackPageSpeed = req.app.set('google-analytics-track-pagespeed');
calipso.theme.renderItem(req, res, template, block, {
- key: key
- },next);
-
-
-};
+ key: key,
+ anonymizeIP: anonymizeIP,
+ trackPageSpeed: trackPageSpeed
+ }, next);
+}
View
4 modules/community/google-analytics/templates/ga.html
@@ -1,9 +1,11 @@
<% if(key) { %>
- <script type="text/javascript">
+<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%- key %>']);
+ <% if(anonymizeIP) { %>_gaq.push(["_gat._anonymizeIp"]); <% } %>
_gaq.push(['_trackPageview']);
+ <% if(trackPageSpeed) { %>_gaq.push(['_trackPageLoadTime']); <% } %>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
Please sign in to comment.
Something went wrong with that request. Please try again.