diaspora/app/helpers/analytics_helper.rb
danielgrippi fe49579ff5 remove google-analytics middleware due to the fact that it doesn't support injection of custom variables before _trackPageView is called (this results in custom vars not getting tracked)
i've submitted an issue to the gem.  hopefully we can put it back in later… for now i've copy and pasted its output into a helper method.
2012-05-01 18:02:25 -07:00

33 lines
No EOL
1.1 KiB
Ruby

# Copyright (c) 2010-2012, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
module AnalyticsHelper
def include_google_analytics
return unless google_configured?
segment = current_user ? current_user.role_name : "unauthenticated"
javascript_tag do
<<-JS
var _gaq = _gaq || [];
_gaq.push(['_setAccount', "#{AppConfig[:google_a_site]}"]);
_gaq.push(['_setCustomVar', 1, 'Role', '#{segment}']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
(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';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
JS
end
end
private
def google_configured?
AppConfig[:google_a_site].present? && AppConfig[:google_a_site].present?
end
end