Class: Sentiero::Analytics::ClickCollector

Inherits:
Object
  • Object
show all
Includes:
Bounded, Events
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

Instance Method Summary collapse

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

#bucketsObject (readonly)

Returns the value of attribute buckets.



25
26
27
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25

def buckets
  @buckets
end

#cappedObject (readonly)

Returns the value of attribute capped.



25
26
27
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25

def capped
  @capped
end

#selectorsObject (readonly)

Returns the value of attribute selectors.



25
26
27
# File 'lib/sentiero/analytics/collectors/click_collector.rb', line 25

def selectors
  @selectors
end

#totalObject (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)
  viewport = viewport_size(segment)
  return nil unless viewport

  page_height = estimate_page_height(segment, viewport)
  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, viewport, page_height)] += 1
      added += 1
    end
    tally_selector(event)
  end

  @total += added
  added
end