plausible_api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -9
- data/lib/plausible_api/api/client.rb +2 -2
- data/lib/plausible_api/api/stats/aggregate.rb +11 -5
- data/lib/plausible_api/api/stats/realtime/visitors.rb +16 -0
- data/lib/plausible_api/api/stats/timeseries.rb +8 -5
- data/lib/plausible_api/version.rb +1 -1
- metadata +2 -2
- data/lib/plausible_api/api/realtime/visitors.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3960123efcdafae0607d993403d5d3ed6108952b623e282e08d97abe5d68b337
|
4
|
+
data.tar.gz: 7c03a6435a1d62ca54c07969e09141a546014b093b5ac6e1150b33031f0bdbbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b6330d478c5affc54605998832e32d38f72659099279f40cb550a84eda0c0593b61efe0af7c7b0ff581e93ed2c191c47518a9eb6d9fee73fb68617372d85f1f
|
7
|
+
data.tar.gz: 53a8202c35ce4507e6144ffb3623ef899822b179b11b716ec60a079aefbbb2fea89d0be1c4e31e6b625c8540dfb5a1160d81224d2a06af9b31d848e422743830
|
data/README.md
CHANGED
@@ -20,9 +20,9 @@ You have all these options to get the aggregate stats
|
|
20
20
|
c.aggregate
|
21
21
|
|
22
22
|
# Set parameters (period, metrics, filter, date)
|
23
|
-
c.aggregate({ period: '
|
24
|
-
c.aggregate({ period: '
|
25
|
-
c.aggregate({ period: '
|
23
|
+
c.aggregate({ period: '30d' })
|
24
|
+
c.aggregate({ period: '30d', metrics: 'visitors,pageviews' })
|
25
|
+
c.aggregate({ period: '30d', metrics: 'visitors,pageviews', filters: 'event:page==/order/confirmation' })
|
26
26
|
|
27
27
|
# You'll get something like this:
|
28
28
|
=> {"bounce_rate"=>{"value"=>81.0}, "pageviews"=>{"value"=>29}, "visit_duration"=>{"value"=>247.0}, "visitors"=>{"value"=>14}}
|
@@ -36,11 +36,11 @@ You have all these options to get the timeseries
|
|
36
36
|
c.timeseries
|
37
37
|
|
38
38
|
# Set parameters (period, metrics, filter, date)
|
39
|
-
c.timeseries({ period: '
|
40
|
-
c.timeseries({ period: '
|
39
|
+
c.timeseries({ period: '7d' })
|
40
|
+
c.timeseries({ period: '7d', filters: 'event:page==/order/confirmation', date: '2020/02/10' })
|
41
41
|
|
42
42
|
# You'll get something like this:
|
43
|
-
=> [{"date"=>"2021-01-11", "value"=>100}, {"date"=>"2021-01-12", "value"=>120}, {"date"=>"2021-01-13", "value"=>80}]
|
43
|
+
=> [{"date"=>"2021-01-11", "value"=>100}, {"date"=>"2021-01-12", "value"=>120}, {"date"=>"2021-01-13", "value"=>80}...]
|
44
44
|
```
|
45
45
|
|
46
46
|
### Realtime >> Visitors
|
@@ -56,9 +56,8 @@ $ gem build plausible_api.gemspec
|
|
56
56
|
$ gem install ./plausible_api-X.X.X.gem
|
57
57
|
$ irb
|
58
58
|
irb(main) > require 'plausible_api'
|
59
|
-
irb(main) > c = PlausibleApi::Client.new(site_id: 'dailytics.com', token: '123123')
|
60
|
-
irb(main) > c.aggregate(period: '1w', metrics: 'visitors,pageviews,bounce_rate,visit_duration')
|
61
59
|
```
|
62
60
|
|
63
61
|
## Todo
|
64
|
-
- Tests
|
62
|
+
- Tests
|
63
|
+
- Options validation
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'plausible_api/api/realtime/visitors'
|
3
|
+
require 'plausible_api/api/stats/realtime/visitors'
|
4
4
|
require 'plausible_api/api/stats/aggregate'
|
5
5
|
require 'plausible_api/api/stats/timeseries'
|
6
6
|
|
@@ -26,7 +26,7 @@ module PlausibleApi
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def realtime_visitors
|
29
|
-
call PlausibleApi::Realtime::Visitors.new
|
29
|
+
call PlausibleApi::Stats::Realtime::Visitors.new
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
@@ -4,16 +4,22 @@ module PlausibleApi
|
|
4
4
|
module Stats
|
5
5
|
class Aggregate
|
6
6
|
def initialize(options = {})
|
7
|
-
@period = options[:period] || '
|
7
|
+
@period = options[:period] || '30d'
|
8
8
|
@metrics = options[:metrics] || 'visitors,pageviews,bounce_rate,visit_duration'
|
9
|
-
@
|
9
|
+
@filters = options[:filters]
|
10
10
|
@date = options[:date]
|
11
11
|
end
|
12
12
|
|
13
13
|
def request_url
|
14
|
-
url = "/api/v1/stats/aggregate?site_id=$SITE_ID
|
15
|
-
if @
|
16
|
-
url += "&
|
14
|
+
url = "/api/v1/stats/aggregate?site_id=$SITE_ID"
|
15
|
+
if @period
|
16
|
+
url += "&period=#{@period}"
|
17
|
+
end
|
18
|
+
if @metrics
|
19
|
+
url += "&metrics=#{@metrics}"
|
20
|
+
end
|
21
|
+
if @filters
|
22
|
+
url += "&filters=#{CGI.escape(@filters)}"
|
17
23
|
end
|
18
24
|
if @date
|
19
25
|
url += "&date=#{@date}"
|
@@ -4,15 +4,18 @@ module PlausibleApi
|
|
4
4
|
module Stats
|
5
5
|
class Timeseries
|
6
6
|
def initialize(options = {})
|
7
|
-
@period = options[:period] || '
|
8
|
-
@
|
7
|
+
@period = options[:period] || '30d'
|
8
|
+
@filters = options[:filters]
|
9
9
|
@date = options[:date]
|
10
10
|
end
|
11
11
|
|
12
12
|
def request_url
|
13
|
-
url = "/api/v1/stats/timeseries?site_id=$SITE_ID
|
14
|
-
if @
|
15
|
-
url += "&
|
13
|
+
url = "/api/v1/stats/timeseries?site_id=$SITE_ID"
|
14
|
+
if @period
|
15
|
+
url += "&period=#{@period}"
|
16
|
+
end
|
17
|
+
if @filters
|
18
|
+
url += "&filters=#{CGI.escape(@filters)}"
|
16
19
|
end
|
17
20
|
if @date
|
18
21
|
url += "&date=#{@date}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plausible_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Garcia
|
@@ -34,8 +34,8 @@ files:
|
|
34
34
|
- README.md
|
35
35
|
- lib/plausible_api.rb
|
36
36
|
- lib/plausible_api/api/client.rb
|
37
|
-
- lib/plausible_api/api/realtime/visitors.rb
|
38
37
|
- lib/plausible_api/api/stats/aggregate.rb
|
38
|
+
- lib/plausible_api/api/stats/realtime/visitors.rb
|
39
39
|
- lib/plausible_api/api/stats/timeseries.rb
|
40
40
|
- lib/plausible_api/version.rb
|
41
41
|
- plausible_api.gemspec
|