Sha256: 7b82dea2547cd1b2980ebc46a6c5711674e46e6bc4b0712901f0ce8bd8065cdb

Contents?: true

Size: 1.67 KB

Versions: 24

Compression:

Stored size: 1.67 KB

Contents

module Analytical
  module Modules
    class Chartbeat
      include Analytical::Modules::Base

      def initialize(options={})
        super
        @tracking_command_location = [:head_prepend, :body_append]
      end

      def init_javascript(location)
        init_location(location) do
          case location.to_sym
            when :head_prepend
            js = <<-HTML
            <!-- Analytical Head Init: Chartbeat -->
            <script type="text/javascript">var _sf_startpt=(new Date()).getTime();</script>
            HTML
            js
            when :body_append
            js = <<-HTML
            <!-- Analytical Body Init: Chartbeat -->
            <script type="text/javascript">
              var _sf_async_config={uid:#{options[:key]}, domain:"#{options[:domain]}"};
              (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://s3.amazonaws.com/" : "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(); };
              })();
              </script>
            HTML
            js
            end
        end
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
analytical-2.2.0 lib/analytical/modules/chartbeat.rb
analytical-2.1.0 lib/analytical/modules/chartbeat.rb
analytical-2.0.0 lib/analytical/modules/chartbeat.rb
analytical-1.9.0 lib/analytical/modules/chartbeat.rb