Permalink
Browse files

Add analytics view and helper method

  • Loading branch information...
1 parent 834c2ab commit b0057de22f6428f2890a53b6c633896dff8666c3 @aron aron committed Apr 24, 2012
Showing with 26 additions and 20 deletions.
  1. +13 −6 lib/handlers.js
  2. +11 −0 views/analytics.html
  3. +2 −14 views/index.html
View
@@ -129,12 +129,16 @@ module.exports = function (app) {
var template = handlers.templateFromBin(bin),
jsbin = handlers.jsbin(bin);
- res.render('index', {
- tips: '{}',
- revision: bin.revision || 1,
- jsbin: JSON.stringify(jsbin),
- json_template: JSON.stringify(template),
- version: jsbin.version
+ handlers.analytics(app.set('analytics id'), function (err, analytics) {
+ res.render('index', {
+ tips: '{}',
+ revision: bin.revision || 1,
+ jsbin: JSON.stringify(jsbin),
+ json_template: JSON.stringify(template),
+ version: jsbin.version,
+ analytics: analytics,
+ 'production?': app.production
+ });
});
},
renderFiles: function (req, res, files) {
@@ -196,6 +200,9 @@ module.exports = function (app) {
return 'default.' + ext;
});
},
+ analytics: function (id, fn) {
+ app.render('analytics', {id: id}, fn);
+ },
formatPreview: function (bin, options, fn) {
var formatted = bin.html || '',
insert = [], parts, last, context;
View
@@ -0,0 +1,11 @@
+<script>
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', '{{id}}']);
+_gaq.push(['_trackPageview']);
+
+(function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
+})();
+</script>
View
@@ -206,20 +206,8 @@
var jsbin = {{{jsbin}}}; tips = {{tips}};
</script>
<script src="{{root}}js/{{version}}/jsbin.js"></script>
-{{#production?}}{{#analytics_id}}
-<script>
-var _gaq = _gaq || [];
-_gaq.push(['_setAccount', '{{analytics_id}}']);
-_gaq.push(['_trackPageview']);
-
-(function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
-})();
-</script>
-{{/analytics_id}}{{/production?}}
-{{{ list_history }}}
+{{#production?}}{{{analytics}}}{{/production?}}
+{{{list_history}}}
<div id="urlHelp" class="modal">
<p>Where the url may be http://jsbin.com/abc the following url fragments can be added to the url to view it differently.</p>
<h2>JS Bin URLs</h2>

0 comments on commit b0057de

Please sign in to comment.