Sha256: 4d351b20ccb50143367740b05f35cfb479c209659117ba2001641fdae7f805d0

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 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('https://i.kissmetrics.com/i.js');_kms('http'+('https:'==document.location.protocol ? 's://s3.amazonaws.com/' : '://')+'scripts.kissmetrics.com/#{options[:key]}.1.js',1);})();
        </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

1 entries across 1 versions & 1 rubygems

Version Path
analytical-0.3.0 lib/analytical/kiss_metrics.rb