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.
This commit is contained in:
danielgrippi 2012-05-01 18:01:50 -07:00
parent b3e3f98145
commit fe49579ff5
7 changed files with 35 additions and 16 deletions

View file

@ -37,7 +37,6 @@ gem "rpm_contrib", "~> 2.1.7"
group :production do # we don't install these on travis to speed up test runs
gem 'rack-ssl', :require => 'rack/ssl'
gem 'rack-rewrite', '~> 1.2.1', :require => false
gem 'rack-google-analytics', :require => 'rack/google-analytics'
gem 'rack-piwik', :require => 'rack/piwik'
end

View file

@ -321,7 +321,6 @@ GEM
rack-cors (0.2.4)
rack
rack-fiber_pool (0.9.2)
rack-google-analytics (0.10.0)
rack-mobile-detect (0.3.0)
rack
rack-mount (0.8.3)
@ -554,7 +553,6 @@ DEPENDENCIES
parallel_tests
pg
rack-cors (~> 0.2.4)
rack-google-analytics
rack-piwik
rack-rewrite (~> 1.2.1)
rack-ssl

View file

@ -0,0 +1,33 @@
# 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

View file

@ -40,12 +40,6 @@ module ApplicationHelper
javascript_tag("Modernizr.mq('(min-width:0)') || document.write(unescape('#{j javascript_include_tag("mbp-respond.min")}'));")
end
# This will *only* fire if analytics are configured (don't panic!)
def include_advanced_segments
segment = current_user ? current_user.role_name : "unauthenticated"
javascript_tag("if(window._gaq) { _gaq.push(['_setCustomVar', 1, 'Role', '#{segment}']) }")
end
# Require jQuery from CDN if possible, falling back to vendored copy, and require
# vendored jquery_ujs
def jquery_include_tag

View file

@ -40,7 +40,7 @@
= set_current_user_in_javascript
= translation_missing_warnings
= current_user_atom_tag
= include_advanced_segments
= include_google_analyics
= yield(:head)
= csrf_meta_tag

View file

@ -45,7 +45,7 @@
= set_asset_host
= translation_missing_warnings
= current_user_atom_tag
= include_advanced_segments
= include_google_analytics
- if @post.present?
%link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"}

View file

@ -5,11 +5,6 @@
if Rails.env == 'production'
Diaspora::Application.configure do
if AppConfig[:google_a_site].present?
config.gem 'rack-google-analytics', :lib => 'rack/google-analytics'
config.middleware.use Rack::GoogleAnalytics, :tracker => AppConfig[:google_a_site]
end
if AppConfig[:piwik_url].present?
config.gem 'rack-piwik', :lib => 'rack/piwik'
config.middleware.use Rack::Piwik, :piwik_url => AppConfig[:piwik_url], :piwik_id => AppConfig[:piwik_id]