posthog-ruby 3.12.1 → 3.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f51843606a47a924b1a6b772f02c61c90e9446c16827b3d5b28d92d7fdade73a
4
- data.tar.gz: 4cfbb395d74bf0f9630b35fafafc6f4eedcdbce9e32a0a8825880f461b581fd9
3
+ metadata.gz: 333bb9ea61d04be7324d0c46eb5dbfa2938a583f8fd88bba845ee6300d219702
4
+ data.tar.gz: eeceaa50cc3defed270dc48ad6863e555d3068a21929c0157f03743b943fdde2
5
5
  SHA512:
6
- metadata.gz: 9978900c0f4091624f901a72396f4b2915cc4532503d1bd3a17c7f7e27a142463f5dbbe8e40d621cb52ae95871055f720d5a1a7a5e4652f266604a7311e2dd68
7
- data.tar.gz: a815192b4521d259e0f2b8c3adba4c1ef2ef2b30748b4ca56c38f5b4d2b3633b1d500d7b06fe1f51d7e4046d3df618c82e2f5a0ed84ed12eb2f87d94f57dc7b8
6
+ metadata.gz: a35cbbd21df7355144bf1f1c6f25e36fc1ab3341d09a326941f8d4f41b7e40766019a4935e6930f8874bf18fe9bf4b0a265879c8f6e87f5a4eb930ddac33c923
7
+ data.tar.gz: 9269f70dd837716bcbf638e626a6928dcc32f7f9c3e4e49b53777cac2d4347b050b65d1393c70ff750cdee8a25baad5607467b2da4454d272a0fd1ad6f4b311d
@@ -181,8 +181,10 @@ module PostHog
181
181
  end
182
182
 
183
183
  # @!macro common_attrs
184
- # @option attrs [String] :message_id ID that uniquely
185
- # identifies a message across the API. (optional)
184
+ # @option attrs [String] :message_id Deprecated. Use `:uuid` instead. If `:uuid` is absent or
185
+ # invalid and `:message_id` is a valid UUID, it is sent as `uuid` for backwards compatibility.
186
+ # If neither value is valid, the SDK generates a `uuid`. SDK metadata is sent as `$lib` and
187
+ # `$lib_version` properties.
186
188
  # @option attrs [Time] :timestamp When the event occurred (optional)
187
189
  # @option attrs [String] :distinct_id The ID for this user in your database
188
190
 
@@ -949,9 +951,6 @@ module PostHog
949
951
  action = process_before_send(action)
950
952
  return false if action.nil? || action.empty?
951
953
 
952
- # add our request id for tracing purposes
953
- action[:messageId] ||= uid
954
-
955
954
  if @sync_mode
956
955
  send_sync(action)
957
956
  return true
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'securerandom'
4
+
3
5
  require 'posthog/logging'
4
6
 
5
7
  module PostHog
@@ -25,7 +27,6 @@ module PostHog
25
27
  event = fields[:event]
26
28
  properties = fields[:properties] || {}
27
29
  groups = fields[:groups]
28
- uuid = fields[:uuid]
29
30
  check_presence!(event, 'event')
30
31
  check_is_hash!(properties, 'properties')
31
32
 
@@ -36,8 +37,6 @@ module PostHog
36
37
 
37
38
  isoify_dates! properties
38
39
 
39
- common['uuid'] = uuid if valid_uuid_for_event_props? uuid
40
-
41
40
  common.merge(
42
41
  {
43
42
  type: 'capture',
@@ -130,12 +129,13 @@ module PostHog
130
129
  #
131
130
  # - "timestamp"
132
131
  # - "distinct_id"
133
- # - "message_id"
132
+ # - "message_id" (deprecated; normalized to "uuid" when it is a valid UUID)
134
133
  # - "send_feature_flags"
134
+ #
135
+ # A new "uuid" is generated when neither "uuid" nor "message_id" is valid.
135
136
  def parse_common_fields(fields)
136
137
  timestamp = fields[:timestamp] || Time.new
137
138
  distinct_id = fields[:distinct_id]
138
- message_id = fields[:message_id].to_s if fields[:message_id]
139
139
  send_feature_flags = fields[:send_feature_flags]
140
140
 
141
141
  check_timestamp! timestamp
@@ -151,13 +151,12 @@ module PostHog
151
151
 
152
152
  parsed = {
153
153
  timestamp: datetime_in_iso8601(timestamp),
154
- library: 'posthog-ruby',
155
- library_version: PostHog::VERSION.to_s,
156
- messageId: message_id,
157
154
  distinct_id: distinct_id,
158
155
  properties: properties
159
156
  }
160
157
 
158
+ parsed['uuid'] = normalized_uuid(fields)
159
+
161
160
  if send_feature_flags && fields[:feature_variants]
162
161
  feature_variants = fields[:feature_variants]
163
162
  active_feature_variants = {}
@@ -190,6 +189,16 @@ module PostHog
190
189
  raise ArgumentError, "#{name} must be a Hash" unless obj.is_a? Hash
191
190
  end
192
191
 
192
+ def normalized_uuid(fields)
193
+ uuid = fields[:uuid]
194
+ return uuid if uuid && valid_uuid_for_event_props?(uuid)
195
+
196
+ message_id = fields[:message_id]
197
+ return message_id if message_id && valid_uuid_for_event_props?(message_id)
198
+
199
+ SecureRandom.uuid
200
+ end
201
+
193
202
  # @param [Object] uuid - the UUID to validate, user provided, so we don't know the type
194
203
  # @return [TrueClass, FalseClass] - true if the UUID is valid or absent, false otherwise
195
204
  def valid_uuid_for_event_props?(uuid)
data/lib/posthog/utils.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'securerandom'
4
-
5
3
  module PostHog
6
4
  class InconclusiveMatchError < StandardError
7
5
  end
@@ -60,16 +58,6 @@ module PostHog
60
58
  hash.replace isoify_dates hash
61
59
  end
62
60
 
63
- # public: Returns a uid string
64
- #
65
- def uid
66
- arr = SecureRandom.random_bytes(16).unpack('NnnnnN')
67
- arr[2] = (arr[2] & 0x0fff) | 0x4000
68
- arr[3] = (arr[3] & 0x3fff) | 0x8000
69
-
70
- '%08x-%04x-%04x-%04x-%04x%08x' % arr # rubocop:disable Style/FormatStringToken, Style/FormatString
71
- end
72
-
73
61
  def datetime_in_iso8601(datetime)
74
62
  case datetime
75
63
  when Time
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.12.1'
4
+ VERSION = '3.12.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.1
4
+ version: 3.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''