Class: Sentiero::Analytics::CustomTagCollector
- Inherits:
-
Object
- Object
- Sentiero::Analytics::CustomTagCollector
- Defined in:
- lib/sentiero/analytics/collectors/custom_tag_collector.rb
Overview
Custom-event tag tally across page segments. The single definition of which tags are "internal" and how the rest are counted and ranked.
Constant Summary collapse
- INTERNAL_TAG_PREFIX =
Recorder-internal annotations (__perf, __click, …); never on the panel.
"__"- ERROR_TAG =
The JS-error tag is also internal — it has its own panel.
"error"- MAX_CUSTOM_TAGS =
200
Constants included from Events
Events::CUSTOM, Events::INCREMENTAL, Events::META, Events::SOURCE_INPUT, Events::SOURCE_MOUSE_INTERACTION, Events::SOURCE_SCROLL
Instance Attribute Summary collapse
-
#capped ⇒ Object
readonly
Returns the value of attribute capped.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #collect(segment) ⇒ Object
-
#initialize(max_tags: nil) ⇒ CustomTagCollector
constructor
max_tags: nil unbounded; an Integer caps distinct tags, flipping #capped.
- #internal_tag?(tag) ⇒ Boolean
-
#tally(tag) ⇒ Object
Returns true when counted, false when internal or capped — callers gate per-tag side-effects on this.
- #top(n) ⇒ Object
Methods included from Stats
#mean, #offset_ms, #percentile, #top_counts
Methods included from Bounded
#bounded_fetch, #bounded_increment
Constructor Details
#initialize(max_tags: nil) ⇒ CustomTagCollector
max_tags: nil unbounded; an Integer caps distinct tags, flipping #capped.
25 26 27 28 29 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 25 def initialize(max_tags: nil) @max_tags = @tags = Hash.new(0) @capped = false end |
Instance Attribute Details
#capped ⇒ Object (readonly)
Returns the value of attribute capped.
22 23 24 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 22 def capped @capped end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
22 23 24 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 22 def @tags end |
Instance Method Details
#collect(segment) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 45 def collect(segment) segment.each do |event| next unless event["type"] == CUSTOM tag = event.dig("data", "tag") next unless tag.is_a?(String) && !tag.empty? tally(tag) end end |
#internal_tag?(tag) ⇒ Boolean
31 32 33 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 31 def internal_tag?(tag) tag.start_with?(INTERNAL_TAG_PREFIX) || tag == ERROR_TAG end |
#tally(tag) ⇒ Object
Returns true when counted, false when internal or capped — callers gate per-tag side-effects on this.
37 38 39 40 41 42 43 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 37 def tally(tag) return false if internal_tag?(tag) counted = bounded_increment(@tags, tag, @max_tags) @capped = true unless counted counted end |
#top(n) ⇒ Object
56 57 58 |
# File 'lib/sentiero/analytics/collectors/custom_tag_collector.rb', line 56 def top(n) top_counts(@tags, limit: n).map { |tag, count| {tag: tag, count: count} } end |