Sha256: 4bcb99f6960b42b9e5459ab000e41fed076b36b86d94d61478c7437085bba894

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

module Analytical
  module Clicky
    class Api
      include Analytical::Base::Api

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

      def init_javascript(location)
        init_location(location) do
          protocol = options[:ssl] ? 'https' : 'http'

          js = <<-HTML
          <!-- Analytical Init: Clicky -->
          <script src="#{protocol}://static.getclicky.com/js" type="text/javascript"></script>
          <script type="text/javascript">clicky.init('#{@options[:key]}');</script>
          <noscript><p><img alt="Clicky" width="1" height="1" src="#{protocol}://in.getclicky.com/#{@options[:key]}ns.gif" /></p></noscript>
          HTML

          identify_commands = []
          @commands.each do |c|
            if c[0] == :identify
              identify_commands << identify(*c[1..-1])
            end
          end
          js = identify_commands.join("\n") + "\n" + js
          @commands = @commands.delete_if {|c| c[0] == :identify }

          js
        end
      end

      def track(*args)
        "clicky.log(\"#{args.first}\");"
      end

      def identify(id, *args)
        data = { :id=>id }.merge(args.first || {})
        code = <<-HTML
        <script type='text/javascript'>
          var clicky_custom_session = #{data.to_json};
        </script>
        HTML
        code
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
analytical-1.5.0 lib/analytical/clicky.rb
analytical-1.4.0 lib/analytical/clicky.rb
analytical-1.3.0 lib/analytical/clicky.rb
analytical-1.2.0 lib/analytical/clicky.rb