Class: Sentiero::Web::AnalyticsApp

Inherits:
BaseApp
  • Object
show all
Defined in:
lib/sentiero/web/analytics_app.rb

Overview

Rack app owning all /analytics/* routes. Mounted at the same point as DashboardApp (which delegates /analytics requests here), so PATH_INFO/SCRIPT_NAME are read from env to preserve base_path.

Constant Summary collapse

ALLOWED_RANGES =
[14, 30, 90].freeze
DEFAULT_RANGE =
30
BROWSER_OPTIONS =
%w[Chrome Safari Firefox Edge Opera Other].freeze
DEVICE_OPTIONS =
%w[Desktop Mobile Tablet].freeze
METADATA_MATCH_OPTIONS =
%w[exact contains].freeze
ENGAGEMENT_SORTS =
%w[score duration].freeze
MAX_FILTER_LENGTH =

Cap on free-text filter inputs

256

Constants inherited from BaseApp

BaseApp::ASSETS_DIR, BaseApp::AUTH_WARNING_LOCK, BaseApp::CONTENT_TYPES, BaseApp::CSP_POLICY

Constants included from Escaping

Escaping::HTML_UNSAFE_IN_SCRIPT, Escaping::HTML_UNSAFE_IN_SCRIPT_PATTERN

Instance Method Summary collapse

Methods inherited from BaseApp

reset_auth_warning!, warn_unauthenticated_once

Methods included from Formatting

#format_duration, #format_vital, #parse_browser, #parse_device

Methods included from Escaping

#escape_html, #escape_js_string, #escape_json

Constructor Details

#initializeAnalyticsApp

Returns a new instance of AnalyticsApp.



20
21
22
23
# File 'lib/sentiero/web/analytics_app.rb', line 20

def initialize
  super
  BaseApp.warn_unauthenticated_once
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sentiero/web/analytics_app.rb', line 25

def call(env)
  path = env["PATH_INFO"] || "/"

  return unauthorized_response unless authorized?(env)

  case path
  when "/analytics"
    handle_overview(env)
  when "/analytics/heatmap"
    handle_heatmap(env)
  when "/analytics/heatmap.json"
    handle_heatmap_json(env)
  when "/analytics/segments"
    handle_segments(env)
  when "/analytics/scroll"
    handle_scroll(env)
  when "/analytics/vitals"
    handle_vitals(env)
  when "/analytics/frustration"
    handle_frustration(env)
  when "/analytics/funnel"
    handle_funnel(env)
  when "/analytics/engagement"
    handle_engagement(env)
  when "/analytics/conversions"
    handle_conversions(env)
  when "/analytics/forms"
    handle_forms(env)
  when "/analytics/page"
    handle_page(env)
  when "/analytics/export"
    handle_export_index(env)
  when %r{\A/analytics/export/(\w+)\.(csv|json)\z}
    handle_export_download(env, $1, $2)
  when %r{\A/analytics/share/([^/]+)\z}
    id = $1
    return invalid_id unless valid_id?(id)
    return not_found unless shareable_replays?
    handle_share(env, id)
  when "/analytics/import"
    return not_found unless shareable_replays?
    handle_import(env)
  else
    not_found
  end
end