eff_matomo 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +11 -6
- data/lib/matomo.rb +26 -12
- data/lib/matomo/version.rb +1 -1
- data/lib/matomo/view_helpers.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7acc3a74ee56d8a406372034ee391cbcdcea3b8b45906fc3f4766be453041a0
|
4
|
+
data.tar.gz: ce930d0b254878f3047e9b7467bb24420b33720f514a1a5c5f6c0cbacad7b074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e4be46b925b9a2df0c7a252d8cbd07084343cdbc710e256c60f1139c694e2569fbbdd0fcdf8858061eea422fa252d714c05b599eb0c38d872a38fc09aa6be77
|
7
|
+
data.tar.gz: cbbe856f841c2afec25db810fed9400a9124bb77ea645026f2b3622e41a31e59e6bb20ed74607fffdbb9ca27da61842c2c5bb05d7fd2e10d03488a0a5a69d47f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eff_matomo (0.1
|
4
|
+
eff_matomo (0.2.1)
|
5
5
|
activesupport
|
6
6
|
httparty
|
7
7
|
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
hashdiff (0.3.7)
|
23
23
|
httparty (0.16.2)
|
24
24
|
multi_xml (>= 0.5.2)
|
25
|
-
i18n (1.1.
|
25
|
+
i18n (1.1.1)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
minitest (5.11.3)
|
28
28
|
multi_xml (0.6.0)
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ The EFF Matomo gem provides utilities for integrating our Ruby applications with
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'eff_matomo'
|
10
|
+
gem 'eff_matomo', require 'matomo'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -35,7 +35,7 @@ Add `<%= matomo_tracking_embed %>` to the footer of your application layout temp
|
|
35
35
|
This gem provides allows users to import site usage data from Matomo to display in their application. It currently supports two types of data:
|
36
36
|
|
37
37
|
**Referrers** show how users are reaching the application. Usage example:
|
38
|
-
```
|
38
|
+
```ruby
|
39
39
|
# Get the top five referrers for the site
|
40
40
|
referrers = Matomo::Referrer.top
|
41
41
|
|
@@ -45,18 +45,18 @@ referrers = Matomo::Referrer.where(start_date: Time.now - 1.month, end_date: Tim
|
|
45
45
|
# Only show referrers for a certain page within the app
|
46
46
|
referrers = Matomo::Referrer.where(path: "/action/my-important-action")
|
47
47
|
|
48
|
-
# Access information about each
|
48
|
+
# Access information about each referrer
|
49
49
|
referrers.each() do |referrer|
|
50
50
|
puts referrer.label # eg. "facebook.com"
|
51
51
|
puts referrer.visits # Number of times a visit came from this referrer
|
52
|
-
puts referrer.actions_per_visit # Average number of actions that
|
52
|
+
puts referrer.actions_per_visit # Average number of actions that occurred during a visit
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
56
|
**Visited Pages** show the top pages within the application, both in terms of unique page views and overall number of hits. Usage example:
|
57
|
-
```
|
57
|
+
```ruby
|
58
58
|
# Get the top pages under a certain path, for example under "/articles"
|
59
|
-
pages = Matomo::
|
59
|
+
pages = Matomo::Page.under_path("/articles")
|
60
60
|
|
61
61
|
# Access information about each page
|
62
62
|
pages.each() do |page|
|
@@ -65,6 +65,11 @@ pages.each() do |page|
|
|
65
65
|
puts page.hits # Overall number of hits on the page
|
66
66
|
puts page.visits # The number of distinct visits to the page
|
67
67
|
end
|
68
|
+
|
69
|
+
# Get views for a certain page, grouped by day
|
70
|
+
# Return format eg. { "2018-10-03": <Matomo::Page>, "2018-10-04": <Matomo::Page>, etc. }
|
71
|
+
pages = Matomo::Page.group_by_day("/articles/harm-reduction",
|
72
|
+
start_date: Time.now - 1.month, end_date: Time.now)
|
68
73
|
```
|
69
74
|
|
70
75
|
## Development
|
data/lib/matomo.rb
CHANGED
@@ -34,32 +34,47 @@ module Matomo
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
class
|
38
|
-
attr_accessor :
|
37
|
+
class Page
|
38
|
+
attr_accessor :hits, :visits, :path
|
39
39
|
|
40
|
-
def initialize(
|
41
|
-
@
|
42
|
-
@label = params["label"]
|
40
|
+
def initialize(path, params)
|
41
|
+
@path = path
|
42
|
+
@label = params["label"]
|
43
43
|
@hits = params["nb_hits"]
|
44
44
|
@visits = params["nb_visits"]
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
47
|
+
def label
|
48
|
+
return nil unless @label
|
49
|
+
@label.sub(/^\//, "").sub(/\?.*$/, "")
|
49
50
|
end
|
50
51
|
|
51
|
-
def self.
|
52
|
+
def self.under_path(base_path, **args)
|
52
53
|
get_subtables unless @subtables
|
53
54
|
# Remove leading and trailing slashes to match Matomo label format.
|
54
|
-
base_path =
|
55
|
+
base_path = base_path.gsub(/^\/|\/$/, "")
|
55
56
|
return [] unless @subtables[base_path]
|
56
57
|
|
57
58
|
resp = Matomo.get({
|
58
59
|
method: "Actions.getPageUrls",
|
59
|
-
idSubtable: @subtables[base_path]
|
60
|
+
idSubtable: @subtables[base_path]
|
60
61
|
})
|
61
62
|
return [] if resp.response.code != "200"
|
62
|
-
resp.map{ |x| new(base_path, x) }
|
63
|
+
resp.map{ |x| new("/#{base_path}#{x["label"]}", x) }
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Return format eg: { "2018-10-03": <Matomo::Page> }
|
68
|
+
def self.group_by_day(path, **args)
|
69
|
+
params = {
|
70
|
+
method: "Actions.getPageUrls",
|
71
|
+
segment: "pageUrl==#{Matomo.tracked_site_url}#{path}",
|
72
|
+
period: "day"
|
73
|
+
}.merge(Matomo.date_range_params(args[:start_date], args[:end_date]))
|
74
|
+
|
75
|
+
resp = Matomo.get(params)
|
76
|
+
return {} if resp.response.code != "200"
|
77
|
+
resp.transform_values{ |v| new(path, v.first || {}) }
|
63
78
|
end
|
64
79
|
|
65
80
|
def self.get_subtables
|
@@ -135,7 +150,6 @@ module Matomo
|
|
135
150
|
end_date = end_date || Date.today
|
136
151
|
start_date = start_date || end_date - 30.days
|
137
152
|
{
|
138
|
-
period: "range",
|
139
153
|
date: start_date.strftime(date_format) + "," + end_date.strftime(date_format)
|
140
154
|
}
|
141
155
|
end
|
data/lib/matomo/version.rb
CHANGED
data/lib/matomo/view_helpers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Matomo
|
2
2
|
module ViewHelpers
|
3
3
|
def matomo_tracking_url
|
4
|
-
"
|
4
|
+
"#{Matomo.base_url}/js/?" + {
|
5
5
|
idsite: Matomo.site_id,
|
6
6
|
rec: 1,
|
7
7
|
action_name: page_title,
|
@@ -13,7 +13,7 @@ module Matomo
|
|
13
13
|
content_tag(:div, id: "anon-stats") do
|
14
14
|
content_tag(:noscript) do
|
15
15
|
content_tag(:img, src: matomo_tracking_url, style: "border:0", alt: "")
|
16
|
-
end
|
16
|
+
end +
|
17
17
|
javascript_tag do
|
18
18
|
"document.getElementById('anon-stats').innerHTML = '<img src=\"#{matomo_tracking_url}\"?urlref=' + encodeURIComponent(document.referrer) + 'style=\"border:0\" alt=\"\" />';".html_safe
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eff_matomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vivian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|