Sha256: baa4b595271b7b4001ec5a5a4df59d4b0b319003c58e1a5986a7d428e864633a

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

module Analytical
  module Chartbeat
    class Api
      include Analytical::Base::Api

      def initialize(parent, 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

2 entries across 2 versions & 1 rubygems

Version Path
analytical-1.5.0 lib/analytical/chartbeat.rb
analytical-1.4.0 lib/analytical/chartbeat.rb