Sha256: 3fa26e35443c1aae075588b1fb8e02e9a1fe0771f775c2f907ce7a228ad057e8

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

module Analytical
  module KissMetrics
    class Api
      include Analytical::Base::Api

      def initialize(parent, options={})
        super
        @tracking_command_location = :body_prepend
      end

      def init_javascript(location)
        return '' unless location==:body_prepend
        js = <<-HTML
        <!-- Analytical Init: KissMetrics -->
        <script type="text/javascript">
          var _kmq = _kmq || [];
          (function(){function _kms(u,d){if(navigator.appName.indexOf("Microsoft")==0 && d)document.write("<scr"+"ipt defer='defer' async='true' src='"+u+"'></scr"+"ipt>");else{var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=u;(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);}}_kms('http' + ('https:' == document.location.protocol ? 's://': '://') + 'i.kissmetrics.com/i.js', 1);_kms('http'+('https:'==document.location.protocol ? 's://s3.amazonaws.com/' : '://')+'scripts.kissmetrics.com/#{options[:key]}.1.js',1);})();
        </script>
        <script type="text/javascript">
          _kmq.push(['pageView']);
        </script>
        HTML
        js
      end

      def identify(id, *args)
        data = args.first || {}
        "_kmq.push([\"identify\", \"#{data[:email]}\"]);"
      end

      def event(name, *args)
        data = args.first || {}
        "_kmq.push([\"record\", \"#{name}\", #{data.to_json}]);"
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
analytical-0.16.0 lib/analytical/kiss_metrics.rb
analytical-0.15.0 lib/analytical/kiss_metrics.rb
analytical-0.14.0 lib/analytical/kiss_metrics.rb
analytical-0.13.0 lib/analytical/kiss_metrics.rb
analytical-0.12.0 lib/analytical/kiss_metrics.rb
analytical-0.11.0 lib/analytical/kiss_metrics.rb
analytical-0.10.0 lib/analytical/kiss_metrics.rb
analytical-0.9.0 lib/analytical/kiss_metrics.rb
analytical-0.8.0 lib/analytical/kiss_metrics.rb