Class: QuickSearch::LoggingController

Inherits:
ApplicationController show all
Includes:
OnCampus
Defined in:
app/controllers/quick_search/logging_controller.rb

Overview

This class handles QuickSearch’s internal logging of queries, events (clicks & serves), and sessions

Instance Method Summary collapse

Instance Method Details

#log_eventObject

Logs an event to the database. Typically, these can be clicks or serves.

This is an API endpoint for logging an event. It requires that at least a TODO are present in the query parameters. It returns a 200 OK HTTP status if the request was successful, or an 400 BAD REQUEST HTTP status if any parameters are missing. This endpoint supports JSONP requests.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/quick_search/logging_controller.rb', line 36

def log_event
  if params[:category].present? && params[:event_action].present? && params[:label].present?
    # if an action isn't passed in, assume that it is a click
    action = params.fetch(:action_type, 'click')

    # create a new event on the current session
    @session.events.create(category: params[:category], item: params[:event_action], query: params[:label][0..250], action: action)

    if params[:ga].present? and params[:ga]
      send_event_to_ga(params[:category], params[:event_action], params[:label])
    end

    # check whether this is a jsonp request
    if params[:callback].present?
      render :json => { 'response': 'success' }, :callback => params[:callback]
    else
      render :json => { 'response': 'success' }
    end
  else
    head :bad_request
  end
end

#log_searchObject

Logs a search to the database

This is an API endpoint for logging a search. It requires that at least a search query and a page are present in the query parameters. It returns a 200 OK HTTP status if the request was successful, or an 400 BAD REQUEST HTTP status if any parameters are missing.



20
21
22
23
24
25
26
27
# File 'app/controllers/quick_search/logging_controller.rb', line 20

def log_search
  if params[:query].present? && params[:page].present?
    @session.searches.create(query: params[:query], page: params[:page])
    head :ok
  else
    head :bad_request
  end
end