Sha256: aceac8325f73c3b23f7d4e1305f2a23c3f55f485ab262f0e64c92ae4cc982a0e

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

module Analytical
  module Console
    class Api
      include Analytical::Base::Api

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

      def init_javascript(location)
        return '' unless location==:head
        js = <<-HTML
        <!-- Analytical Init: Console -->
        <script type="text/javascript">
          console.log('Analytical Init: Console');
        </script>
        HTML
        js
      end

      def track(*args)
        "console.log(\"Analytical Track: \"+\"#{escape args.first}\");"
      end

      def identify(id, *args)
        data = args.first || {}
        "console.log(\"Analytical Identify: \"+\"#{id}\"+\" \"+$H(#{data.to_json}).toJSON());"
      end

      def event(name, *args)
        data = args.first || {}
        "console.log(\"Analytical Event: \"+\"#{name}\"+\" \"+$H(#{data.to_json}).toJSON());"
      end

      private

      CONSOLE_JS_ESCAPE_MAP = {
        '\\' => '\\\\',
        '</' => '<\/',
        "\r\n" => '\n',
        "\n" => '\n',
        "\r" => '\n',
        '"' => '\\"',
        "'" => "\\'"
      }

      def escape(js)
        js.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { CONSOLE_JS_ESCAPE_MAP[$1] }
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
analytical-1.0.0 lib/analytical/console.rb
analytical-0.16.0 lib/analytical/console.rb
analytical-0.15.0 lib/analytical/console.rb
analytical-0.14.0 lib/analytical/console.rb
analytical-0.13.0 lib/analytical/console.rb
analytical-0.12.0 lib/analytical/console.rb
analytical-0.11.0 lib/analytical/console.rb
analytical-0.10.0 lib/analytical/console.rb
analytical-0.9.0 lib/analytical/console.rb
analytical-0.8.0 lib/analytical/console.rb
analytical-0.7.0 lib/analytical/console.rb
analytical-0.6.0 lib/analytical/console.rb
analytical-0.5.0 lib/analytical/console.rb