Sha256: 370833a4081cfa1186ce4439c0e5e8b37adfce0e7a95bb528b2f2a291323675a

Contents?: true

Size: 997 Bytes

Versions: 22

Compression:

Stored size: 997 Bytes

Contents

module Ahoy
  class EventsController < Ahoy::BaseController
    def create
      events =
        if params[:name]
          # legacy API and AMP
          [request.params]
        elsif params[:events]
          request.params[:events]
        else
          data =
            if params[:events_json]
              request.params[:events_json]
            else
              request.body.read
            end
          begin
            ActiveSupport::JSON.decode(data)
          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

22 entries across 22 versions & 1 rubygems

Version Path
ahoy_matey-5.1.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-5.0.2 app/controllers/ahoy/events_controller.rb
ahoy_matey-5.0.1 app/controllers/ahoy/events_controller.rb
ahoy_matey-5.0.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.2.1 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.2.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.1.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.0.3 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.0.2 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.0.1 app/controllers/ahoy/events_controller.rb
ahoy_matey-4.0.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.3.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.2.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.1.0 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.5 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.4 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.3 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.2 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.1 app/controllers/ahoy/events_controller.rb
ahoy_matey-3.0.0 app/controllers/ahoy/events_controller.rb