Sha256: bf96e54944641a6cbb46a00af538625c4dff8514f031dcd76aa4f80263f8889f

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

require "event_capture/events_controller"
require "event_capture/event"

module EventCapture
  # Augment/override behavior.
  class EventsController
    before_action :authenticate_participant!

    def event_params
      {
        kind: params[:kind],
        payload: payload_params.to_h.merge(remote_ip: request.remote_ip),
        emitted_at: params[:emittedAt],
        participant_id: current_participant.id
      }
    end

    private

    # Permit payload parameters defined in
    # app/assets/javascripts/think_feel_do_engine/event_capture/init.js
    def payload_params
      params.require(:payload).permit(
        :currentUrl,
        :headers,
        :ua,
        :buttonHtml,
        :parentHtml,
        :headers
      )
    end
  end

  # Augment behavior.
  class Event
    belongs_to :participant

    def self.next_event_for(event)
      where(participant_id: event.participant_id)
        .where.not(kind: "videoPlay")
        .where("emitted_at > ?", event.emitted_at)
        .select(:participant_id, :kind, :emitted_at)
        .order(:emitted_at)
        .limit(1)
        .first
    end

    def current_url
      payload["currentUrl"]
    end

    def button_html
      payload["buttonHtml"]
    end

    def headers
      payload["headers"]
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.0 config/initializers/event_capture.rb
think_feel_do_engine-3.21.2 config/initializers/event_capture.rb
think_feel_do_engine-3.21.1 config/initializers/event_capture.rb
think_feel_do_engine-3.21.0 config/initializers/event_capture.rb
think_feel_do_engine-3.20.1 config/initializers/event_capture.rb
think_feel_do_engine-3.19.9 config/initializers/event_capture.rb
think_feel_do_engine-3.19.8 config/initializers/event_capture.rb
think_feel_do_engine-3.19.7 config/initializers/event_capture.rb
think_feel_do_engine-3.19.6 config/initializers/event_capture.rb
think_feel_do_engine-3.19.5 config/initializers/event_capture.rb
think_feel_do_engine-3.19.4 config/initializers/event_capture.rb
think_feel_do_engine-3.19.3 config/initializers/event_capture.rb
think_feel_do_engine-3.19.2 config/initializers/event_capture.rb
think_feel_do_engine-3.19.1 config/initializers/event_capture.rb
think_feel_do_engine-3.19.0 config/initializers/event_capture.rb