added GA back into rack; added mixpanel configuration options
This commit is contained in:
parent
6dba7fe9a9
commit
72d2f619fc
7 changed files with 50 additions and 46 deletions
3
Gemfile
3
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<g.length;e++)(function(a){b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,0)))}})(g[e]);c._i.push([a,d,f])};window.mixpanel=c})(document,[]);
|
||||
mixpanel.init(#{service_uid});
|
||||
JS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def chartbeat_head_block
|
||||
return unless chartbeat_configured?
|
||||
return unless configured?("chartbeat")
|
||||
javascript_tag("var _sf_startpt=(new Date()).getTime()")
|
||||
end
|
||||
|
||||
def include_chartbeat
|
||||
return unless chartbeat_configured?
|
||||
javascript_tag do
|
||||
<<-JS
|
||||
var _sf_async_config = { uid: #{AppConfig[:chartbeat_uid]}, domain: '#{AppConfig[:pod_uri].host}' };
|
||||
(function() {
|
||||
function loadChartbeat() {
|
||||
window._sf_endpt = (new Date()).getTime();
|
||||
var e = document.createElement('script');
|
||||
e.setAttribute('language', 'javascript');
|
||||
e.setAttribute('type', 'text/javascript');
|
||||
e.setAttribute('src',
|
||||
(('https:' == document.location.protocol) ? 'https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/' : 'http://static.chartbeat.com/') +
|
||||
'js/chartbeat.js');
|
||||
document.body.appendChild(e);
|
||||
};
|
||||
var oldonload = window.onload;
|
||||
window.onload = (typeof window.onload != 'function') ?
|
||||
loadChartbeat : function() { oldonload(); loadChartbeat(); };
|
||||
})();
|
||||
JS
|
||||
include_analytics "chartbeat" do |service_uid|
|
||||
javascript_tag do
|
||||
<<-JS
|
||||
var _sf_async_config = { uid: #{service_uid}, domain: '#{AppConfig[:pod_uri].host}' };
|
||||
(function() {
|
||||
function loadChartbeat() {
|
||||
window._sf_endpt = (new Date()).getTime();
|
||||
var e = document.createElement('script');
|
||||
e.setAttribute('language', 'javascript');
|
||||
e.setAttribute('type', 'text/javascript');
|
||||
e.setAttribute('src',
|
||||
(('https:' == document.location.protocol) ? 'https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/' : 'http://static.chartbeat.com/') +
|
||||
'js/chartbeat.js');
|
||||
document.body.appendChild(e);
|
||||
};
|
||||
var oldonload = window.onload;
|
||||
window.onload = (typeof window.onload != 'function') ?
|
||||
loadChartbeat : function() { oldonload(); loadChartbeat(); };
|
||||
})();
|
||||
JS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def google_configured?
|
||||
AppConfig[:google_a_site].present? && AppConfig[:google_a_site].present?
|
||||
def include_analytics(service, &block)
|
||||
return unless configured?(service)
|
||||
yield block, service_uid=AppConfig["#{service}_uid".to_sym]
|
||||
end
|
||||
|
||||
def chartbeat_configured?
|
||||
AppConfig[:chartbeat_uid].present?
|
||||
def configured?(service)
|
||||
AppConfig["#{service}_uid".to_sym].present?
|
||||
end
|
||||
end
|
||||
|
|
@ -42,7 +42,6 @@
|
|||
= set_current_user_in_javascript
|
||||
= translation_missing_warnings
|
||||
= current_user_atom_tag
|
||||
= include_google_analytics
|
||||
|
||||
= yield(:head)
|
||||
= csrf_meta_tag
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
= set_asset_host
|
||||
= translation_missing_warnings
|
||||
= current_user_atom_tag
|
||||
= include_google_analytics
|
||||
|
||||
- if @post.present?
|
||||
%link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ defaults: &defaults
|
|||
## Chartbeat tracking
|
||||
chartbeat_uid:
|
||||
|
||||
## Mixpanel event tracking
|
||||
mixpanel_uid:
|
||||
|
||||
|
||||
######################################################
|
||||
# General Pod Settings
|
||||
######################################################
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in a new issue