ahoy_matey 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +44 -4
- data/lib/ahoy/engine.rb +7 -0
- data/lib/ahoy/query_methods.rb +21 -34
- data/lib/ahoy/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: 06e00a470a12c20b510cc9f1476e39c2cfd8ec24115b29d5d09489d091465b74
|
4
|
+
data.tar.gz: e19501a6019c94bafc32121122e2832152adb0fe8475cb3b91ed4d50c791ff6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0fe7c188d2165aae96a6a5d2def6658bcf41158477d5d9aa79448b889f87c3b88ef3f6aee19309c56af3587110fff71bfcd60fae0a46562e87e1a22ae070073
|
7
|
+
data.tar.gz: 285deb63fb81a4cc423c3eab394e324d5ebe8572c5500750cefe88d615bbd869228d04a725f62cde2868730d7dbd345d3d3787bbaf0acb75f04aa2e231669a81
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
## 4.0.2 (2021-11-06)
|
2
|
+
|
3
|
+
- Added experimental support for `importmap-rails`
|
4
|
+
|
1
5
|
## 4.0.1 (2021-08-18)
|
2
6
|
|
3
7
|
- Added support for `where_event`, `where_props`, and `where_group` for SQLite
|
4
|
-
- Fixed results with `where_event`
|
5
|
-
- Fixed results with `where_props` and `where_group` when used with other scopes
|
8
|
+
- Fixed results with `where_event` for MySQL, MariaDB, and Postgres `hstore`
|
9
|
+
- Fixed results with `where_props` and `where_group` when used with other scopes for MySQL, MariaDB, and Postgres `hstore`
|
6
10
|
|
7
11
|
## 4.0.0 (2021-08-14)
|
8
12
|
|
data/README.md
CHANGED
@@ -57,7 +57,7 @@ yarn add ahoy.js
|
|
57
57
|
And add to `app/javascript/packs/application.js`:
|
58
58
|
|
59
59
|
```javascript
|
60
|
-
import ahoy from "ahoy.js"
|
60
|
+
import ahoy from "ahoy.js"
|
61
61
|
```
|
62
62
|
|
63
63
|
For Rails 5 / Sprockets, add to `app/assets/javascripts/application.js`:
|
@@ -66,6 +66,18 @@ For Rails 5 / Sprockets, add to `app/assets/javascripts/application.js`:
|
|
66
66
|
//= require ahoy
|
67
67
|
```
|
68
68
|
|
69
|
+
For Rails 7 / Importmap (experimental), add to `config/importmap.rb`:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
pin "ahoy", to: "ahoy.js"
|
73
|
+
```
|
74
|
+
|
75
|
+
And add to `app/javascript/application.js`:
|
76
|
+
|
77
|
+
```javascript
|
78
|
+
import "ahoy"
|
79
|
+
```
|
80
|
+
|
69
81
|
Track an event with:
|
70
82
|
|
71
83
|
```javascript
|
@@ -661,7 +673,7 @@ Group by properties with:
|
|
661
673
|
Ahoy::Event.group_prop(:product_id, :category).count
|
662
674
|
```
|
663
675
|
|
664
|
-
Note: MySQL and MariaDB always return string keys (
|
676
|
+
Note: MySQL and MariaDB always return string keys (including `"null"` for `nil`) for `group_prop`.
|
665
677
|
|
666
678
|
### Funnels
|
667
679
|
|
@@ -694,6 +706,24 @@ daily_visits = Ahoy::Visit.group_by_day(:started_at).count # uses Groupdate
|
|
694
706
|
Prophet.forecast(daily_visits)
|
695
707
|
```
|
696
708
|
|
709
|
+
### Anomaly Detection
|
710
|
+
|
711
|
+
To detect anomalies in visits and events, check out [AnomalyDetection.rb](https://github.com/ankane/AnomalyDetection.rb).
|
712
|
+
|
713
|
+
```ruby
|
714
|
+
daily_visits = Ahoy::Visit.group_by_day(:started_at).count # uses Groupdate
|
715
|
+
AnomalyDetection.detect(daily_visits, period: 7)
|
716
|
+
```
|
717
|
+
|
718
|
+
### Breakout Detection
|
719
|
+
|
720
|
+
To detect breakouts in visits and events, check out [Breakout](https://github.com/ankane/breakout).
|
721
|
+
|
722
|
+
```ruby
|
723
|
+
daily_visits = Ahoy::Visit.group_by_day(:started_at).count # uses Groupdate
|
724
|
+
Breakout.detect(daily_visits)
|
725
|
+
```
|
726
|
+
|
697
727
|
### Recommendations
|
698
728
|
|
699
729
|
To make recommendations based on events, check out [Disco](https://github.com/ankane/disco#ahoy).
|
@@ -781,10 +811,20 @@ bundle install
|
|
781
811
|
bundle exec rake test
|
782
812
|
```
|
783
813
|
|
784
|
-
To test query methods,
|
814
|
+
To test query methods, use:
|
785
815
|
|
786
816
|
```sh
|
817
|
+
# Postgres
|
787
818
|
createdb ahoy_test
|
819
|
+
bundle exec rake test:query_methods:postgresql
|
820
|
+
|
821
|
+
# SQLite
|
822
|
+
bundle exec rake test:query_methods:sqlite
|
823
|
+
|
824
|
+
# MySQL and MariaDB
|
788
825
|
mysqladmin create ahoy_test
|
789
|
-
bundle exec rake test:query_methods
|
826
|
+
bundle exec rake test:query_methods:mysql
|
827
|
+
|
828
|
+
# MongoDB
|
829
|
+
bundle exec rake test:query_methods:mongoid
|
790
830
|
```
|
data/lib/ahoy/engine.rb
CHANGED
@@ -26,5 +26,12 @@ module Ahoy
|
|
26
26
|
alias_method :call, :call_with_quiet_ahoy
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
# for importmap
|
31
|
+
if defined?(Importmap)
|
32
|
+
initializer "ahoy.importmap", after: "importmap" do |app|
|
33
|
+
app.config.assets.precompile << "ahoy.js"
|
34
|
+
end
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
data/lib/ahoy/query_methods.rb
CHANGED
@@ -10,47 +10,38 @@ module Ahoy
|
|
10
10
|
def where_props(properties)
|
11
11
|
return all if properties.empty?
|
12
12
|
|
13
|
-
|
14
|
-
if respond_to?(:columns_hash)
|
15
|
-
column_type = columns_hash["properties"].type
|
16
|
-
adapter_name = connection.adapter_name.downcase
|
17
|
-
else
|
18
|
-
adapter_name = "mongoid"
|
19
|
-
end
|
13
|
+
adapter_name = respond_to?(:connection) ? connection.adapter_name.downcase : "mongoid"
|
20
14
|
case adapter_name
|
21
15
|
when "mongoid"
|
22
|
-
|
16
|
+
where(properties.to_h { |k, v| ["properties.#{k}", v] })
|
23
17
|
when /mysql/
|
24
|
-
|
18
|
+
where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
|
25
19
|
when /postgres|postgis/
|
26
|
-
case
|
27
|
-
when :jsonb
|
28
|
-
relation = relation.where("properties @> ?", properties.to_json)
|
20
|
+
case columns_hash["properties"].type
|
29
21
|
when :hstore
|
30
|
-
properties.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
22
|
+
properties.inject(all) do |relation, (k, v)|
|
23
|
+
if v.nil?
|
24
|
+
relation.where("properties -> ? IS NULL", k.to_s)
|
25
|
+
else
|
26
|
+
relation.where("properties -> ? = ?", k.to_s, v.to_s)
|
27
|
+
end
|
37
28
|
end
|
29
|
+
when :jsonb
|
30
|
+
where("properties @> ?", properties.to_json)
|
38
31
|
else
|
39
|
-
|
32
|
+
where("properties::jsonb @> ?", properties.to_json)
|
40
33
|
end
|
41
34
|
when /sqlite/
|
42
|
-
properties.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
35
|
+
properties.inject(all) do |relation, (k, v)|
|
36
|
+
if v.nil?
|
37
|
+
relation.where("JSON_EXTRACT(properties, ?) IS NULL", "$.#{k}")
|
38
|
+
else
|
39
|
+
relation.where("JSON_EXTRACT(properties, ?) = ?", "$.#{k}", v.as_json)
|
40
|
+
end
|
49
41
|
end
|
50
42
|
else
|
51
43
|
raise "Adapter not supported: #{adapter_name}"
|
52
44
|
end
|
53
|
-
relation
|
54
45
|
end
|
55
46
|
alias_method :where_properties, :where_props
|
56
47
|
|
@@ -59,12 +50,7 @@ module Ahoy
|
|
59
50
|
props.flatten!
|
60
51
|
|
61
52
|
relation = all
|
62
|
-
|
63
|
-
column_type = columns_hash["properties"].type
|
64
|
-
adapter_name = connection.adapter_name.downcase
|
65
|
-
else
|
66
|
-
adapter_name = "mongoid"
|
67
|
-
end
|
53
|
+
adapter_name = respond_to?(:connection) ? connection.adapter_name.downcase : "mongoid"
|
68
54
|
case adapter_name
|
69
55
|
when "mongoid"
|
70
56
|
raise "Adapter not supported: #{adapter_name}"
|
@@ -77,6 +63,7 @@ module Ahoy
|
|
77
63
|
# convert to jsonb to fix
|
78
64
|
# could not identify an equality operator for type json
|
79
65
|
# and for text columns
|
66
|
+
column_type = columns_hash["properties"].type
|
80
67
|
cast = [:jsonb, :hstore].include?(column_type) ? "" : "::jsonb"
|
81
68
|
|
82
69
|
props.each do |prop|
|
data/lib/ahoy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahoy_matey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|