diff --git a/Gemfile b/Gemfile index 18d43ef97..06172736f 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,9 @@ group :production do # we don't install these on travis to speed up test runs gem 'fastercsv', '1.5.4', :require => false gem 'rack-ssl', :require => 'rack/ssl' gem 'rack-rewrite', '~> 1.2.1', :require => false + + # analytics + gem 'rack-google-analytics', :require => 'rack/google-analytics' gem 'rack-piwik', :require => 'rack/piwik', :require => false end diff --git a/Gemfile.lock b/Gemfile.lock index deace8cd9..3d734a3c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -300,6 +300,7 @@ GEM rack (>= 0.4) rack-cors (0.2.6) rack + rack-google-analytics (0.10.0) rack-mobile-detect (0.3.0) rack rack-piwik (0.1.2) @@ -509,6 +510,7 @@ DEPENDENCIES omniauth-twitter 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 index 3a5be8026..63b57591d 100644 --- a/app/helpers/analytics_helper.rb +++ b/app/helpers/analytics_helper.rb @@ -3,64 +3,56 @@ # 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 + def include_mixpanel + include_analytics "mixpanel" do |service_uid| + javascript_tag do + <<-JS + (function(d,c){var a,b,g,e;a=d.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===d.location.protocol?"https:":"http:")+'//api.mixpanel.com/site_media/js/api/mixpanel.2.js';b=d.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b);c._i=[];c.init=function(a,d,f){var b=c;"undefined"!==typeof f?b=c[f]=[]:f="mixpanel";g="disable track track_pageview track_links track_forms register register_once unregister identify name_tag set_config".split(" "); + for(e=0;e 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"} diff --git a/config/application.yml.example b/config/application.yml.example index 1179aadce..569e3e87c 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -85,6 +85,10 @@ defaults: &defaults ## Chartbeat tracking chartbeat_uid: + ## Mixpanel event tracking + mixpanel_uid: + + ###################################################### # General Pod Settings ###################################################### diff --git a/config/initializers/load_analyitics.rb b/config/initializers/load_analyitics.rb index ccfbc22bc..0b804ffeb 100644 --- a/config/initializers/load_analyitics.rb +++ b/config/initializers/load_analyitics.rb @@ -5,6 +5,11 @@ 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? require 'rack/piwik' config.gem 'rack-piwik', :lib => 'rack/piwik'