From 7be7acdfd6fd3ee4231c6d031f474803c5515c26 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Thu, 3 May 2012 14:02:40 -0700 Subject: [PATCH] add chartbeat option for great success (and metrics) --- app/helpers/analytics_helper.rb | 33 +++++++++++++++++++++++++ app/views/layouts/application.html.haml | 4 +++ app/views/layouts/post.html.haml | 4 +++ config/application.yml.example | 3 +++ 4 files changed, 44 insertions(+) diff --git a/app/helpers/analytics_helper.rb b/app/helpers/analytics_helper.rb index 7e7c3308c..cfd2ca417 100644 --- a/app/helpers/analytics_helper.rb +++ b/app/helpers/analytics_helper.rb @@ -25,9 +25,42 @@ module AnalyticsHelper end end + def chartbeat_head_block + return unless chartbeat_configured? + 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[:charbeat_uid]}, domain: '#{AppConfig[:pod_url]}' }; + (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 + private def google_configured? AppConfig[:google_a_site].present? && AppConfig[:google_a_site].present? end + + def chartbeat_configured? + AppConfig[:chartbeat_uid].present? + end end \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 5750b4b60..9c528bdde 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -19,6 +19,8 @@ %title = page_title yield(:page_title) + = chartbeat_head_block + = include_base_css_framework = stylesheet_link_tag 'login', 'application', 'default' @@ -73,3 +75,5 @@ %li= link_to t('.whats_new'), 'https://github.com/diaspora/diaspora/wiki/Changelog' %li= link_to(t('layouts.application.toggle'), toggle_mobile_path) if is_mobile_device? = image_tag 'branding/powered_by_diaspora.png', :height => "11px", :width => "145px" + + = include_chartbeat diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index c4cdca34a..8dc76bd1b 100644 --- a/app/views/layouts/post.html.haml +++ b/app/views/layouts/post.html.haml @@ -20,6 +20,8 @@ %link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'} = og_site_name + = chartbeat_head_block + %title = page_title yield(:page_title) @@ -58,3 +60,5 @@ = flash_messages #container = javascript_tag "window.preLoadContent = '#{escape_javascript(yield)}'" + + = include_chartbeat diff --git a/config/application.yml.example b/config/application.yml.example index 069f642d2..9cf9b9a01 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -82,6 +82,9 @@ defaults: &defaults # the site url in raw format (e.g. pikwik.examplehost.com) piwik_url: + ## Chartbeat tracking + chartbeat_uid: + ###################################################### # General Pod Settings ######################################################