Sha256: 386205a6d0a3207577f8dd5017bc0e09a8e4c76f4256f38d6c8acc292ff1dd82

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Analytical
  module Modules
    class Clicky
      include Analytical::Modules::Base

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

      def init_javascript(location)
        init_location(location) do
          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

1 entries across 1 versions & 1 rubygems

Version Path
analytical-1.9.0 lib/analytical/modules/clicky.rb