ahoy_matey 5.0.2 → 5.2.0

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: f2da2e05c42ba50652c0fc6aada9a25bbaada8746a6802a7585790a751a2d9f4
4
- data.tar.gz: 6ad4e393177de9f357957259082e0960ad8ea07e51d2c75e1b07826955a01456
3
+ metadata.gz: 9161dead45561a928523eb7d5ed70be20c67c8629499c35cb428271d714895a7
4
+ data.tar.gz: f17eb958ee297a4eda86388e0458a04a2a39de5b868076521eb65dd6e4cbc21a
5
5
  SHA512:
6
- metadata.gz: cbfcb708d2a2343b51f0eb9b20de751f9802695445049d09f15a09ee214151ac4b20705d4f7369d12cdf254018a3b5f3c3271ebdfef5fc2516c52ecd457f5203
7
- data.tar.gz: 135303f5c3c1f04a0e08b38859f4ed67e0d530e83908c1d1e83af7d012c6c68dabd810a2800bec9e32249ea5605a3405a66969ebb55d8cd56eba0a66d7b55af9
6
+ metadata.gz: c68fa7030244573a75b72167d163a8a0f2cfb5ef01e3718980ea25e5c13a5936973d0d5f83d3302f9e610508d94758ec0587f6fe4dd19c7c23668181ea1dcfe0
7
+ data.tar.gz: 7950a3cd2dda3818e21a6da37ab0d1b49b01d22110c76f0ae1abd15abba7aaa6140db24d70cedb4d5af0c5022f2b95a2f7e5a11339425eefb51240bb9ea17578
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 5.2.0 (2024-09-04)
2
+
3
+ - Improved error handling for invalid API parameters
4
+
5
+ ## 5.1.0 (2024-03-26)
6
+
7
+ - Added support for Trilogy
8
+ - Updated Ahoy.js to 0.4.4
9
+
1
10
  ## 5.0.2 (2023-10-05)
2
11
 
3
12
  - Excluded visits from Rails health check
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2023 Andrew Kane
1
+ Copyright (c) 2014-2024 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -10,7 +10,7 @@ Track visits and events in Ruby, JavaScript, and native apps. Data is stored in
10
10
 
11
11
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
12
12
 
13
- [![Build Status](https://github.com/ankane/ahoy/workflows/build/badge.svg?branch=master)](https://github.com/ankane/ahoy/actions)
13
+ [![Build Status](https://github.com/ankane/ahoy/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/ahoy/actions)
14
14
 
15
15
  ## Installation
16
16
 
@@ -197,7 +197,7 @@ Order.joins(:ahoy_visit).group("device_type").count
197
197
  Here’s what the migration to add the `ahoy_visit_id` column should look like:
198
198
 
199
199
  ```ruby
200
- class AddAhoyVisitToOrders < ActiveRecord::Migration[7.0]
200
+ class AddAhoyVisitToOrders < ActiveRecord::Migration[7.2]
201
201
  def change
202
202
  add_reference :orders, :ahoy_visit
203
203
  end
@@ -17,12 +17,23 @@ module Ahoy
17
17
  begin
18
18
  ActiveSupport::JSON.decode(data)
19
19
  rescue ActiveSupport::JSON.parse_error
20
- # do nothing
20
+ # TODO change to nil in Ahoy 6
21
21
  []
22
22
  end
23
23
  end
24
24
 
25
- events.first(Ahoy.max_events_per_request).each do |event|
25
+ max_events_per_request = Ahoy.max_events_per_request
26
+
27
+ # check before creating any events
28
+ unless events.is_a?(Array) && events.first(max_events_per_request).all? { |v| v.is_a?(Hash) }
29
+ logger.info "[ahoy] Invalid parameters"
30
+ # :unprocessable_entity is probably more correct
31
+ # but keep consistent with missing parameters for now
32
+ render plain: "Invalid parameters\n", status: :bad_request
33
+ return
34
+ end
35
+
36
+ events.first(max_events_per_request).each do |event|
26
37
  time = Time.zone.parse(event["time"]) rescue nil
27
38
 
28
39
  # timestamp is deprecated
@@ -14,7 +14,7 @@ module Ahoy
14
14
  case adapter_name
15
15
  when "mongoid"
16
16
  where(properties.to_h { |k, v| ["properties.#{k}", v] })
17
- when /mysql/
17
+ when /mysql|trilogy/
18
18
  where("JSON_CONTAINS(properties, ?, '$') = 1", properties.to_json)
19
19
  when /postgres|postgis/
20
20
  case columns_hash["properties"].type
@@ -54,7 +54,7 @@ module Ahoy
54
54
  case adapter_name
55
55
  when "mongoid"
56
56
  raise "Adapter not supported: #{adapter_name}"
57
- when /mysql/
57
+ when /mysql|trilogy/
58
58
  props.each do |prop|
59
59
  quoted_prop = connection.quote("$.#{prop}")
60
60
  relation = relation.group("JSON_UNQUOTE(JSON_EXTRACT(properties, #{quoted_prop}))")
data/lib/ahoy/tracker.rb CHANGED
@@ -49,7 +49,7 @@ module Ahoy
49
49
  visit_token: visit_token,
50
50
  visitor_token: visitor_token,
51
51
  user_id: user.try(:id),
52
- started_at: trusted_time(started_at),
52
+ started_at: trusted_time(started_at)
53
53
  }.merge(visit_properties).select { |_, v| v }
54
54
 
55
55
  @store.track_visit(data)
data/lib/ahoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "5.0.2"
2
+ VERSION = "5.2.0"
3
3
  end
@@ -21,7 +21,7 @@ module Ahoy
21
21
  case adapter
22
22
  when /postg/i # postgres, postgis
23
23
  "jsonb"
24
- when /mysql/i
24
+ when /mysql|trilogy/i
25
25
  "json"
26
26
  else
27
27
  "text"
@@ -37,14 +37,10 @@ module Ahoy
37
37
  ActiveRecord::VERSION::STRING.to_f >= 7.1 ? "coder: JSON" : "JSON"
38
38
  end
39
39
 
40
- # use connection_config instead of connection.adapter
40
+ # use connection_db_config instead of connection.adapter
41
41
  # so database connection isn't needed
42
42
  def adapter
43
- if ActiveRecord::VERSION::STRING.to_f >= 6.1
44
- ActiveRecord::Base.connection_db_config.adapter.to_s
45
- else
46
- ActiveRecord::Base.connection_config[:adapter].to_s
47
- end
43
+ ActiveRecord::Base.connection_db_config.adapter.to_s
48
44
  end
49
45
 
50
46
  def migration_version
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Ahoy.js v0.4.2
2
+ * Ahoy.js v0.4.4
3
3
  * Simple, powerful JavaScript analytics
4
4
  * https://github.com/ankane/ahoy.js
5
5
  * MIT License
@@ -188,6 +188,10 @@
188
188
 
189
189
  // https://stackoverflow.com/a/2117523/1177228
190
190
  function generateId() {
191
+ if (window.crypto && window.crypto.randomUUID) {
192
+ return window.crypto.randomUUID();
193
+ }
194
+
191
195
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
192
196
  var r = Math.random() * 16 | 0;
193
197
  var v = c === 'x' ? r : (r & 0x3 | 0x8);
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: 5.0.2
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-05 00:00:00.000000000 Z
11
+ date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.4.10
115
+ rubygems_version: 3.5.11
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Simple, powerful, first-party analytics for Rails