Sha256: acd37c766ed0ac819ecc67c3e82cbb361f9269e429d210ee9d0aa988949ec202

Contents?: true

Size: 841 Bytes

Versions: 5

Compression:

Stored size: 841 Bytes

Contents

module Ahoy
  class EventsController < Ahoy::BaseController
    def create
      events =
        if params[:name]
          # legacy API
          [request.params]
        elsif params[:events]
          request.params[:events]
        else
          begin
            ActiveSupport::JSON.decode(request.body.read)
          rescue ActiveSupport::JSON.parse_error
            # do nothing
            []
          end
        end

      events.first(Ahoy.max_events_per_request).each do |event|
        time = Time.zone.parse(event["time"]) rescue nil

        # timestamp is deprecated
        time ||= Time.zone.at(event["time"].to_f) rescue nil

        options = {
          id: event["id"],
          time: time
        }
        ahoy.track event["name"], event["properties"], options
      end
      render json: {}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ahoy_matey-1.6.1 app/controllers/ahoy/events_controller.rb
ahoy_matey-1.6.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-1.5.5 app/controllers/ahoy/events_controller.rb
ahoy_matey-1.5.4 app/controllers/ahoy/events_controller.rb
ahoy_matey-1.5.3 app/controllers/ahoy/events_controller.rb