diff --git a/Gemfile b/Gemfile index 10a9394f7..378e6588a 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 5b61087e8..e87b148a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/helpers/analytics_helper.rb b/app/helpers/analytics_helper.rb new file mode 100644 index 000000000..cf9b93c0d --- /dev/null +++ b/app/helpers/analytics_helper.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e7e676831..acebf3057 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c7ad46c08..1e277f693 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index b995d03d5..c4cdca34a 100644 --- a/app/views/layouts/post.html.haml +++ b/app/views/layouts/post.html.haml @@ -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))}"} diff --git a/config/initializers/load_analyitics.rb b/config/initializers/load_analyitics.rb index d071392c5..15ccc71b3 100644 --- a/config/initializers/load_analyitics.rb +++ b/config/initializers/load_analyitics.rb @@ -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]