ahoy_matey 4.0.1 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cea71919e25f8f3b9ce9f3ccea43f8d11ec29d1995b3c5078428a8d4a7948457
4
- data.tar.gz: 81316ad1b9fc956bf0ece8c23c63570d5f333e0f7c781406e1b2214e965feebb
3
+ metadata.gz: 06e00a470a12c20b510cc9f1476e39c2cfd8ec24115b29d5d09489d091465b74
4
+ data.tar.gz: e19501a6019c94bafc32121122e2832152adb0fe8475cb3b91ed4d50c791ff6e
5
5
  SHA512:
6
- metadata.gz: c52e5f32c8fd7f9d070867e8d53868a58365430ed6d7bfa3baa1dd826f042875d42fadddc7991bf5c1c0b836021dd1b2634e8c2e43fa88a055dff9b8aeae70e5
7
- data.tar.gz: e3cdb04028a3277f678f65bf713d3a93339be369d4ed8af73a87bddd549b2ffd7983abd91443858e4411459442b8e292612381ea3ff731ce53d8f0b50f995857
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 (include `"null"` for `nil`) for `group_prop`.
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, start PostgreSQL, MySQL, and MongoDB and use:
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
@@ -10,47 +10,38 @@ module Ahoy
10
10
  def where_props(properties)
11
11
  return all if properties.empty?
12
12
 
13
- relation = all
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
- relation = where(properties.to_h { |k, v| ["properties.#{k}", v] })
16
+ where(properties.to_h { |k, v| ["properties.#{k}", v] })
23
17
  when /mysql/
24
- relation = relation.where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
18
+ where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
25
19
  when /postgres|postgis/
26
- case column_type
27
- when :jsonb
28
- relation = relation.where("properties @> ?", properties.to_json)
20
+ case columns_hash["properties"].type
29
21
  when :hstore
30
- properties.each do |k, v|
31
- relation =
32
- if v.nil?
33
- relation.where("properties -> ? IS NULL", k.to_s)
34
- else
35
- relation.where("properties -> ? = ?", k.to_s, v.to_s)
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
- relation = relation.where("properties::jsonb @> ?", properties.to_json)
32
+ where("properties::jsonb @> ?", properties.to_json)
40
33
  end
41
34
  when /sqlite/
42
- properties.each do |k, v|
43
- relation =
44
- if v.nil?
45
- relation.where("JSON_EXTRACT(properties, ?) IS NULL", "$.#{k}")
46
- else
47
- relation.where("JSON_EXTRACT(properties, ?) = ?", "$.#{k}", v.as_json)
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
- if respond_to?(:columns_hash)
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
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "4.0.1"
2
+ VERSION = "4.0.2"
3
3
  end
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.1
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-08-18 00:00:00.000000000 Z
11
+ date: 2021-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport