Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
Update Google Analytics snippet to use Universal Analytics (analytics…
Browse files Browse the repository at this point in the history
….js) instead of ga.js. Closes #32.
  • Loading branch information
smockle committed Sep 18, 2013
1 parent f7214f5 commit 19f975c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
8 changes: 1 addition & 7 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
// Using the Garber-Irish method:
// http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution

var SMOCKLE = $.extend(typeof SMOCKLE === "undefined" ? {} : SMOCKLE, {
// common: {
// init: function () {
// "use strict";
// }
// }
});
var SMOCKLE = $.extend(typeof SMOCKLE === "undefined" ? {} : SMOCKLE, {});

var UTIL = {
exec: function (controller, action) {
Expand Down
17 changes: 17 additions & 0 deletions app/assets/javascripts/ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*jslint browser: true */
/*global $: true */

var SMOCKLE = $.extend(typeof SMOCKLE === "undefined" ? {} : SMOCKLE, {
common: {
init: function () {
"use strict";

var body = document.body,
environment = body.getAttribute("data-env");

if (environment === "production") {
(function(G,o,O,g,l){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;g=o.createElement('script'),l=o.scripts[0];g.src='//www.google-analytics.com/analytics.js';l.parentNode.insertBefore(g,l)}(this,document,'ga'));ga('create','UA-37140610-3');ga('send','pageview')
}
}
}
});
16 changes: 3 additions & 13 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- Size should be 32 x 32 pixels -->
<%= favicon_link_tag "favicon.ico" %>
</head>
<body data-controller="<%= controller_name %>" data-action="<%= action_name %>">
<body data-controller="<%= controller_name %>" data-action="<%= action_name %>" data-env="<%= Rails.env %>">
<header>
<a class="site-logo" href="/"><h1>Smockle.</h1></a>
<nav>
Expand All @@ -47,17 +47,7 @@
<%= yield %>

<footer>
<p>Copyright &copy; <%= Time.now.year %> Clay Miller. All rights reserved.</p>
</footer>

<% if Rails.env.production? %>
<!-- Google Analytics. -->
<script>
var _gaq=[['_setAccount','UA-37140610-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src='//www.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<% end %>
<p>Copyright &copy; <%= Time.now.year %> Clay Miller. All rights reserved.</p>
</footer>
</body>
</html>

0 comments on commit 19f975c

Please sign in to comment.