plausible_api 0.1.0 → 0.1.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 +1 -1
- data/README.md +10 -8
- data/lib/plausible_api/client.rb +1 -1
- data/lib/plausible_api/stats/aggregate.rb +6 -14
- data/lib/plausible_api/stats/timeseries.rb +6 -12
- data/lib/plausible_api/version.rb +1 -1
- 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: 1ab7e5d90aa275223a1b9006a563093a7ac9e7ceb0be4efdb2539a511361a15b
|
4
|
+
data.tar.gz: f42c1294d5a65bb6ed07043a99c8febf4f42dc88d1b722632d86af2d845dd216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d85ed0990813b05c2cd277e6544859bf7bfdb8875ee68c20d6d71ce62ffef1579878b6e459b35305fc825bfa20fd868c5157d24eb9114bb100b2f7ce7e1a6601
|
7
|
+
data.tar.gz: cb29f033d91225f2bdaa6cb908308444855d734b2fd3b146345915c593257db8689556a6d227775cd440683001756a377b770a6c36b3e248b88429fece538877
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ gem 'plausible_api'
|
|
9
9
|
```
|
10
10
|
Then you need to initialize a Client with your `site_id` (the domain) and your `token`.
|
11
11
|
```rb
|
12
|
-
c = PlausibleApi::Client.new(
|
12
|
+
c = PlausibleApi::Client.new('dailytics.com', '123123')
|
13
13
|
```
|
14
14
|
|
15
15
|
### Stats > Aggregate
|
@@ -19,7 +19,7 @@ You have all these options to get the aggregate stats
|
|
19
19
|
# Use the default parameters (3mo period + the 4 main metrics)
|
20
20
|
c.aggregate
|
21
21
|
|
22
|
-
# Set parameters (period, metrics, filter,
|
22
|
+
# Set parameters (period, metrics, filter, compare)
|
23
23
|
c.aggregate({ period: '30d' })
|
24
24
|
c.aggregate({ period: '30d', metrics: 'visitors,pageviews' })
|
25
25
|
c.aggregate({ period: '30d', metrics: 'visitors,pageviews', filters: 'event:page==/order/confirmation' })
|
@@ -35,19 +35,21 @@ You have all these options to get the timeseries
|
|
35
35
|
# Use the default parameters (3mo period)
|
36
36
|
c.timeseries
|
37
37
|
|
38
|
-
# Set parameters (period,
|
38
|
+
# Set parameters (period, filters, interval)
|
39
39
|
c.timeseries({ period: '7d' })
|
40
|
-
c.timeseries({ period: '7d', filters: 'event:page==/order/confirmation'
|
40
|
+
c.timeseries({ period: '7d', filters: 'event:page==/order/confirmation' })
|
41
41
|
|
42
42
|
# You'll get something like this:
|
43
43
|
=> [{"date"=>"2021-01-11", "value"=>100}, {"date"=>"2021-01-12", "value"=>120}, {"date"=>"2021-01-13", "value"=>80}...]
|
44
44
|
```
|
45
45
|
|
46
|
-
### Realtime
|
46
|
+
### Realtime > Visitors
|
47
47
|
|
48
|
-
|
48
|
+
It's as simple as:
|
49
49
|
```rb
|
50
50
|
c.realtime_visitors
|
51
|
+
|
52
|
+
=> 13
|
51
53
|
```
|
52
54
|
|
53
55
|
|
@@ -59,7 +61,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
59
61
|
|
60
62
|
## Contributing
|
61
63
|
|
62
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/dailytics/plausible_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dailytics/plausible_api/blob/
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dailytics/plausible_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dailytics/plausible_api/blob/main/CODE_OF_CONDUCT.md).
|
63
65
|
|
64
66
|
|
65
67
|
## License
|
@@ -68,4 +70,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
68
70
|
|
69
71
|
## Code of Conduct
|
70
72
|
|
71
|
-
Everyone interacting in the PlausibleApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dailytics/plausible_api/blob/
|
73
|
+
Everyone interacting in the PlausibleApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dailytics/plausible_api/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/plausible_api/client.rb
CHANGED
@@ -6,24 +6,16 @@ module PlausibleApi
|
|
6
6
|
def initialize(options = {})
|
7
7
|
@period = options[:period] || '30d'
|
8
8
|
@metrics = options[:metrics] || 'visitors,pageviews,bounce_rate,visit_duration'
|
9
|
-
@filters
|
10
|
-
@
|
9
|
+
@filters = options[:filters]
|
10
|
+
@compare = options[:compare]
|
11
11
|
end
|
12
12
|
|
13
13
|
def request_url
|
14
14
|
url = "/api/v1/stats/aggregate?site_id=$SITE_ID"
|
15
|
-
if @period
|
16
|
-
|
17
|
-
|
18
|
-
if @
|
19
|
-
url += "&metrics=#{@metrics}"
|
20
|
-
end
|
21
|
-
if @filters
|
22
|
-
url += "&filters=#{CGI.escape(@filters)}"
|
23
|
-
end
|
24
|
-
if @date
|
25
|
-
url += "&date=#{@date}"
|
26
|
-
end
|
15
|
+
url += "&period=#{@period}" if @period
|
16
|
+
url += "&metrics=#{@metrics}" if @metrics
|
17
|
+
url += "&filters=#{CGI.escape(@filters)}" if @filters
|
18
|
+
url += "&compare=#{@compare}" if @compare
|
27
19
|
url
|
28
20
|
end
|
29
21
|
end
|
@@ -4,22 +4,16 @@ module PlausibleApi
|
|
4
4
|
module Stats
|
5
5
|
class Timeseries
|
6
6
|
def initialize(options = {})
|
7
|
-
@period
|
8
|
-
@filters
|
9
|
-
@
|
7
|
+
@period = options[:period] || '30d'
|
8
|
+
@filters = options[:filters]
|
9
|
+
@interval = options[:interval]
|
10
10
|
end
|
11
11
|
|
12
12
|
def request_url
|
13
13
|
url = "/api/v1/stats/timeseries?site_id=$SITE_ID"
|
14
|
-
if @period
|
15
|
-
|
16
|
-
|
17
|
-
if @filters
|
18
|
-
url += "&filters=#{CGI.escape(@filters)}"
|
19
|
-
end
|
20
|
-
if @date
|
21
|
-
url += "&date=#{@date}"
|
22
|
-
end
|
14
|
+
url += "&period=#{@period}" if @period
|
15
|
+
url += "&filters=#{CGI.escape(@filters)}" if @filters
|
16
|
+
url += "&interval=#{@interval}" if @interval
|
23
17
|
url
|
24
18
|
end
|
25
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plausible_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|