Class: Sentiero::Analytics::ConversionAnalyzer

Inherits:
Analyzer
  • Object
show all
Defined in:
lib/sentiero/analytics/conversion_analyzer.rb

Overview

Conversion rate by acquisition dimension (entry page, referrer host, UTM) for one custom-event tag. A session counts as converting at most once, regardless of how many times/windows the tag fired.

Constant Summary collapse

TOP_ROWS =
15
MIN_SESSIONS_FOR_RATE =

Below this many sessions a rate is too thin; rows flagged low_volume.

5
MAX_DIMENSION_KEYS =

A new key past the cap is dropped and sets was_truncated.

200
DIRECT =
"(direct / none)"
UTM_PARAMS =

Matched case-insensitively.

%w[utm_source utm_medium utm_campaign].freeze

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

#store

Instance Method Summary collapse

Methods inherited from Analyzer

#initialize

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(tag = nil, limit: nil, since: nil, until_time: nil) ⇒ Object

No tag selected → empty facets, but tag vocabulary is still collected.



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
# File 'lib/sentiero/analytics/conversion_analyzer.rb', line 28

def analyze(tag = nil, limit: nil, since: nil, until_time: nil)
  selected = FunnelAnalyzer.usable_steps([tag].compact).first

  tags = {}
  sessions = {}
  @truncated = false

  _scanned, hit_cap = scan_sessions(limit: limit, since: since, until_time: until_time) do |summary, window_id, events|
    session_id = summary[:session_id]
    state = sessions[session_id] ||= new_state(summary, window_id)

    update_entry_candidate(state, events)
    collect_vocabulary(tags, events)
    record_conversion(state, selected, window_id, events) if selected
  end

  facets = selected ? build_facets(sessions) : empty_facets

  {
    tags: tags.keys.sort,
    selected_tag: selected,
    entry_pages: facets[:entry_pages],
    referrers: facets[:referrers],
    utm: facets[:utm],
    was_truncated: @truncated || hit_cap
  }
end