Class: Sentiero::Analytics::ClickCollector
- Inherits:
-
Object
- Object
- Sentiero::Analytics::ClickCollector
- Defined in:
- lib/sentiero/analytics/collectors/click_collector.rb
Overview
Per-URL click density grid + element selectors across page segments. A click's viewport y becomes a page coordinate by adding the latest scroll offset, normalized against the estimated page height (deepest scroll + viewport); x by viewport width. Both bucket into a GRID_SIZE x GRID_SIZE grid.
Constant Summary collapse
- MOUSE_CLICK =
2- CLICK_TAG =
Carries the clicked element's CSS selector; rrweb's own click event only references an internal node id, not a stable selector.
"__click"- GRID_SIZE =
Grid resolution per axis.
20
Constants included from Events
Events::CUSTOM, Events::INCREMENTAL, Events::META, Events::SOURCE_INPUT, Events::SOURCE_MOUSE_INTERACTION, Events::SOURCE_SCROLL
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
-
#capped ⇒ Object
readonly
Returns the value of attribute capped.
-
#selectors ⇒ Object
readonly
Returns the value of attribute selectors.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#collect(segment) ⇒ Object
Returns clicks added, or nil when the segment has no usable viewport (callers branch on the nil).
-
#initialize(max_selectors: nil) ⇒ ClickCollector
constructor
A new instance of ClickCollector.
Methods included from Bounded
#bounded_fetch, #bounded_increment
Constructor Details
#initialize(max_selectors: nil) ⇒ ClickCollector
Returns a new instance of ClickCollector.
27 28 29 30 31 32 33 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 27 def initialize(max_selectors: nil) @max_selectors = max_selectors @buckets = Hash.new(0) @selectors = Hash.new(0) @total = 0 @capped = false end |
Instance Attribute Details
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
25 26 27 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25 def buckets @buckets end |
#capped ⇒ Object (readonly)
Returns the value of attribute capped.
25 26 27 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25 def capped @capped end |
#selectors ⇒ Object (readonly)
Returns the value of attribute selectors.
25 26 27 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25 def selectors @selectors end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
25 26 27 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25 def total @total end |
Instance Method Details
#collect(segment) ⇒ Object
Returns clicks added, or nil when the segment has no usable viewport (callers branch on the nil).
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 37 def collect(segment) = (segment) return nil unless page_height = estimate_page_height(segment, ) scroll_y = 0 added = 0 segment.each do |event| scroll_y = 0 if event["type"] == META if (y = document_scroll_y(event)) scroll_y = y end if click?(event) data = event["data"] @buckets[bucket(data["x"], data["y"] + scroll_y, , page_height)] += 1 added += 1 end tally_selector(event) end @total += added added end |