Class: Sentiero::Analytics::HeatmapAnalyzer
- Defined in:
- lib/sentiero/analytics/heatmap_analyzer.rb
Overview
Aggregates click coordinates for a single page URL into a normalized density grid plus a most-clicked-elements table. The per-segment density math lives in ClickCollector (shared with PageReportAnalyzer).
Constant Summary collapse
- CLICK_TAG =
ClickCollector::CLICK_TAG
- GRID_SIZE =
ClickCollector::GRID_SIZE
- TOP_ELEMENTS_LIMIT =
20- MAX_URLS =
200
Constants included from Events
Events::CUSTOM, Events::INCREMENTAL, Events::META, Events::SOURCE_INPUT, Events::SOURCE_MOUSE_INTERACTION, Events::SOURCE_SCROLL
Instance Attribute Summary
Attributes inherited from Analyzer
Instance Method Summary collapse
-
#analyze(target_url, limit: nil, since: nil, until_time: nil) ⇒ Object
Clicks are attributed per page segment (Meta-href boundaries).
- #build_heatmap_table(since: nil, until_time: nil) ⇒ Object
- #recorded_urls ⇒ Object
Methods inherited from Analyzer
Methods included from EntryAttribution
#earlier?, #first_meta_href, #same_origin?, #update_entry_candidate
Methods included from Bounded
#bounded_fetch, #bounded_increment
Methods included from Stats
#mean, #offset_ms, #percentile, #top_counts
Constructor Details
This class inherits a constructor from Sentiero::Analytics::Analyzer
Instance Method Details
#analyze(target_url, limit: nil, since: nil, until_time: nil) ⇒ Object
Clicks are attributed per page segment (Meta-href boundaries).
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sentiero/analytics/heatmap_analyzer.rb', line 19 def analyze(target_url, limit: nil, since: nil, until_time: nil) clicks = ClickCollector.new representative = nil _scanned, hit_cap = scan_sessions(limit: limit, since: since, until_time: until_time) do |summary, window_id, events| session_id = summary[:session_id] each_page_segment(events) do |url, segment, _anchor| next unless url == target_url added = clicks.collect(segment) representative ||= {session_id: session_id, window_id: window_id} unless added.nil? end end { clicks_by_bucket: clicks.buckets, top_elements: top_elements(clicks.selectors), total_clicks: clicks.total, representative_window: representative, was_truncated: hit_cap } end |
#build_heatmap_table(since: nil, until_time: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sentiero/analytics/heatmap_analyzer.rb', line 43 def build_heatmap_table(since: nil, until_time: nil) selectors_by_url = {} scan_sessions(since: since, until_time: until_time) do |_summary, _window_id, events| each_page_segment(events) do |url, segment, _anchor| next unless url selectors = selectors_by_url[url] if selectors.nil? next if selectors_by_url.size >= MAX_URLS selectors = selectors_by_url[url] = Hash.new(0) end segment.each { |event| tally_selector(selectors, event) } end end selectors_by_url .sort_by { |url, _selectors| url } .to_h { |url, selectors| [url, top_elements(selectors)] } end |
#recorded_urls ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sentiero/analytics/heatmap_analyzer.rb', line 64 def recorded_urls urls = {} scan_sessions do |_summary, _window_id, events| each_page_segment(events) do |url, _segment, _anchor| urls[url] = true if url && (urls.key?(url) || urls.size < MAX_URLS) end end urls.keys end |