Class: Matomo::Page
- Inherits:
-
Object
- Object
- Matomo::Page
- Defined in:
- lib/matomo.rb
Instance Attribute Summary collapse
-
#hits ⇒ Object
Returns the value of attribute hits.
-
#path ⇒ Object
Returns the value of attribute path.
-
#visits ⇒ Object
Returns the value of attribute visits.
Class Method Summary collapse
- .get_subtables ⇒ Object
-
.group_by_day(path, **args) ⇒ Object
Return format eg: { “2018-10-03”: <Matomo::Page> }.
- .under_path(base_path, **args) ⇒ Object
Instance Method Summary collapse
-
#initialize(path, params = {}) ⇒ Page
constructor
A new instance of Page.
- #label ⇒ Object
Constructor Details
#initialize(path, params = {}) ⇒ Page
Returns a new instance of Page.
41 42 43 44 45 46 |
# File 'lib/matomo.rb', line 41 def initialize(path, params = {}) @path = path @label = params["label"] @hits = params["nb_hits"] || 0 @visits = params["nb_visits"] || 0 end |
Instance Attribute Details
#hits ⇒ Object
Returns the value of attribute hits.
39 40 41 |
# File 'lib/matomo.rb', line 39 def hits @hits end |
#path ⇒ Object
Returns the value of attribute path.
39 40 41 |
# File 'lib/matomo.rb', line 39 def path @path end |
#visits ⇒ Object
Returns the value of attribute visits.
39 40 41 |
# File 'lib/matomo.rb', line 39 def visits @visits end |
Class Method Details
.get_subtables ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/matomo.rb', line 81 def self.get_subtables # Get a mapping from resource paths to Matomo page view subtable ids resp = Matomo.get({ method: "Actions.getPageUrls", filter_limit: 50, }) if resp.response.code == "200" @subtables = resp.map{|x| [x["label"], x["idsubdatatable"]]}.to_h else @subtables = {} end end |
.group_by_day(path, **args) ⇒ Object
Return format eg: { “2018-10-03”: <Matomo::Page> }
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/matomo.rb', line 69 def self.group_by_day(path, **args) params = { method: "Actions.getPageUrls", segment: "pageUrl==#{Matomo.tracked_site_url}#{path}", period: "day" }.merge(Matomo.date_range_params(args[:start_date], args[:end_date])) resp = Matomo.get(params) return {} if resp.response.code != "200" resp.transform_values{ |v| new(path, v.first || {}) } end |
.under_path(base_path, **args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/matomo.rb', line 53 def self.under_path(base_path, **args) get_subtables unless @subtables # Remove leading and trailing slashes to match Matomo label format. base_path = base_path.gsub(/^\/|\/$/, "") return [] unless @subtables[base_path] resp = Matomo.get({ method: "Actions.getPageUrls", idSubtable: @subtables[base_path] }) return [] if resp.response.code != "200" resp.map{ |x| new("/#{base_path}#{x["label"]}", x) } end |
Instance Method Details
#label ⇒ Object
48 49 50 51 |
# File 'lib/matomo.rb', line 48 def label return nil unless @label @label.sub(/^\//, "").sub(/\?.*$/, "") end |